From 973d92420531a3b1953a8139429b98d1a7134eaf Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Tue, 17 Mar 2009 10:21:31 -0600 Subject: [PATCH] Add support to return list of expunged messages --- framework/Imap_Client/lib/Horde/Imap/Client/Base.php | 8 +++++++- framework/Imap_Client/lib/Horde/Imap/Client/Cclient.php | 17 +++++++++++++---- framework/Imap_Client/lib/Horde/Imap/Client/Socket.php | 9 +++++++-- .../Imap_Client/lib/Horde/Imap/Client/Socket/Pop3.php | 12 ++++++++++++ 4 files changed, 39 insertions(+), 7 deletions(-) diff --git a/framework/Imap_Client/lib/Horde/Imap/Client/Base.php b/framework/Imap_Client/lib/Horde/Imap/Client/Base.php index 1d1ef9587..c2e8e8a82 100644 --- a/framework/Imap_Client/lib/Horde/Imap/Client/Base.php +++ b/framework/Imap_Client/lib/Horde/Imap/Client/Base.php @@ -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. * * + * @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); diff --git a/framework/Imap_Client/lib/Horde/Imap/Client/Cclient.php b/framework/Imap_Client/lib/Horde/Imap/Client/Cclient.php index ae4a756b2..945790e0b 100644 --- a/framework/Imap_Client/lib/Horde/Imap/Client/Cclient.php +++ b/framework/Imap_Client/lib/Horde/Imap/Client/Cclient.php @@ -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; } /** diff --git a/framework/Imap_Client/lib/Horde/Imap/Client/Socket.php b/framework/Imap_Client/lib/Horde/Imap/Client/Socket.php index f16bc7caa..d78f0bdf2 100644 --- a/framework/Imap_Client/lib/Horde/Imap/Client/Socket.php +++ b/framework/Imap_Client/lib/Horde/Imap/Client/Socket.php @@ -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']); diff --git a/framework/Imap_Client/lib/Horde/Imap/Client/Socket/Pop3.php b/framework/Imap_Client/lib/Horde/Imap/Client/Socket/Pop3.php index e87abad6b..66d861d4e 100644 --- a/framework/Imap_Client/lib/Horde/Imap/Client/Socket/Pop3.php +++ b/framework/Imap_Client/lib/Horde/Imap/Client/Socket/Pop3.php @@ -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; } /** -- 2.11.0