Add comment to parsePriority function. I had to duplicate this function in
[squirrelmail.git] / functions / imap_messages.php
index 6a6c076707976f4d91afda086ed6df1a56922a06..7f4614872f8ba91b1f77810e6df169ec4dae7fca 100755 (executable)
@@ -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
@@ -133,10 +133,6 @@ function sqimap_message_list_squisher($messages_array) {
 function sqimap_get_sort_order($imap_stream, $sSortField, $reverse, $search='ALL') {
     global  $default_charset;
 
-    $id = array();
-    $sort_test = array();
-    $sort_query = '';
-
     if ($sSortField) {
         if ($reverse) {
             $sSortField = 'REVERSE '.$sSortField;
@@ -208,7 +204,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;
@@ -246,7 +242,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) {
@@ -429,7 +425,6 @@ function get_thread_sort($imap_stream, $search='ALL') {
         $thread_temp = preg_split("//", $thread_list, -1, PREG_SPLIT_NO_EMPTY);
     }
 
-    $char_count = count($thread_temp);
     $counter = 0;
     $thread_new = array();
     $k = 0;
@@ -484,6 +479,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
@@ -565,11 +584,10 @@ 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();
-    $read_list = array();
 
     $bUidFetch = ! in_array('UID', $aFetchItems, true);
 
@@ -588,7 +606,6 @@ function sqimap_get_small_header_list($imap_stream, $msg_list,
         }
     } else {
         $msgs_str = '1:*';
-        $aId = array();
     }
 
     /*
@@ -694,7 +711,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':
@@ -721,7 +738,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;
@@ -963,4 +983,4 @@ function sqimap_get_small_header($imap_stream, $id, $sent) {
     return $res[0];
 }
 
-?>
\ No newline at end of file
+?>