From: Michael M Slusarz Date: Fri, 4 Dec 2009 19:48:26 +0000 (-0700) Subject: Simplify and improve priority header generation/display X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=164cdc31b8275631294c77f94672218f67afdb7c;p=horde.git Simplify and improve priority header generation/display --- diff --git a/imp/compose.php b/imp/compose.php index 61bfba6d8..fa9ee82a1 100644 --- a/imp/compose.php +++ b/imp/compose.php @@ -414,7 +414,7 @@ case 'send_message': 'sent_folder' => $sent_mail_folder, 'save_attachments' => Horde_Util::getFormData('save_attachments_select'), 'encrypt' => $prefs->isLocked('default_encrypt') ? $prefs->getValue('default_encrypt') : Horde_Util::getFormData('encrypt_options'), - 'priority' => Horde_Util::getFormData('x_priority'), + 'priority' => Horde_Util::getFormData('priority'), 'readreceipt' => Horde_Util::getFormData('request_read_receipt') ); @@ -1021,13 +1021,11 @@ if ($redirect) { $t->set('priority_label', Horde::label('priority', _("_Priority"))); $t->set('priority_tabindex', ++$tabindex); - $priority = Horde_Util::getFormData('x_priority', 3); + $priority = Horde_Util::getFormData('priority', 'normal'); $priorities = array( - 1 => '1 (' . _("Highest") . ')', - 2 => '2 (' . _("High") . ')', - 3 => '3 (' . _("Normal") . ')', - 4 => '4 (' . _("Low") . ')', - 5 => '5 (' . _("Lowest") . ')' + 'high' => _("High"), + 'normal' => _("Normal"), + 'low' => _("Low") ); $priority_option = array(); foreach ($priorities as $key => $val) { diff --git a/imp/config/prefs.php.dist b/imp/config/prefs.php.dist index 42a1f8e71..99ee9f462 100644 --- a/imp/config/prefs.php.dist +++ b/imp/config/prefs.php.dist @@ -603,14 +603,14 @@ $_prefs['compose_confirm'] = array( 'type' => 'checkbox', 'desc' => _("Display confirmation after sending a message?")); -// allow the user to add a "X-Priority" header when composing messages? +// allow the user to add a priority header when composing messages? $_prefs['set_priority'] = array( 'value' => 1, // Locked by default 'locked' => true, 'shared' => false, 'type' => 'checkbox', - 'desc' => _("Set the X-Priority header when composing messages?")); + 'desc' => _("Set a priority header when composing messages?")); // compose in a separate window? $_prefs['compose_popup'] = array( diff --git a/imp/docs/CHANGES b/imp/docs/CHANGES index f4957a40c..73a1676bd 100644 --- a/imp/docs/CHANGES +++ b/imp/docs/CHANGES @@ -2,6 +2,7 @@ v5.0-git -------- +[mms] Simplify and improve priority header generation/display. [mms] Add Face: header support to IMP. [mms] Add splitbar to resize sidebar in DIMP. [mms] Use LIST-EXTENDED IMAP extension (RFC 5258) to get subscribed diff --git a/imp/docs/RFCS b/imp/docs/RFCS index 69328f7d6..9c030a39d 100644 --- a/imp/docs/RFCS +++ b/imp/docs/RFCS @@ -45,9 +45,12 @@ RFC 5256 THREAD/SORT RFC 5258 LIST-EXTENDED RFC 5267 ESORT RFC 5464 METADATA +RFC 5530 IMAP Response Codes RFC 5550 Lemonade Profile (specifically [2.8] - $Forwarded flag) draft-ietf-morg-sortdisplay-02 SORT=DISPLAY +draft-ietf-morg-inthread-00 THREAD=REFS + POP3 @@ -141,3 +144,7 @@ Non-RFC Features Face Header (view support) - http://quimby.gnus.org/circus/face/ + +Importance/Priority Header + - See, e.g., RFC 4356 [2.1.3.3.1] + http://kb.mozillazine.org/Emulate_Microsoft_email_clients diff --git a/imp/lib/Compose.php b/imp/lib/Compose.php index b9b40f522..8db4bc8e3 100644 --- a/imp/lib/Compose.php +++ b/imp/lib/Compose.php @@ -424,7 +424,7 @@ class IMP_Compose * 'encrypt' => (integer) A flag whether to encrypt or sign the message. * One of IMP::PGP_ENCRYPT, IMP::PGP_SIGNENC, * IMP::SMIME_ENCRYPT, or IMP::SMIME_SIGNENC. - * 'priority' => (integer) The message priority from 1 to 5. + * 'priority' => (string) The message priority ('high', 'normal', 'low'). * 'readreceipt' => (bool) Add return receipt headers? * 'useragent' => (string) The User-Agent string to use. * @@ -481,31 +481,19 @@ class IMP_Compose $headers->addReceivedHeader(); $headers->addMessageIdHeader(); - /* Add the X-Priority header, if requested. */ + /* Add priority header, if requested. */ if (!empty($opts['priority'])) { - $priority = $opts['priority']; - switch ($priority) { - case 1: - $priority .= ' (Highest)'; + switch ($opts['priority']) { + case 'high': + $headers->addHeader('Importance', 'High'); + $headers->addHeader('X-Priority', '1 (Highest)'); break; - case 2: - $priority .= ' (High)'; - break; - - case 3: - $priority .= ' (Normal)'; - break; - - case 4: - $priority .= ' (Low)'; - break; - - case 5: - $priority .= ' (Lowest)'; + case 'low': + $headers->addHeader('Importance', 'Low'); + $headers->addHeader('X-Priority', '5 (Lowest)'); break; } - $headers->addHeader('X-Priority', $priority); } $headers->addHeader('Date', date('r')); diff --git a/imp/lib/Imap/Flags.php b/imp/lib/Imap/Flags.php index c8c4db236..21e3fd71c 100644 --- a/imp/lib/Imap/Flags.php +++ b/imp/lib/Imap/Flags.php @@ -233,8 +233,8 @@ class IMP_Imap_Flags * addresses as returned by * Horde_Mime_Address::getAddressesFromObject(), or the * identity that matched the address list.. - * 'priority' - (string) Message priority. The content of the X-Priority - * header. + * 'priority' - (Horde_Mime_Headers) Determines priority information from + * a headers object. * * * @return array A list of flags with the following keys: @@ -272,8 +272,8 @@ class IMP_Imap_Flags } if (!empty($options['priority'])) { - $imp_msg_ui = new IMP_Ui_Message(); - switch ($imp_msg_ui->getXpriority($options['priority'])) { + $imp_hdr_ui = new IMP_Ui_Headers(); + switch ($imp_hdr_ui->getPriority($options['priority'])) { case 'high': $process['highpri'] = $f['highpri']; break; diff --git a/imp/lib/Mailbox.php b/imp/lib/Mailbox.php index 6e6773b9f..a104359da 100644 --- a/imp/lib/Mailbox.php +++ b/imp/lib/Mailbox.php @@ -158,7 +158,7 @@ class IMP_Mailbox * @param array $options Additional options: *
      * 'headers' - (boolean) Return info on the non-envelope headers
-     *             'List-Post' and 'X-Priority'.
+     *             'Importance', 'List-Post', and 'X-Priority'.
      *             DEFAULT: false (only envelope headers returned)
      * 'preview' - (mixed) Include preview information?  If empty, add no
      *                     preview information. If 1, uses value from prefs.
@@ -225,7 +225,7 @@ class IMP_Mailbox
         );
 
         if (!empty($options['headers'])) {
-            $fetch_criteria[Horde_Imap_Client::FETCH_HEADERS] = array(array('cache' => true, 'headers' => array('list-post', 'x-priority'), 'label' => 'imp', 'parse' => true, 'peek' => true));
+            $fetch_criteria[Horde_Imap_Client::FETCH_HEADERS] = array(array('cache' => true, 'headers' => array('importance', 'list-post', 'x-priority'), 'label' => 'imp', 'parse' => true, 'peek' => true));
         }
 
         if (!empty($options['structure'])) {
diff --git a/imp/lib/Ui/Headers.php b/imp/lib/Ui/Headers.php
new file mode 100644
index 000000000..13217209c
--- /dev/null
+++ b/imp/lib/Ui/Headers.php
@@ -0,0 +1,42 @@
+
+ * @package IMP
+ */
+class IMP_Ui_Headers
+{
+    /**
+     * Determines the priority of the message based on the headers.
+     *
+     * @param Horde_Mime_Headers $header  The headers object.
+     *
+     * @return string  'high', 'low', or 'normal'.
+     */
+    public function getPriority($header)
+    {
+        if (preg_match('/\s*(\d+)\s*/', $header->getValue('x-priority'), $matches)) {
+            if (in_array($matches[1], array(1, 2))) {
+                return 'high';
+            } elseif (in_array($matches[1], array(4, 5))) {
+                return 'low';
+            }
+        } elseif (preg_match('/:\s*(\w+)\s*/', $header->getValue('importance'), $matches)) {
+            if (strcasecmp($matches[1], 'high') === 0) {
+                return 'high';
+            } elseif (strcasecmp($matches[1], 'low') === 0) {
+                return 'low';
+            }
+        }
+
+        return 'normal';
+    }
+
+}
diff --git a/imp/lib/Ui/Message.php b/imp/lib/Ui/Message.php
index df70048ee..7e73251a9 100644
--- a/imp/lib/Ui/Message.php
+++ b/imp/lib/Ui/Message.php
@@ -255,26 +255,6 @@ class IMP_Ui_Message
     }
 
     /**
-     * Determines the X-Priority of the message based on the headers.
-     *
-     * @param string $header  The X-Priority header.
-     *
-     * @return string  'high', 'low', or 'normal'.
-     */
-    public function getXpriority($header)
-    {
-        if ($header && preg_match('/\s*(\d+)\s*/', $header, $matches)) {
-            if (in_array($matches[1], array(1, 2))) {
-                return 'high';
-            } elseif (in_array($matches[1], array(4, 5))) {
-                return 'low';
-            }
-        }
-
-        return 'normal';
-    }
-
-    /**
      * Returns e-mail information for a mailing list.
      *
      * @param Horde_Mime_Headers $headers  A Horde_Mime_Headers object.
diff --git a/imp/lib/Views/ListMessages.php b/imp/lib/Views/ListMessages.php
index 58c176c83..f0ef826b2 100644
--- a/imp/lib/Views/ListMessages.php
+++ b/imp/lib/Views/ListMessages.php
@@ -297,7 +297,7 @@ class IMP_Views_ListMessages
                 'atc' => isset($ob['structure']) ? $ob['structure'] : null,
                 'flags' => $ob['flags'],
                 'personal' => Horde_Mime_Address::getAddressesFromObject($ob['envelope']['to']),
-                'priority' => $ob['headers']->getValue('x-priority')
+                'priority' => $ob['headers']
             ));
 
             if (!empty($flag_parse)) {
diff --git a/imp/lib/Views/ShowMessage.php b/imp/lib/Views/ShowMessage.php
index d3970290f..3c8cdae39 100644
--- a/imp/lib/Views/ShowMessage.php
+++ b/imp/lib/Views/ShowMessage.php
@@ -83,7 +83,7 @@ class IMP_Views_ShowMessage
      * 'bcc' - The Bcc addresses
      * 'headers' - An array of headers (not including basic headers)
      * 'list_info' - List information.
-     * 'priority' - The X-Priority of the message ('low', 'high', 'normal')
+     * 'priority' - The priority of the message ('low', 'high', 'normal')
      * 'replyTo' - The Reply-to addresses
      * 'save_as' - The save link
      * 'title' - The title of the page
@@ -131,7 +131,10 @@ class IMP_Views_ShowMessage
         $envelope = $fetch_ret[$uid]['envelope'];
         $mime_headers = reset($fetch_ret[$uid]['headertext']);
 
-        /* Get the IMP_Ui_Message:: object. */
+        /* Initialize variables. */
+        if (!$preview) {
+            $imp_hdr_ui = new IMP_Ui_Headers();
+        }
         $imp_ui = new IMP_Ui_Message();
 
         /* Develop the list of Headers to display now. Deal with the 'basic'
@@ -234,9 +237,9 @@ class IMP_Views_ShowMessage
             }
         }
 
-        /* Get X-Priority. */
+        /* Get message priority. */
         if (!$preview) {
-            $result['priority'] = $imp_ui->getXpriority($mime_headers->getValue('x-priority'));
+            $result['priority'] = $imp_hdr_ui->getPriority($mime_headers);
         }
 
         // Create message text and attachment list.
diff --git a/imp/mailbox-mimp.php b/imp/mailbox-mimp.php
index d76982747..7ba5d0568 100644
--- a/imp/mailbox-mimp.php
+++ b/imp/mailbox-mimp.php
@@ -142,7 +142,7 @@ while (list(,$ob) = each($mbox_info['overview'])) {
     $flag_parse = $imp_flags->parse(array(
         'flags' => $ob['flags'],
         'personal' => Horde_Mime_Address::getAddressesFromObject($ob['envelope']['to']),
-        'priority' => $ob['headers']->getValue('x-priority')
+        'priority' => $ob['headers']
     ));
 
     foreach ($flag_parse as $val) {
diff --git a/imp/mailbox.php b/imp/mailbox.php
index 7df04ddd7..7a0145afe 100644
--- a/imp/mailbox.php
+++ b/imp/mailbox.php
@@ -738,7 +738,7 @@ while (list(,$ob) = each($mbox_info['overview'])) {
         'div' => true,
         'flags' => $ob['flags'],
         'personal' => Horde_Mime_Address::getAddressesFromObject($ob['envelope']['to']),
-        'priority' => $ob['headers']->getValue('x-priority')
+        'priority' => $ob['headers']
     ));
 
     $subject_flags = array();
diff --git a/imp/message-mimp.php b/imp/message-mimp.php
index 7f72f6a90..7cf7efb16 100644
--- a/imp/message-mimp.php
+++ b/imp/message-mimp.php
@@ -29,6 +29,7 @@ if (!$imp_mailbox->isValidIndex(false)) {
 }
 
 $imp_message = IMP_Message::singleton();
+$imp_hdr_ui = new IMP_Ui_Headers();
 $imp_ui = new IMP_Ui_Message();
 
 /* Determine if mailbox is readonly. */
@@ -199,13 +200,12 @@ $display_headers['subject'] = $subject;
 /* Check for the presence of mailing list information. */
 $list_info = $imp_ui->getListInformation($mime_headers);
 
-/* See if the 'X-Priority' header has been set. */
-$xpriority = $mime_headers->getValue('x-priority');
-switch ($imp_ui->getXpriority($xpriority)) {
+/* See if the priority has been set. */
+switch($priority = $imp_hdr_ui->getPriority($mime_headers)) {
 case 'high':
 case 'low':
     $basic_headers['priority'] = _("Priority");
-    $display_headers['priority'] = $xpriority;
+    $display_headers['priority'] = Horde_String::ucfirst($priority);
     break;
 }
 
diff --git a/imp/message.php b/imp/message.php
index a1bd91350..ec6560d28 100644
--- a/imp/message.php
+++ b/imp/message.php
@@ -68,6 +68,7 @@ $uid = $index_array['uid'];
 $indices_array = array($mailbox_name => array($uid));
 
 $imp_flags = IMP_Imap_Flags::singleton();
+$imp_hdr_ui = new IMP_Ui_Headers();
 $imp_ui = new IMP_Ui_Message();
 
 switch ($actionID) {
@@ -288,17 +289,16 @@ if ($subject = $mime_headers->getValue('subject')) {
     $title = sprintf(_("%s: %s"), $page_label, $shortsub);
 }
 
-/* See if the 'X-Priority' header has been set. */
-$xpriority = $mime_headers->getValue('x-priority');
-switch ($imp_ui->getXpriority($xpriority)) {
+/* See if the priority has been set. */
+switch ($priority = $imp_hdr_ui->getPriority($mime_headers)) {
 case 'high':
     $basic_headers['priority'] = _("Priority");
-    $display_headers['priority'] = '
 ' . $xpriority; + $display_headers['priority'] = '
 ' . _("High"); break; case 'low': $basic_headers['priority'] = _("Priority"); - $display_headers['priority'] = '
 ' . $xpriority; + $display_headers['priority'] = '
 ' . _("Low"); break; } @@ -336,7 +336,8 @@ if ($all_headers) { /* Skip the header if we have already dealt with it. */ if (!isset($display_headers[$head]) && !isset($all_list_headers[$head]) && - (($head != 'x-priority') || !isset($display_headers['priority']))) { + (!in_array($head, array('importance', 'x-priority')) || + !isset($display_headers['priority']))) { $full_headers[$head] = $val; } } diff --git a/imp/templates/compose/compose.html b/imp/templates/compose/compose.html index cc0bc028c..0a957361b 100644 --- a/imp/templates/compose/compose.html +++ b/imp/templates/compose/compose.html @@ -113,7 +113,7 @@   -