Explorar o código

Add support for recognising 'Priority' and 'Importance' headers next to the
'X-Priority' that we've been supporting for a long time.

Thijs Kinkhorst %!s(int64=20) %!d(string=hai) anos
pai
achega
7f32e1d4d0
Modificáronse 4 ficheiros con 51 adicións e 6 borrados
  1. 2 0
      ChangeLog
  2. 29 2
      class/mime/Rfc822Header.class.php
  3. 18 2
      functions/imap_messages.php
  4. 2 2
      functions/mailbox_display.php

+ 2 - 0
ChangeLog

@@ -156,6 +156,8 @@ Version 1.5.1 -- CVS
     instead of php xml extension. Fixes bug #655137.
   - Added Wood theme and Silver Steel theme by Pavel Spatny and Simple Green theme
   - Fix two time zone calculation bugs, thanks to David White
+  - 'Priority' and 'Importance' headers are now also recognised, next to the
+    'X-Priority' header that we've supported since a long time.
 
 Version 1.5.0
 --------------------

+ 29 - 2
class/mime/Rfc822Header.class.php

@@ -186,7 +186,9 @@ class Rfc822Header {
                 $this->xmailer = $value;
                 break;
             case 'x-priority':
-                $this->priority = $value;
+            case 'importance':
+            case 'priority':
+                $this->priority = $this->parsePriority($value);
                 break;
             case 'list-post':
                 $value = $this->stripComments($value);
@@ -504,6 +506,31 @@ class Rfc822Header {
         }
     }
 
+    /**
+     * 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.
+     *
+     * NOTE: this is actually a duplicate from the function in
+     * functions/imap_messages. I'm not sure if it's ok here to call
+     * that function?
+     */
+    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;
+        }
+        // default is normal priority
+        return 3;
+    }
+
     function parseContentType($value) {
         $pos = strpos($value, ';');
         $props = '';
@@ -751,4 +778,4 @@ class Rfc822Header {
     }
 }
 
-?>
+?>

+ 18 - 2
functions/imap_messages.php

@@ -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;

+ 2 - 2
functions/mailbox_display.php

@@ -838,7 +838,7 @@ function fetchMessageHeaders($imapConnection, &$aMailbox) {
     }
 
     // initialize the fields we want to retrieve:
-    $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');
 
     // Are we sorting on internaldate then retrieve the internaldate value as well
@@ -2141,4 +2141,4 @@ function attachSelectedMessages($imapConnection,$aMsgHeaders) {
 }
 
 // vim: et ts=4
-?>
+?>