* 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);
}
/**
*
* @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);
*
* @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)) {
if (!empty($unflag)) {
$this->store($this->_selected, array('add' => array('\\deleted'), 'ids' => $unflag, 'sequence' => $use_seq));
}
+
+ return $msg_list ? $ids['match'] : null;
}
/**
*
* @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)
$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
$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'];
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']);
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.
} catch (Horde_Imap_Client_Exception $e) {}
fclose($this->_stream);
$this->_stream = null;
+ $this->_deleted = array();
}
}
* @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;
}
/**