Replacing tabs with spaces, trimming white space at EOL and newline at EOF (PHP only)
[squirrelmail.git] / functions / imap_messages.php
index 27eab41b45da6ff7c3f4bf26699113975e16b884..cb2cf325c13f5caf35cf41ace1c2ca8ecc032a71 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
@@ -242,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) {
@@ -479,6 +479,19 @@ function elapsedTime($start) {
 }
 
 
+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 +573,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();
@@ -714,7 +727,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 +972,4 @@ function sqimap_get_small_header($imap_stream, $id, $sent) {
     return $res[0];
 }
 
-?>
+?>
\ No newline at end of file