Request #9457: Add priority information to draft
authorMichael M Slusarz <slusarz@curecanti.org>
Tue, 21 Dec 2010 01:28:04 +0000 (18:28 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Tue, 21 Dec 2010 02:16:19 +0000 (19:16 -0700)
imp/compose-dimp.php
imp/compose-mimp.php
imp/compose.php
imp/docs/CHANGES
imp/js/compose-dimp.js
imp/lib/Ajax/Application.php
imp/lib/Compose.php

index b0c6f32..9fbd8a1 100644 (file)
@@ -185,6 +185,7 @@ case 'resume':
             $identity->setDefault($result['identity']);
         }
         $header = array_merge($header, $result['header']);
+        $fillform_opts['priority'] = $result['priority'];
     } catch (IMP_Compose_Exception $e) {
         $notification->push($e);
     }
index 0c1ea00..0a75332 100644 (file)
@@ -257,7 +257,7 @@ case _("Send"):
     switch ($vars->a) {
     case _("Save Draft"):
         try {
-            $notification->push($imp_compose->saveDraft($header, $message, false), 'horde.success');
+            $notification->push($imp_compose->saveDraft($header, $message), 'horde.success');
             if ($prefs->getValue('close_draft')) {
                 $imp_compose->destroy('save_draft');
                 require IMP_BASE . '/mailbox-mimp.php';
index 04eb9d0..7c959ed 100644 (file)
@@ -185,6 +185,11 @@ if ($session->get('imp', 'file_upload')) {
     }
 }
 
+/* Get message priority. */
+$priority = isset($vars->priority)
+    ? $vars->priority
+    : 'normal';
+
 /* Run through the action handlers. */
 $title = _("New Message");
 switch ($vars->actionID) {
@@ -235,6 +240,7 @@ case 'draft':
             $identity->setDefault($result['identity']);
             $sent_mail_folder = $identity->getValue('sent_mail_folder');
         }
+        $priority = $result['priority'];
     } catch (IMP_Compose_Exception $e) {
         $notification->push($e);
     }
@@ -368,7 +374,10 @@ case 'send_message':
     if (in_array($vars->actionID, array('auto_save_draft', 'save_draft'))) {
         if (!$readonly_drafts) {
             try {
-                $result = $imp_compose->saveDraft($header, $message, $rtemode);
+                $result = $imp_compose->saveDraft($header, $message, array(
+                    'html' => $rtemode,
+                    'priority' => $priority
+                ));
 
                 /* Closing draft if requested by preferences. */
                 if ($vars->actionID == 'save_draft') {
@@ -417,7 +426,7 @@ case 'send_message':
         'encrypt' => $prefs->isLocked('default_encrypt') ? $prefs->getValue('default_encrypt') : $vars->encrypt_options,
         'html' => $rtemode,
         'identity' => $identity,
-        'priority' => $vars->priority,
+        'priority' => $priority,
         'save_sent' => $save_sent_mail,
         'sent_folder' => $sent_mail_folder,
         'save_attachments' => $vars->save_attachments_select,
@@ -822,7 +831,6 @@ if ($redirect) {
         $t->set('priority_label', Horde::label('priority', _("_Priority")));
         $t->set('priority_tabindex', ++$tabindex);
 
-        $priority = isset($vars->priority) ? $vars->priority : 'normal';
         $priorities = array(
             'high' => _("High"),
             'normal' => _("Normal"),
index 3d4ad0d..171a643 100644 (file)
@@ -2,6 +2,7 @@
 v5.0-git
 --------
 
+[mms] Add priority information to saved draft (Request #9457).
 [mms] Added example in pre_sent hook to do forgotten attachment checking at
       send time (Request #9028).
 [mms] Add subfolder searching (subfolders dynamically determined at time of
index 51e4107..ce2eb64 100644 (file)
@@ -512,7 +512,7 @@ var DimpCompose = {
         }
     },
 
-    // opts = auto, focus, fwd_list, noupdate, show_editor
+    // opts = auto, focus, fwd_list, noupdate, priority, show_editor
     fillForm: function(msg, header, opts)
     {
         if (!document.loaded) {
@@ -548,6 +548,10 @@ var DimpCompose = {
         }
         $('subject').setValue(header.subject);
 
+        if (DIMP.conf_compose.priority && opts.priority) {
+            this.setPopdownLabel('p', opts.priority);
+        }
+
         this.processFwdList(opts.fwd_list);
 
         Field.focus(opts.focus || 'to');
index 10e6e7b..bf5d722 100644 (file)
@@ -1957,6 +1957,7 @@ class IMP_Ajax_Application extends Horde_Core_Ajax_Application
      * <pre>
      * 'html' - (integer) In HTML compose mode?
      * 'message' - (string) The message text.
+     * 'priority' - (string) The priority of the message.
      * </pre>
      *
      * @return object  An object with the following entries:
@@ -1973,7 +1974,10 @@ class IMP_Ajax_Application extends Horde_Core_Ajax_Application
         }
 
         try {
-            $res = $imp_compose->saveDraft($headers, $this->_vars->message, $this->_vars->html);
+            $res = $imp_compose->saveDraft($headers, $this->_vars->message, array(
+                'html' => $this->_vars->html,
+                'priority' => $this->_vars->priority
+            ));
             if ($this->_action == 'autoSaveDraft') {
                 $GLOBALS['notification']->push(_("Draft automatically saved."), 'horde.message');
             } else {
index c6006ee..2e1467a 100644 (file)
@@ -151,40 +151,48 @@ class IMP_Compose implements ArrayAccess, Countable, Iterator
     /**
      * Saves a message to the draft folder.
      *
-     * @param array $header    List of message headers (UTF-8).
-     * @param mixed $message   Either the message text (string) or a
-     *                         Horde_Mime_Part object that contains the
-     *                         text to send.
-     * @param boolean $html    Whether this is an HTML message.
+     * @param array $header   List of message headers (UTF-8).
+     * @param mixed $message  Either the message text (string) or a
+     *                        Horde_Mime_Part object that contains the text
+     *                        to send.
+     * @param array $opts     An array of options w/the following keys:
+     * <pre>
+     * html - (boolean) Is this an HTML message?
+     * priority - (string) The message priority ('high', 'normal', 'low').
+     * </pre>
      *
      * @return string  Notification text on success.
      * @throws IMP_Compose_Exception
      */
-    public function saveDraft($headers, $message, $html)
+    public function saveDraft($headers, $message, array $opts = array())
     {
-        $body = $this->_saveDraftMsg($headers, $message, $html);
+        $body = $this->_saveDraftMsg($headers, $message, $opts);
         return $this->_saveDraftServer($body);
     }
 
     /**
      * Prepare the draft message.
      *
-     * @param array $headers    List of message headers.
-     * @param mixed $message    Either the message text (string) or a
-     *                          Horde_Mime_Part object that contains the
-     *                          text to send.
-     * @param boolean $html     Whether this is an HTML message.
+     * @param array $headers  List of message headers.
+     * @param mixed $message  Either the message text (string) or a
+     *                        Horde_Mime_Part object that contains the text
+     *                        to send.
+     * @param array $opts     An array of options w/the following keys:
+     * <pre>
+     * html - (boolean) Is this an HTML message?
+     * priority - (string) The message priority ('high', 'normal', 'low').
+     * </pre>
      *
      * @return string  The body text.
      * @throws IMP_Compose_Exception
      */
-    protected function _saveDraftMsg($headers, $message, $html)
+    protected function _saveDraftMsg($headers, $message, $opts)
     {
         $has_session = (bool)$GLOBALS['registry']->getAuth();
 
         /* Set up the base message now. */
         $mime = $this->_createMimeMessage(array(null), $message, array(
-            'html' => $html,
+            'html' => !empty($opts['html']),
             'noattach' => !$has_session,
             'nofinal' => true
         ));
@@ -204,7 +212,7 @@ class IMP_Compose implements ArrayAccess, Countable, Iterator
         }
 
         /* Initalize a header object for the draft. */
-        $draft_headers = $this->_prepareHeaders($headers);
+        $draft_headers = $this->_prepareHeaders($headers, $opts);
 
         /* Add information necessary to log replies/forwards when finally
          * sent. */
@@ -303,6 +311,7 @@ class IMP_Compose implements ArrayAccess, Countable, Iterator
      * 'identity' - (integer) The identity used to create the message.
      * 'mode' - (string) 'html' or 'text'.
      * 'msg' - (string) The message text.
+     * 'priority' - (string) The message priority.
      * </pre>
      * @throws IMP_Compose_Exception
      */
@@ -413,6 +422,9 @@ class IMP_Compose implements ArrayAccess, Countable, Iterator
             } catch (Exception $e) {}
         }
 
+        $imp_ui_hdrs = new IMP_Ui_Headers();
+        $priority = $imp_ui_hdrs->getPriority($headers);
+
         $this->_metadata['draft_uid_resume'] = $indices;
         $this->changed = 'changed';
 
@@ -421,7 +433,8 @@ class IMP_Compose implements ArrayAccess, Countable, Iterator
             'header' => $header,
             'identity' => $identity_id,
             'mode' => $mode,
-            'msg' => $message
+            'msg' => $message,
+            'priority' => $priority
         );
     }
 
@@ -518,7 +531,7 @@ class IMP_Compose implements ArrayAccess, Countable, Iterator
         }
 
         /* Initalize a header object for the outgoing message. */
-        $headers = $this->_prepareHeaders($header);
+        $headers = $this->_prepareHeaders($header, $opts);
 
         /* Add a Received header for the hop from browser to server. */
         $headers->addReceivedHeader(array(
@@ -532,21 +545,6 @@ class IMP_Compose implements ArrayAccess, Countable, Iterator
             $headers->addHeader('Reply-to', $header['replyto']);
         }
 
-        /* Add priority header, if requested. */
-        if (!empty($opts['priority'])) {
-            switch ($opts['priority']) {
-            case 'high':
-                $headers->addHeader('Importance', 'High');
-                $headers->addHeader('X-Priority', '1 (Highest)');
-                break;
-
-            case 'low':
-                $headers->addHeader('Importance', 'Low');
-                $headers->addHeader('X-Priority', '5 (Lowest)');
-                break;
-            }
-        }
-
         /* Add Return Receipt Headers. */
         $mdn = null;
         if (!empty($opts['readreceipt']) &&
@@ -692,12 +690,15 @@ class IMP_Compose implements ArrayAccess, Countable, Iterator
      *
      * @param array $headers  Array with 'from', 'to', 'cc', 'bcc', and
      *                        'subject' values.
+     * @param array $opts     An array of options w/the following keys:
+     * <pre>
+     * priority - (string) The message priority ('high', 'normal', 'low').
+     * </pre>
      *
-     * @return Horde_Mime_Headers  Headers object with the Date, From, To, Cc,
-     *                             Bcc, Subject, Message-ID, References, and
-     *                             In-Reply-To headers set.
+     * @return Horde_Mime_Headers  Headers object with the appropriate headers
+     *                             set.
      */
-    protected function _prepareHeaders($headers)
+    protected function _prepareHeaders($headers, array $opts = array())
     {
         $ob = new Horde_Mime_Headers();
 
@@ -731,6 +732,21 @@ class IMP_Compose implements ArrayAccess, Countable, Iterator
             }
         }
 
+        /* Add priority header, if requested. */
+        if (!empty($opts['priority'])) {
+            switch ($opts['priority']) {
+            case 'high':
+                $ob->addHeader('Importance', 'High');
+                $ob->addHeader('X-Priority', '1 (Highest)');
+                break;
+
+            case 'low':
+                $ob->addHeader('Importance', 'Low');
+                $ob->addHeader('X-Priority', '5 (Lowest)');
+                break;
+            }
+        }
+
         return $ob;
     }
 
@@ -2655,7 +2671,10 @@ class IMP_Compose implements ArrayAccess, Countable, Iterator
         }
 
         try {
-            $body = $this->_saveDraftMsg($headers, $vars->message, $vars->rtemode);
+            $body = $this->_saveDraftMsg($headers, $vars->message, array(
+                'html' => $vars->rtemode,
+                'priority' => $vars->priority
+            ));
         } catch (IMP_Compose_Exception $e) {
             return;
         }