- Use consistent results from some functions, code cleanup

release-0.6
alecpl 14 years ago
parent c309cd8928
commit 93272ea91b

@ -2474,8 +2474,7 @@ class rcube_imap
} }
// move messages // move messages
$move = $this->conn->move($uids, $from_mbox, $to_mbox); $moved = $this->conn->move($uids, $from_mbox, $to_mbox);
$moved = !($move === false || $move < 0);
// send expunge command in order to have the moved message // send expunge command in order to have the moved message
// really deleted from the source mailbox // really deleted from the source mailbox
@ -2536,8 +2535,9 @@ class rcube_imap
list($uids, $all_mode) = $this->_parse_uids($uids, $from_mbox); list($uids, $all_mode) = $this->_parse_uids($uids, $from_mbox);
// exit if no message uids are specified // exit if no message uids are specified
if (empty($uids)) if (empty($uids)) {
return false; return false;
}
// make sure mailbox exists // make sure mailbox exists
if ($to_mbox != 'INBOX' && !$this->mailbox_exists($tbox, true)) { if ($to_mbox != 'INBOX' && !$this->mailbox_exists($tbox, true)) {
@ -2548,8 +2548,7 @@ class rcube_imap
} }
// copy messages // copy messages
$copy = $this->conn->copy($uids, $from_mbox, $to_mbox); $copied = $this->conn->copy($uids, $from_mbox, $to_mbox);
$copied = !($copy === false || $copy < 0);
if ($copied) { if ($copied) {
$this->_clear_messagecount($to_mbox); $this->_clear_messagecount($to_mbox);
@ -3650,7 +3649,7 @@ class rcube_imap
if (!$msg_count) if (!$msg_count)
return $cache_count ? -2 : 1; return $cache_count ? -2 : 1;
if ($cache_count==$msg_count) { if ($cache_count == $msg_count) {
if ($this->skip_deleted) { if ($this->skip_deleted) {
$h_index = $this->conn->fetchHeaderIndex($mailbox, "1:*", 'UID', $this->skip_deleted); $h_index = $this->conn->fetchHeaderIndex($mailbox, "1:*", 'UID', $this->skip_deleted);

@ -1199,35 +1199,52 @@ class rcube_imap_generic
return implode(',', $result); return implode(',', $result);
} }
function UID2ID($folder, $uid) /**
* Returns message sequence identifier
*
* @param string $mailbox Mailbox name
* @param int $uid Message unique identifier (UID)
*
* @return int Message sequence identifier
* @access public
*/
function UID2ID($mailbox, $uid)
{ {
if ($uid > 0) { if ($uid > 0) {
$id_a = $this->search($folder, "UID $uid"); $id_a = $this->search($mailbox, "UID $uid");
if (is_array($id_a) && count($id_a) == 1) { if (is_array($id_a) && count($id_a) == 1) {
return $id_a[0]; return (int) $id_a[0];
} }
} }
return false; return null;
} }
function ID2UID($folder, $id) /**
* Returns message unique identifier (UID)
*
* @param string $mailbox Mailbox name
* @param int $uid Message sequence identifier
*
* @return int Message unique identifier
* @access public
*/
function ID2UID($mailbox, $id)
{ {
if (empty($id)) { if (empty($id) || $id < 0) {
return -1; return null;
} }
if (!$this->select($folder)) { if (!$this->select($folder)) {
return -1; return null;
} }
$result = -1;
list($code, $response) = $this->execute('FETCH', array($id, '(UID)')); list($code, $response) = $this->execute('FETCH', array($id, '(UID)'));
if ($code == self::ERROR_OK && preg_match("/^\* $id FETCH \(UID (.*)\)/i", $response, $m)) { if ($code == self::ERROR_OK && preg_match("/^\* $id FETCH \(UID (.*)\)/i", $response, $m)) {
$result = $m[1]; return (int) $m[1];
} }
return $result; return null;
} }
function fetchUIDs($mailbox, $message_set=null) function fetchUIDs($mailbox, $message_set=null)
@ -1615,18 +1632,32 @@ class rcube_imap_generic
function copy($messages, $from, $to) function copy($messages, $from, $to)
{ {
if (empty($from) || empty($to)) { if (empty($from) || empty($to)) {
return -1; return false;
} }
if (!$this->select($from)) { if (!$this->select($from)) {
return -1; return false;
} }
$result = $this->execute('UID COPY', array( $result = $this->execute('UID COPY', array(
$this->compressMessageSet($messages), $this->escape($to)), $this->compressMessageSet($messages), $this->escape($to)),
self::COMMAND_NORESPONSE); self::COMMAND_NORESPONSE);
return $result; return ($result == self::ERROR_OK);
}
function move($messages, $from, $to)
{
if (!$from || !$to) {
return false;
}
$r = $this->copy($messages, $from, $to);
if ($r) {
return $this->delete($from, $messages);
}
return $r;
} }
// Don't be tempted to change $str to pass by reference to speed this up - it will slow it down by about // Don't be tempted to change $str to pass by reference to speed this up - it will slow it down by about
@ -1806,20 +1837,6 @@ class rcube_imap_generic
return false; return false;
} }
function move($messages, $from, $to)
{
if (!$from || !$to) {
return -1;
}
$r = $this->copy($messages, $from, $to);
if ($r==0) {
return $this->delete($from, $messages);
}
return $r;
}
/** /**
* Returns list of mailboxes * Returns list of mailboxes
* *

Loading…
Cancel
Save