X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=functions%2Fimap_messages.php;h=606c99c15de6f490e45d3455fca78ed516f944a4;hb=dc027257ddbb2de540e88a22d038c69e4fab29c0;hp=de96678592661fd5836e610c212b5124d0f78021;hpb=8d8da447778a43b78bc95f9601b385416ad84477;p=squirrelmail.git diff --git a/functions/imap_messages.php b/functions/imap_messages.php index de966785..606c99c1 100755 --- a/functions/imap_messages.php +++ b/functions/imap_messages.php @@ -3,7 +3,7 @@ /** * imap_messages.php * - * Copyright (c) 1999-2004 The SquirrelMail Project Team + * Copyright (c) 1999-2005 The SquirrelMail Project Team * Licensed under the GNU GPL. For full terms see the file COPYING. * * This implements functions that manipulate messages @@ -20,11 +20,12 @@ * @param int $imap_stream The resource ID for the IMAP socket * @param string $id The list of messages to copy * @param string $mailbox The destination to copy to - * @return bool + * @param bool $handle_errors Show error messages in case of a NO, BAD or BYE response + * @return bool If the copy completed without errors */ -function sqimap_msgs_list_copy($imap_stream, $id, $mailbox) { +function sqimap_msgs_list_copy($imap_stream, $id, $mailbox, $handle_errors = true) { $msgs_id = sqimap_message_list_squisher($id); - $read = sqimap_run_command ($imap_stream, "COPY $msgs_id " . sqimap_encode_mailbox_name($mailbox), true, $response, $message, TRUE); + $read = sqimap_run_command ($imap_stream, "COPY $msgs_id " . sqimap_encode_mailbox_name($mailbox), $handle_errors, $response, $message, TRUE); if ($response == 'OK') { return true; } else { @@ -38,11 +39,12 @@ function sqimap_msgs_list_copy($imap_stream, $id, $mailbox) { * @param int $imap_stream The resource ID for the IMAP socket * @param string $id The list of messages to move * @param string $mailbox The destination to move to - * @return void + * @param bool $handle_errors Show error messages in case of a NO, BAD or BYE response + * @return bool If the move completed without errors */ -function sqimap_msgs_list_move($imap_stream, $id, $mailbox) { +function sqimap_msgs_list_move($imap_stream, $id, $mailbox, $handle_errors = true) { $msgs_id = sqimap_message_list_squisher($id); - if (sqimap_msgs_list_copy ($imap_stream, $id, $mailbox)) { + if (sqimap_msgs_list_copy ($imap_stream, $id, $mailbox, $handle_errors)) { return sqimap_toggle_flag($imap_stream, $id, '\\Deleted', true, true); } else { return false; @@ -55,8 +57,9 @@ function sqimap_msgs_list_move($imap_stream, $id, $mailbox) { * @param resource imap connection * @param string $mailbox mailbox, used for checking if it concerns the trash_folder * @param array $id list with uid's - * @param bool $bypass_trash skip copy to trash + * @param bool $bypass_trash (since 1.5.0) skip copy to trash * @return array $aMessageList array with messages containing the new flags and UID @see parseFetch + * @since 1.4.0 */ function sqimap_msgs_list_delete($imap_stream, $mailbox, $id, $bypass_trash=false) { // FIX ME, remove globals by introducing an associative array with properties @@ -204,7 +207,7 @@ function get_squirrel_sort($imap_stream, $sSortField, $reverse = false, $aUid = $sPersonal = (isset($addr[SQM_ADDR_PERSONAL]) && $addr[SQM_ADDR_PERSONAL]) ? $addr[SQM_ADDR_PERSONAL] : ""; $sEmail = ($addr[SQM_ADDR_HOST]) ? - $addr[SQM_ADDR_HOST] . "@".$addr[SQM_ADDR_HOST] : + $addr[SQM_ADDR_MAILBOX] . "@".$addr[SQM_ADDR_HOST] : $addr[SQM_ADDR_HOST]; $v[$f] = ($sPersonal) ? decodeHeader($sPersonal):$sEmail;'),$sSortField); $walk = true; @@ -242,7 +245,7 @@ function get_squirrel_sort($imap_stream, $sSortField, $reverse = false, $aUid = case 'RFC822.SIZE': if(!$walk) { // redefine $sSortField to maintain the same namespace between - // server-side sorting and squirrelmail sorting + // server-side sorting and SquirrelMail sorting $sSortField = 'SIZE'; } foreach ($msgs as $item) { @@ -479,6 +482,30 @@ function elapsedTime($start) { } +/** + * Normalise the different Priority headers into a uniform value, + * namely that of the X-Priority header (1, 3, 5). Supports: + * Prioirty, X-Priority, Importance. + * X-MS-Mail-Priority is not parsed because it always coincides + * with one of the other headers. + * + * DUPLICATE CODE ALERT: + * NOTE: this is actually a duplicate from the function in + * class/mime/Rfc822Header.php. + */ +function parsePriority($value) { + $value = strtolower(array_shift(split('/\w/',trim($value)))); + if ( is_numeric($value) ) { + return $value; + } + if ( $value == 'urgent' || $value == 'high' ) { + return 1; + } elseif ( $value == 'non-urgent' || $value == 'low' ) { + return 5; + } + return 3; +} + /** * Parses a string in an imap response. String starts with " or { which means it * can handle double quoted strings and literal strings @@ -560,7 +587,7 @@ function parseArray($read,&$i) { * @return array $aMessages associative array with messages. Key is the UID, value is an associative array */ function sqimap_get_small_header_list($imap_stream, $msg_list, - $aHeaderFields = array('Date', 'To', 'Cc', 'From', 'Subject', 'X-Priority', 'Content-Type'), + $aHeaderFields = array('Date', 'To', 'Cc', 'From', 'Subject', 'X-Priority', 'Importance', 'Priority', 'Content-Type'), $aFetchItems = array('FLAGS', 'RFC822.SIZE', 'INTERNALDATE')) { $aMessageList = array(); @@ -687,7 +714,7 @@ function parseFetch($aResponse,$aMessageList = array()) { case 'BODYSTRUCTURE': break; case 'INTERNALDATE': - $msg['INTERNALDATE'] = str_replace(' ', ' ',parseString($read,$i)); + $msg['INTERNALDATE'] = trim(str_replace(' ', ' ',parseString($read,$i))); break; case 'BODY.PEEK[HEADER.FIELDS': case 'BODY[HEADER.FIELDS': @@ -714,7 +741,10 @@ function parseFetch($aResponse,$aMessageList = array()) { case 'date': $msg['DATE'] = str_replace(' ', ' ', $value); break; - case 'x-priority': $msg['PRIORITY'] = $value; break; + case 'x-priority': + case 'importance': + case 'priority': + $msg['PRIORITY'] = parsePriority($value); break; case 'subject': $msg['SUBJECT'] = $value; break; case 'content-type': $type = $value; @@ -956,4 +986,4 @@ function sqimap_get_small_header($imap_stream, $id, $sent) { return $res[0]; } -?> \ No newline at end of file +?>