From 7c3f2ade3b3d17d1d0da6667ef998dca88ed5f83 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Mon, 20 Dec 2010 18:28:04 -0700 Subject: [PATCH] Request #9457: Add priority information to draft --- imp/compose-dimp.php | 1 + imp/compose-mimp.php | 2 +- imp/compose.php | 14 +++++-- imp/docs/CHANGES | 1 + imp/js/compose-dimp.js | 6 ++- imp/lib/Ajax/Application.php | 6 ++- imp/lib/Compose.php | 93 ++++++++++++++++++++++++++------------------ 7 files changed, 80 insertions(+), 43 deletions(-) diff --git a/imp/compose-dimp.php b/imp/compose-dimp.php index b0c6f3204..9fbd8a117 100644 --- a/imp/compose-dimp.php +++ b/imp/compose-dimp.php @@ -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); } diff --git a/imp/compose-mimp.php b/imp/compose-mimp.php index 0c1ea0034..0a75332b9 100644 --- a/imp/compose-mimp.php +++ b/imp/compose-mimp.php @@ -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'; diff --git a/imp/compose.php b/imp/compose.php index 04eb9d042..7c959ed01 100644 --- a/imp/compose.php +++ b/imp/compose.php @@ -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"), diff --git a/imp/docs/CHANGES b/imp/docs/CHANGES index 3d4ad0d81..171a64313 100644 --- a/imp/docs/CHANGES +++ b/imp/docs/CHANGES @@ -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 diff --git a/imp/js/compose-dimp.js b/imp/js/compose-dimp.js index 51e410715..ce2eb6472 100644 --- a/imp/js/compose-dimp.js +++ b/imp/js/compose-dimp.js @@ -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'); diff --git a/imp/lib/Ajax/Application.php b/imp/lib/Ajax/Application.php index 10e6e7bcc..bf5d722e0 100644 --- a/imp/lib/Ajax/Application.php +++ b/imp/lib/Ajax/Application.php @@ -1957,6 +1957,7 @@ class IMP_Ajax_Application extends Horde_Core_Ajax_Application *
      * 'html' - (integer) In HTML compose mode?
      * 'message' - (string) The message text.
+     * 'priority' - (string) The priority of the message.
      * 
* * @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 { diff --git a/imp/lib/Compose.php b/imp/lib/Compose.php index c6006ee58..2e1467ac9 100644 --- a/imp/lib/Compose.php +++ b/imp/lib/Compose.php @@ -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: + *
+     * html - (boolean) Is this an HTML message?
+     * priority - (string) The message priority ('high', 'normal', 'low').
+     * 
* * @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: + *
+     * html - (boolean) Is this an HTML message?
+     * priority - (string) The message priority ('high', 'normal', 'low').
+     * 
* * @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. * * @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: + *
+     * priority - (string) The message priority ('high', 'normal', 'low').
+     * 
* - * @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; } -- 2.11.0