summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoralecpl <alec@alec.pl>2010-03-31 07:14:32 +0000
committeralecpl <alec@alec.pl>2010-03-31 07:14:32 +0000
commit6f31b356b2b21882b439324d233aceec413f4737 (patch)
tree6830ba38afe65f25ae34242d48a420011d10f67b
parent024f05762a66dde984785f868b8965905784072d (diff)
- fix save/delete draft message with enabled threading (#1486596)
- performance improvement using UID SEARCH intead of SEARCH + FETCH - re-fix r3445
-rw-r--r--program/include/rcube_imap.php21
-rw-r--r--program/include/rcube_imap_generic.php9
-rw-r--r--program/steps/mail/sendmail.inc10
3 files changed, 31 insertions, 9 deletions
diff --git a/program/include/rcube_imap.php b/program/include/rcube_imap.php
index 26d0ef48a..7dc70df32 100644
--- a/program/include/rcube_imap.php
+++ b/program/include/rcube_imap.php
@@ -1414,6 +1414,27 @@ class rcube_imap
return $a_messages;
}
+
+ /**
+ * Direct (real and simple) SEARCH request to IMAP server,
+ * without result sorting and caching
+ *
+ * @param string Mailbox name to search in
+ * @param string Search string
+ * @param boolean True if UIDs should be returned
+ * @return array Search results as list of message IDs or UIDs
+ * @access public
+ */
+ function search_once($mbox_name='', $str=NULL, $ret_uid=false)
+ {
+ if (!$str)
+ return false;
+
+ $mailbox = $mbox_name ? $this->mod_mailbox($mbox_name) : $this->mailbox;
+
+ return $this->conn->search($mailbox, $str, $ret_uid);
+ }
+
/**
* Sort thread
diff --git a/program/include/rcube_imap_generic.php b/program/include/rcube_imap_generic.php
index ed2788a02..41c053da2 100644
--- a/program/include/rcube_imap_generic.php
+++ b/program/include/rcube_imap_generic.php
@@ -366,7 +366,7 @@ class rcube_imap_generic
}
// generate hash
- $hash = md5($this->xor($pass,$opad) . pack("H*", md5($this->xor($pass, $ipad) . base64_decode($encChallenge))));
+ $hash = md5($this->_xor($pass,$opad) . pack("H*", md5($this->_xor($pass, $ipad) . base64_decode($encChallenge))));
// generate reply
$reply = base64_encode($user . ' ' . $hash);
@@ -1553,18 +1553,19 @@ class rcube_imap_generic
return false;
}
- function search($folder, $criteria)
+ function search($folder, $criteria, $return_uid=false)
{
if (!$this->select($folder)) {
return false;
}
$data = '';
- $query = "srch1 SEARCH " . chop($criteria);
+ $query = 'srch1 ' . ($return_uid ? 'UID ' : '') . 'SEARCH ' . chop($criteria);
if (!$this->putLineC($query)) {
return false;
}
+
do {
$line = trim($this->readLine());
if ($this->startsWith($line, '* SEARCH')) {
@@ -2150,7 +2151,7 @@ class rcube_imap_generic
return $result;
}
- private function xor($string, $string2)
+ private function _xor($string, $string2)
{
$result = '';
$size = strlen($string);
diff --git a/program/steps/mail/sendmail.inc b/program/steps/mail/sendmail.inc
index d6ef159dd..b89edc473 100644
--- a/program/steps/mail/sendmail.inc
+++ b/program/steps/mail/sendmail.inc
@@ -617,9 +617,9 @@ if ($store_target)
if ($olddraftmessageid)
{
// delete previous saved draft
- $a_deleteid = $IMAP->search($CONFIG['drafts_mbox'], 'HEADER Message-ID '.$olddraftmessageid);
-
- $deleted = $IMAP->delete_message($IMAP->get_uid($a_deleteid[0], $CONFIG['drafts_mbox']), $CONFIG['drafts_mbox']);
+ $a_deleteid = $IMAP->search_once($CONFIG['drafts_mbox'],
+ 'HEADER Message-ID '.$olddraftmessageid, true);
+ $deleted = $IMAP->delete_message($a_deleteid, $CONFIG['drafts_mbox']);
// raise error if deletion of old draft failed
if (!$deleted)
@@ -639,8 +639,8 @@ if ($savedraft)
$msgid = strtr($message_id, array('>' => '', '<' => ''));
// remember new draft-uid
- $draftids = $IMAP->search($CONFIG['drafts_mbox'], 'HEADER Message-ID '.$msgid);
- $_SESSION['compose']['param']['_draft_uid'] = $IMAP->get_uid($draftids[0], $CONFIG['drafts_mbox']);
+ $draftuids = $IMAP->search_once($CONFIG['drafts_mbox'], 'HEADER Message-ID '.$msgid, true);
+ $_SESSION['compose']['param']['_draft_uid'] = $draftuids[0];
// display success
$OUTPUT->show_message('messagesaved', 'confirmation');