Add support to return list of expunged messages
authorMichael M Slusarz <slusarz@curecanti.org>
Tue, 17 Mar 2009 16:21:31 +0000 (10:21 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Tue, 17 Mar 2009 16:21:31 +0000 (10:21 -0600)
framework/Imap_Client/lib/Horde/Imap/Client/Base.php
framework/Imap_Client/lib/Horde/Imap/Client/Cclient.php
framework/Imap_Client/lib/Horde/Imap/Client/Socket.php
framework/Imap_Client/lib/Horde/Imap/Client/Socket/Pop3.php

index 1d1ef95..c2e8e8a 100644 (file)
@@ -1161,16 +1161,20 @@ abstract class Horde_Imap_Client_Base
      *         are also flagged as deleted. By default, this array is
      *         assumed to contain UIDs (see 'sequence').
      *         DEFAULT: All messages marked as deleted will be expunged.
+     * 'list' - (boolean) If true, returns the list of expunged messages.
+     *          DEFAULT: false
      * 'sequence' - (boolean) If true, 'ids' is an array of sequence numbers.
      *              DEFAULT: 'sequence' is an array of UIDs.
      * </pre>
      *
+     * @return array  If 'list' option is true, returns the list of
+     *                expunged messages.
      * @throws Horde_Imap_Client_Exception
      */
     public function expunge($mailbox, $options = array())
     {
         $this->openMailbox($mailbox, Horde_Imap_Client::OPEN_READWRITE);
-        $this->_expunge($options);
+        return $this->_expunge($options);
     }
 
     /**
@@ -1178,6 +1182,8 @@ abstract class Horde_Imap_Client_Base
      *
      * @param array $options  Additional options.
      *
+     * @return array  If 'list' option is true, returns the list of
+     *                expunged messages.
      * @throws Horde_Imap_Client_Exception
      */
     abstract protected function _expunge($options);
index ae4a756..945790e 100644 (file)
@@ -697,26 +697,33 @@ class Horde_Imap_Client_Cclient extends Horde_Imap_Client_Base
      *
      * @param array $options  Additional options.
      *
+     * @return array  If 'list' option is true, returns the list of
+     *                expunged messages.
      * @throws Horde_Imap_Client_Exception
      */
     protected function _expunge($options)
     {
         // Already guaranteed to be logged in here.
 
+        $msg_list = !empty($options['list']);
+
+        if (!empty($options['ids']) || $msg_list) {
+            $search_query = new Horde_Imap_Client_Search_Query();
+            $search_query->flag('\\deleted');
+            $ids = $this->search($this->_selected, $search_query, array('sequence' => $use_seq));
+        }
+
         if (empty($options['ids'])) {
             $old_error = error_reporting(0);
             imap_expunge($this->_stream);
             error_reporting($old_error);
-            return;
+            return $msg_list ? $ids['match'] : null;
         }
 
         $use_seq = !empty($options['sequence']);
 
         // Need to temporarily unflag all messages marked as deleted but not
         // a part of requested UIDs to delete.
-        $search_query = new Horde_Imap_Client_Search_Query();
-        $search_query->flag('\\deleted');
-        $ids = $this->search($this->_selected, $search_query, array('sequence' => $use_seq));
         if (!empty($ids['match'])) {
             $unflag = array_diff($ids['match'], $options['ids']);
             if (!empty($unflag)) {
@@ -746,6 +753,8 @@ class Horde_Imap_Client_Cclient extends Horde_Imap_Client_Base
         if (!empty($unflag)) {
             $this->store($this->_selected, array('add' => array('\\deleted'), 'ids' => $unflag, 'sequence' => $use_seq));
         }
+
+        return $msg_list ? $ids['match'] : null;
     }
 
     /**
index f16bc7c..d78f0bd 100644 (file)
@@ -1293,6 +1293,8 @@ class Horde_Imap_Client_Socket extends Horde_Imap_Client_Base
      *
      * @param array $options  Additional options.
      *
+     * @return array  If 'list' option is true, returns the list of
+     *                expunged messages.
      * @throws Horde_Imap_Client_Exception
      */
     protected function _expunge($options)
@@ -1351,11 +1353,12 @@ class Horde_Imap_Client_Socket extends Horde_Imap_Client_Base
 
         $tmp = &$this->_temp;
         $tmp['expunge'] = $tmp['vanished'] = array();
+        $list_msgs = !empty($options['list']);
 
         /* Always use UID EXPUNGE if available. */
         if ($uidplus) {
             $this->_sendLine('UID EXPUNGE ' . $uid_string);
-        } elseif ($use_cache) {
+        } elseif ($use_cache || $list_msgs) {
             $this->_sendLine('EXPUNGE');
         } else {
             /* This is faster than an EXPUNGE because the server will not
@@ -1368,7 +1371,7 @@ class Horde_Imap_Client_Socket extends Horde_Imap_Client_Base
             $this->store($mailbox, array('add' => array('\\deleted'), 'ids' => $unflag));
         }
 
-        if ($use_cache) {
+        if ($use_cache || $list_msgs) {
             if (!empty($tmp['vanished'])) {
                 $i = count($tmp['vanished']);
                 $expunged = $tmp['vanished'];
@@ -1389,6 +1392,8 @@ class Horde_Imap_Client_Socket extends Horde_Imap_Client_Base
             if (isset($this->_init['enabled']['QRESYNC'])) {
                 $this->_cache->setMetaData($mailbox, array('HICmodseq' => $this->_temp['mailbox']['highestmodseq']));
             }
+
+            return $list_msgs ? $i : null;
         } elseif (!empty($tmp['expunge'])) {
             /* Updates status message count if not using cache. */
             $tmp['mailbox']['messages'] -= count($tmp['expunge']);
index e87abad..66d861d 100644 (file)
@@ -74,6 +74,13 @@ class Horde_Imap_Client_Socket_Pop3 extends Horde_Imap_Client_Base
     protected $_stream = null;
 
     /**
+     * The list of deleted messages.
+     *
+     * @var array
+     */
+    protected $_deleted = array();
+
+    /**
      * Constructs a new object.
      *
      * @param array $params  A hash containing configuration parameters.
@@ -352,6 +359,7 @@ class Horde_Imap_Client_Socket_Pop3 extends Horde_Imap_Client_Base
             } catch (Horde_Imap_Client_Exception $e) {}
             fclose($this->_stream);
             $this->_stream = null;
+            $this->_deleted = array();
         }
     }
 
@@ -592,11 +600,15 @@ class Horde_Imap_Client_Socket_Pop3 extends Horde_Imap_Client_Base
      * @param array $options  Additional options. 'ids' and 'sequence' have
      *                        no effect in this driver.
      *
+     * @return array  If 'count' option is true, returns the list of
+     *                expunged messages.
      * @throws Horde_Imap_Client_Exception
      */
     protected function _expunge($options)
     {
+        $msg_list = $this->_deleted();
         $this->logout();
+        return empty($options['list']) ? null : $msg_list;
     }
 
     /**