Fixes to improve POP3 compatibility
authorMichael M Slusarz <slusarz@curecanti.org>
Tue, 3 Mar 2009 22:18:25 +0000 (15:18 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Wed, 4 Mar 2009 19:46:46 +0000 (12:46 -0700)
framework/Imap_Client/lib/Horde/Imap/Client/Base.php
framework/Imap_Client/test/Horde/Imap/test_client.php

index 5881105..27b9eff 100644 (file)
@@ -1779,6 +1779,11 @@ abstract class Horde_Imap_Client_Base
         $qresync = isset($this->_init['enabled']['QRESYNC']);
         $seq = !empty($options['sequence']);
 
+        /* Make sure 'ids' is defined. */
+        if (!isset($options['ids'])) {
+            $options['ids'] = array();
+        }
+
         /* The 'vanished' modifier requires QRESYNC, 'changedsince', and
          * !'sequence'. */
         if (!empty($options['vanished']) &&
@@ -1793,15 +1798,17 @@ abstract class Horde_Imap_Client_Base
          * information (RFC 3501 [6.4.8]). Don't add to criteria because it
          * simply creates a longer FETCH command. */
 
-        /* If using cache, we store by UID so we need to return UIDs. */
-        if ($seq && !empty($cf)) {
-            $criteria[Horde_Imap_Client::FETCH_UID] = true;
-        }
-
         $this->openMailbox($mailbox, Horde_Imap_Client::OPEN_AUTO);
 
-        /* We need the UIDVALIDITY for the current mailbox. */
-        $status_res = $this->status($this->_selected, Horde_Imap_Client::STATUS_HIGHESTMODSEQ | Horde_Imap_Client::STATUS_UIDVALIDITY);
+        if (!empty($cf)) {
+            /* We need the UIDVALIDITY for the current mailbox. */
+            $status_res = $this->status($this->_selected, Horde_Imap_Client::STATUS_HIGHESTMODSEQ | Horde_Imap_Client::STATUS_UIDVALIDITY);
+
+            /* If using cache, we store by UID so we need to return UIDs. */
+            if ($seq) {
+                $criteria[Horde_Imap_Client::FETCH_UID] = true;
+            }
+        }
 
         /* Determine if caching is available and if anything in $criteria is
          * cacheable. Do some sanity checking on criteria also. */
index 070dfe6..1ce70cb 100644 (file)
@@ -3,10 +3,11 @@
  * Test script for the Horde_Imap_Client:: library.
  *
  * Usage:
- *   test_client.php [[username] [[password] [[IMAP URL]]]]
+ *   test_client.php [[username] [[password] [[IMAP URL] [driver]]]]
  *
  * Username/password/hostspec on the command line will override the $params
  * values.
+ * Driver on the command line will override the $driver value.
  *
  * TODO:
  *   + Test for 'charset' searching
@@ -83,9 +84,13 @@ if (!empty($argv[3])) {
     $params = array_merge($params, $imap_utils->parseUrl($argv[3]));
 }
 
-function exception_handler($exception) {
+if (!empty($argv[4])) {
+    $driver = $argv[4];
+}
+
+function exception_handler($e) {
     print "\n=====================================\n" .
-          'UNCAUGHT EXCEPTION: ' . $exception->getMessage() .
+          'UNCAUGHT EXCEPTION: ' . $e->getMessage() .
           "\n=====================================\n";
 }
 set_exception_handler('exception_handler');
@@ -100,7 +105,10 @@ $params['id'] = array('name' => 'Horde_Imap_Client test program');
 
 $imap_client = Horde_Imap_Client::getInstance($driver, $params);
 if ($driver == 'Cclient_Pop3') {
+    $pop3 = true;
     $test_mbox = $test_mbox_utf8 = 'INBOX';
+} else {
+    $pop3 = false;
 }
 
 $use_imapproxy = false;
@@ -562,11 +570,14 @@ try {
 $simple_fetch = array(
     Horde_Imap_Client::FETCH_STRUCTURE => true,
     Horde_Imap_Client::FETCH_ENVELOPE => true,
-    Horde_Imap_Client::FETCH_FLAGS => true,
     Horde_Imap_Client::FETCH_DATE => true,
     Horde_Imap_Client::FETCH_SIZE => true
 );
 
+if (!$pop3) {
+    $simple_fetch[Horde_Imap_Client::FETCH_FLAGS] = true;
+}
+
 print "\nSimple fetch example:\n";
 try {
     print_r($imap_client->fetch($test_mbox, $simple_fetch));
@@ -706,7 +717,7 @@ try {
     print "Fetch: FAILED\n";
 
     // If POP3, try easier fetch criteria
-    if ($driver == 'Cclient_Pop3') {
+    if ($pop3) {
         try {
             print_r($imap_client->fetch('INBOX', array(
                 Horde_Imap_Client::FETCH_FULLMSG => array(