From bddb3448fd8562229509f3b49092bc4fe05dbc9f Mon Sep 17 00:00:00 2001 From: kink Date: Sun, 21 Nov 2004 13:10:06 +0000 Subject: [PATCH] Add support for recognising 'Priority' and 'Importance' headers next to the 'X-Priority' that we've been supporting for a long time. git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@8388 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- ChangeLog | 2 ++ class/mime/Rfc822Header.class.php | 31 +++++++++++++++++++++++++++++-- functions/imap_messages.php | 20 ++++++++++++++++++-- functions/mailbox_display.php | 4 ++-- 4 files changed, 51 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index c489bc4a..7579b99e 100644 --- a/ChangeLog +++ b/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 -------------------- diff --git a/class/mime/Rfc822Header.class.php b/class/mime/Rfc822Header.class.php index e8097976..4424755a 100644 --- a/class/mime/Rfc822Header.class.php +++ b/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 { } } -?> \ No newline at end of file +?> diff --git a/functions/imap_messages.php b/functions/imap_messages.php index 27eab41b..5399847e 100755 --- a/functions/imap_messages.php +++ b/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; diff --git a/functions/mailbox_display.php b/functions/mailbox_display.php index 4d0e4524..0e82d4db 100644 --- a/functions/mailbox_display.php +++ b/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 -?> \ No newline at end of file +?> -- 2.25.1