Simplify and improve priority header generation/display
authorMichael M Slusarz <slusarz@curecanti.org>
Fri, 4 Dec 2009 19:48:26 +0000 (12:48 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Fri, 4 Dec 2009 19:49:59 +0000 (12:49 -0700)
16 files changed:
imp/compose.php
imp/config/prefs.php.dist
imp/docs/CHANGES
imp/docs/RFCS
imp/lib/Compose.php
imp/lib/Imap/Flags.php
imp/lib/Mailbox.php
imp/lib/Ui/Headers.php [new file with mode: 0644]
imp/lib/Ui/Message.php
imp/lib/Views/ListMessages.php
imp/lib/Views/ShowMessage.php
imp/mailbox-mimp.php
imp/mailbox.php
imp/message-mimp.php
imp/message.php
imp/templates/compose/compose.html

index 61bfba6..fa9ee82 100644 (file)
@@ -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) {
index 42a1f8e..99ee9f4 100644 (file)
@@ -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(
index f4957a4..73a1676 100644 (file)
@@ -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
index 69328f7..9c030a3 100644 (file)
@@ -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
index b9b40f5..8db4bc8 100644 (file)
@@ -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.
      * </pre>
@@ -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'));
index c8c4db2..21e3fd7 100644 (file)
@@ -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.
      * </pre>
      *
      * @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;
index 6e6773b..a104359 100644 (file)
@@ -158,7 +158,7 @@ class IMP_Mailbox
      * @param array $options  Additional options:
      * <pre>
      * '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 (file)
index 0000000..1321720
--- /dev/null
@@ -0,0 +1,42 @@
+<?php
+/**
+ * The IMP_Ui_Headers:: class is designed to provide a place to store common
+ * code shared among IMP's various UI views for header information.
+ *
+ * Copyright 2009 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (GPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
+ *
+ * @author  Michael Slusarz <slusarz@horde.org>
+ * @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';
+    }
+
+}
index df70048..7e73251 100644 (file)
@@ -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.
index 58c176c..f0ef826 100644 (file)
@@ -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)) {
index d397029..3c8cdae 100644 (file)
@@ -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.
index d769827..7ba5d05 100644 (file)
@@ -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) {
index 7df04dd..7a0145a 100644 (file)
@@ -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();
index 7f72f6a..7cf7efb 100644 (file)
@@ -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;
 }
 
index a1bd913..ec6560d 100644 (file)
@@ -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'] = '<div class="msgflags flagHighpriority" title="' . htmlspecialchars(_("High Priority")) . '"></div>&nbsp;' . $xpriority;
+    $display_headers['priority'] = '<div class="msgflags flagHighpriority" title="' . htmlspecialchars(_("High Priority")) . '"></div>&nbsp;' . _("High");
     break;
 
 case 'low':
     $basic_headers['priority'] = _("Priority");
-    $display_headers['priority'] = '<div class="msgflags flagLowpriority" title="' . htmlspecialchars(_("Low Priority")) . '"></div>&nbsp;' . $xpriority;
+    $display_headers['priority'] = '<div class="msgflags flagLowpriority" title="' . htmlspecialchars(_("Low Priority")) . '"></div>&nbsp;' . _("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;
         }
     }
index cc0bc02..0a95736 100644 (file)
    <strong><tag:priority_label />&nbsp;</strong>
   </td>
   <td class="item">
-   <select id="priority" name="x_priority" tabindex="<tag:priority_tabindex />">
+   <select id="priority" name="priority" tabindex="<tag:priority_tabindex />">
 <loop:pri_opt>
     <option value="<tag:pri_opt.val />" <if:pri_opt.selected>selected="selected" </if:pri_opt.selected>><tag:pri_opt.label /></option>
 </loop:pri_opt>