From 9ad763efa473b2301c7280cc0d6d8ed8eae2fe24 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Tue, 26 Jan 2010 15:53:43 -0700 Subject: [PATCH] Improved forwarding options. Re-add ability to choose between the different kinds of forwarding. However, lock the ability to choose by default - continue to default to forwarding entire message as message/rfc822. --- imp/compose-dimp.php | 9 ++-- imp/compose-mimp.php | 5 +- imp/compose.php | 15 ++++-- imp/config/prefs.php.dist | 64 +++++++++++++++++------ imp/docs/CHANGES | 2 +- imp/docs/UPGRADING | 2 +- imp/js/DimpBase.js | 17 +++++- imp/js/fullmessage-dimp.js | 17 +++++- imp/lib/Ajax/Application.php | 10 ++-- imp/lib/Compose.php | 23 ++++++-- imp/lib/LoginTasks/SystemTask/UpgradeFromImp4.php | 25 +++++++++ imp/lib/Ui/Compose.php | 13 ----- imp/mailbox.php | 4 +- imp/message.php | 8 ++- imp/templates/chunks/message.php | 10 +++- imp/templates/index/index-dimp.inc | 8 +++ imp/templates/message/navbar_actions.html | 10 +++- imp/themes/screen-dimp.css | 2 +- imp/themes/silver/screen-dimp.css | 2 +- 19 files changed, 184 insertions(+), 62 deletions(-) diff --git a/imp/compose-dimp.php b/imp/compose-dimp.php index a25b574f1..3f2bc9597 100644 --- a/imp/compose-dimp.php +++ b/imp/compose-dimp.php @@ -195,7 +195,7 @@ $folder = Horde_Util::getFormData('folder'); $show_editor = false; $title = _("New Message"); -if (in_array($type, array('reply', 'reply_all', 'reply_auto', 'reply_list', 'forward', 'resume'))) { +if (in_array($type, array('reply', 'reply_all', 'reply_auto', 'reply_list', 'forward_attach', 'forward_auto', 'forward_body', 'forward_both', 'resume'))) { if (!$uid || !$folder) { $type = 'new'; } @@ -238,8 +238,11 @@ case 'reply_list': } break; -case 'forward': - $fwd_msg = $imp_ui->getForwardData($imp_compose, $imp_contents, $uid . IMP::IDX_SEP . $folder); +case 'forward_attach': +case 'forward_auto': +case 'forward_body': +case 'forward_both': + $fwd_msg = $imp_compose->forwardMessage($type, $imp_contents); $msg = $fwd_msg['body']; $header = $fwd_msg['headers']; $header['replytype'] = 'forward'; diff --git a/imp/compose-mimp.php b/imp/compose-mimp.php index 2e61e685d..712407f24 100644 --- a/imp/compose-mimp.php +++ b/imp/compose-mimp.php @@ -139,7 +139,7 @@ case 'f': if (!($imp_contents = $imp_ui->getIMPContents($uid, $thismailbox))) { break; } - $fwd_msg = $imp_compose->forwardMessage($imp_contents); + $fwd_msg = $imp_compose->forwardMessage('forward_attach', $imp_contents, false); $header = $fwd_msg['headers']; $notification->push(_("Forwarded message will be automatically added to your outgoing message."), 'horde.message'); @@ -203,10 +203,9 @@ case _("Send"): break; case 'forward': - $fwd_msg = $imp_compose->forwardMessage($imp_contents); + $fwd_msg = $imp_compose->forwardMessage('forward_attach', $imp_contents); $msg = $fwd_msg['body']; $message .= "\n" . $msg; - $imp_compose->attachIMAPMessage(array($uid . IMP::IDX_SEP . $thismailbox), $header); break; } } diff --git a/imp/compose.php b/imp/compose.php index e46376b93..cd4d61c32 100644 --- a/imp/compose.php +++ b/imp/compose.php @@ -80,7 +80,10 @@ if ($actionID) { case 'reply_all': case 'reply_auto': case 'reply_list': - case 'forward': + case 'forward_attach': + case 'forward_auto': + case 'forward_body': + case 'forward_both': case 'redirect_compose': case 'fwd_digest': // These are all safe actions that might be invoked without a token. @@ -304,12 +307,15 @@ case 'reply_list': $encoding = empty($charset) ? $reply_msg['encoding'] : $charset; break; -case 'forward': +case 'forward_attach': +case 'forward_auto': +case 'forward_body': +case 'forward_both': if (!($imp_contents = $imp_ui->getIMPContents($uid, $thismailbox))) { break; } - $fwd_msg = $imp_ui->getForwardData($imp_compose, $imp_contents, $uid . IMP::IDX_SEP . $thismailbox); + $fwd_msg = $imp_compose->forwardMessage($actionID, $imp_contents); $msg = $fwd_msg['body']; $header = $fwd_msg['headers']; $format = $fwd_msg['format']; @@ -486,8 +492,7 @@ case 'fwd_digest': $indices = Horde_Util::getFormData('fwddigest'); if (!empty($indices)) { $msglist = unserialize(urldecode($indices)); - $subject_header = $imp_compose->attachIMAPMessage($msglist); - if ($subject_header !== false) { + if (($subject_header = $imp_compose->attachIMAPMessage($msglist)) !== false) { $header['subject'] = $subject_header; } } diff --git a/imp/config/prefs.php.dist b/imp/config/prefs.php.dist index e293ea74f..bd86b3eb9 100644 --- a/imp/config/prefs.php.dist +++ b/imp/config/prefs.php.dist @@ -79,12 +79,19 @@ if (!empty($GLOBALS['conf']['compose']['allow_receipts'])) { $prefGroups['compose']['members'] = array_merge($prefGroups['compose']['members'], array('disposition_request_read')); } -$prefGroups['reply_forward'] = array( +$prefGroups['reply'] = array( 'column' => _("Message Options"), - 'label' => _("Message Replies/Forwards"), - 'desc' => _("Configure how you reply to or forward mail."), - 'members' => array('reply_quote', 'reply_format', 'forward_bodytext', - 'reply_headers', 'attrib_text') + 'label' => _("Message Replies"), + 'desc' => _("Configure how you reply to mail."), + 'members' => array('reply_quote', 'reply_format', 'reply_headers', + 'attrib_text') +); + +$prefGroups['forward'] = array( + 'column' => _("Message Options"), + 'label' => _("Message Forwards"), + 'desc' => _("Configure how you forward mail."), + 'members' => array('forward_bodytext') ); $prefGroups['drafts'] = array( @@ -713,7 +720,7 @@ $_prefs['disposition_request_read'] = array( // End Message Composition preferences -// Message Replies/Forwards preferences +// Message Replies preferences // Should the original message be included? $_prefs['reply_quote'] = array( @@ -724,22 +731,14 @@ $_prefs['reply_quote'] = array( 'type' => 'checkbox', 'desc' => _("Include original message in a reply?")); -// When replying/forwarding to a message, should we use the same format as the +// When replying to a message, should we use the same format as the // original message? $_prefs['reply_format'] = array( 'value' => 0, 'locked' => false, 'shared' => false, 'type' => 'checkbox', - 'desc' => _("When replying/forwarding to a message, should we use the same format as the original message?")); - -// Should the original message be included? -$_prefs['forward_bodytext'] = array( - 'value' => 0, - 'locked' => false, - 'shared' => false, - 'type' => 'checkbox', - 'desc' => _("Include body text in forward message by default?")); + 'desc' => _("When replying to a message, should we use the same format as the original message?")); // Reply to header summary - leave a brief summary of the header inside // the message. @@ -759,7 +758,38 @@ $_prefs['attrib_text'] = array( 'desc' => _("How to attribute quoted lines in a reply"), 'help' => 'prefs-attrib_text'); -// End Message Replies/Forwards preferences +// End Message Replies preferences + + +// Message Forwards preferences + +// Should the body text of the original message be included? +// If this preference is locked, the user will not be able to select the +// forward method. +$_prefs['forward_default'] = array( + 'value' => 'attach', + // Locked by default + 'locked' => true, + 'shared' => false, + 'type' => 'enum', + 'enum' => array( + 'attach' => _("As attachment"), + 'body' => _("In the body text"), + 'both' => _("As both body text and an attachment") + ), + 'desc' => _("How should messages be forwarded by default?")); + +// When forwarding a message, should we use the same format as the +// original message (for the body text)? +$_prefs['forward_format'] = array( + 'value' => 0, + // Locked by default + 'locked' => true, + 'shared' => false, + 'type' => 'checkbox', + 'desc' => _("When forwarding a message in the body text, should we use the same format as the original message?")); + +// End Message Forwards preferences // Message Drafts preferences diff --git a/imp/docs/CHANGES b/imp/docs/CHANGES index aa5e38450..75986aa56 100644 --- a/imp/docs/CHANGES +++ b/imp/docs/CHANGES @@ -2,6 +2,7 @@ v5.0-git -------- +[mms] Improved forwarding options. [mms] Add support for LIST-STATUS IMAP extension. [mms] Add hook to allow determination of compose attachments MIME type. [mms] Move AJAX processing framework to Horde (Request #4561). @@ -78,7 +79,6 @@ v5.0-git [mms] Implement spellcheck on send in DIMP. [mms] Sanity check - don't do message operations reliant on UID list if UIDVALIDITY of mailbox has changed. -[mms] Simplify forwarding - always attach entire message. [mms] Remember splitbar position on login/refresh (DIMP). [mms] Disable advanced functions if using POP3 driver (caching, on-demand filtering, searching, sorting) because it is too resource intensive. diff --git a/imp/docs/UPGRADING b/imp/docs/UPGRADING index 0ab556f6a..9674353e3 100644 --- a/imp/docs/UPGRADING +++ b/imp/docs/UPGRADING @@ -57,7 +57,7 @@ your ``config/prefs.php`` file and your preferences backend:: 'alternative_display' 'attachment_display' - 'forward_default' + 'forward_bodytext' Hooks diff --git a/imp/js/DimpBase.js b/imp/js/DimpBase.js index a97b7fa2d..e06195541 100644 --- a/imp/js/DimpBase.js +++ b/imp/js/DimpBase.js @@ -789,7 +789,8 @@ var DimpBase = { break; case 'ctx_message_forward': - this.composeMailbox('forward'); + case 'ctx_message_reply': + this.composeMailbox(id == 'ctx_message_forward' ? 'forward_auto' : 'reply_auto'); break; case 'ctx_message_source': @@ -808,6 +809,12 @@ var DimpBase = { this.composeMailbox(id.substring(10)); break; + case 'ctx_forward_attach': + case 'ctx_forward_body': + case 'ctx_forward_both': + this.composeMailbox(id.substring(4)); + break; + case 'oa_preview_hide': DIMP.conf.preview_pref_old = DIMP.conf.preview_pref; this.togglePreviewPane(''); @@ -1985,7 +1992,7 @@ var DimpBase = { case 'button_forward': case 'button_reply': - this.composeMailbox(id == 'button_reply' ? 'reply_auto' : 'forward'); + this.composeMailbox(id == 'button_reply' ? 'reply_auto' : 'forward_auto'); break; case 'button_ham': @@ -2958,6 +2965,9 @@ var DimpBase = { this._addMouseEvents({ id: 'folderopts', type: 'folderopts' }, $('folderopts').down(1)); DM.addSubMenu('ctx_message_reply', 'ctx_reply'); + if ($('ctx_forward')) { + DM.addSubMenu('ctx_message_forward', 'ctx_forward'); + } [ 'ctx_message_', 'oa_', 'ctx_draft_' ].each(function(i) { if ($(i + 'setflag')) { DM.addSubMenu(i + 'setflag', 'ctx_flag'); @@ -2970,6 +2980,9 @@ var DimpBase = { } else { this._addMouseEvents({ id: 'button_reply', type: 'reply' }, $('button_reply')); DM.disable('button_reply_img', true, true); + + this._addMouseEvents({ id: 'button_forward', type: 'forward' }, $('button_forward')); + DM.disable('button_forward_img', true, true); } new Drop('dropbase', this._folderDropConfig); diff --git a/imp/js/fullmessage-dimp.js b/imp/js/fullmessage-dimp.js index f183d1905..23b2acdfb 100644 --- a/imp/js/fullmessage-dimp.js +++ b/imp/js/fullmessage-dimp.js @@ -19,11 +19,15 @@ var DimpFullmessage = { switch (type) { case 'reply': case 'reply_all': + case 'reply_auto': case 'reply_list': func = 'GetReplyData'; break; - case 'forward': + case 'forward_auto': + case 'forward_attach': + case 'forward_body': + case 'forward_both': func = 'GetForwardData'; break; } @@ -85,7 +89,7 @@ var DimpFullmessage = { case 'forward_link': case 'reply_link': - this.quickreply(id == 'reply_link' ? 'reply' : 'forward'); + this.quickreply(id == 'reply_link' ? 'reply_auto' : 'forward_auto'); e.stop(); return; @@ -153,6 +157,12 @@ var DimpFullmessage = { this.quickreply(id.substring(10)); break; + case 'ctx_forward_attach': + case 'ctx_forward_body': + case 'ctx_forward_both': + this.quickreply(id.substring(4)); + break; + default: parentfunc(e); break; @@ -183,6 +193,9 @@ var DimpFullmessage = { tmp = $('reply_link', 'forward_link').compact().invoke('up', 'SPAN').concat([ $('ctx_contacts_new') ]).compact().invoke('remove'); } else { this.addPopdown('reply_link', 'replypopdown'); + if ($('ctx_forwardpopdown')) { + this.addPopdown('forward_link', 'forwardpopdown'); + } } /* Set up address linking. */ diff --git a/imp/lib/Ajax/Application.php b/imp/lib/Ajax/Application.php index 86e65e877..8359b8b91 100644 --- a/imp/lib/Ajax/Application.php +++ b/imp/lib/Ajax/Application.php @@ -884,6 +884,7 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base * used: *
      * 'imp_compose' - (string) The IMP_Compose cache identifier.
+     * 'type' - (string) See IMP_Compose::forwardMessage().
      * 'uid' - (string) Indices of the messages to forward (IMAP sequence
      *         string).
      * 
@@ -907,13 +908,11 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base $indices = $GLOBALS['imp_imap']->ob()->utils->fromSequenceString($vars->uid); $i = each($indices); - $idx_string = reset($i['value']) . IMP::IDX_SEP . $i['key']; try { - $imp_contents = IMP_Contents::singleton($idx_string); + $imp_contents = IMP_Contents::singleton(reset($i['value']) . IMP::IDX_SEP . $i['key']); $imp_compose = IMP_Compose::singleton($vars->imp_compose); - $imp_ui = new IMP_Ui_Compose(); - $fwd_msg = $imp_ui->getForwardData($imp_compose, $imp_contents, $idx_string); + $fwd_msg = $imp_compose->forwardMessage($vars->type, $imp_contents); $header = $fwd_msg['headers']; $header['replytype'] = 'forward'; @@ -962,10 +961,9 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base { $indices = $GLOBALS['imp_imap']->ob()->utils->fromSequenceString($vars->uid); $i = each($indices); - $idx_string = reset($i['value']) . IMP::IDX_SEP . $i['key']; try { - $imp_contents = IMP_Contents::singleton($idx_string); + $imp_contents = IMP_Contents::singleton(reset($i['value']) . IMP::IDX_SEP . $i['key']); $imp_compose = IMP_Compose::singleton($vars->imp_compose); $reply_msg = $imp_compose->replyMessage($vars->type, $imp_contents); $header = $reply_msg['headers']; diff --git a/imp/lib/Compose.php b/imp/lib/Compose.php index 41e25366d..2d95f5e8c 100644 --- a/imp/lib/Compose.php +++ b/imp/lib/Compose.php @@ -1465,7 +1465,11 @@ class IMP_Compose /** * Determine the text and headers for a forwarded message. * + * @param string $type The forward type (forward_attach, + * forward_body, forward_both, + * forward_auto). * @param IMP_Contents $contents An IMP_Contents object. + * @param boolean $attach Attach the forwarded message? * * @return array An array with the following keys: *
@@ -1477,7 +1481,7 @@ class IMP_Compose
      *              message's addresses.
      * 
*/ - public function forwardMessage($contents) + public function forwardMessage($type, $contents, $attach = true) { /* The headers of the message. */ $header = array( @@ -1487,6 +1491,14 @@ class IMP_Compose 'subject' => '' ); + if ($GLOBALS['prefs']->isLocked('forward_default') || + ($type == 'forward_auto')) { + if (!($type = $GLOBALS['prefs']->getValue('forward_default'))) { + $type = 'attach'; + } + $type = 'forward_' . $type; + } + $h = $contents->getHeaderOb(); $format = 'text'; $msg = ''; @@ -1510,7 +1522,7 @@ class IMP_Compose $header['subject'] = 'Fwd:'; } - if ($GLOBALS['prefs']->getValue('forward_bodytext')) { + if (in_array($type, array('forward_body', 'forward_both'))) { $from = Horde_Mime_Address::addrArray2String($h->getOb('from')); $msg_pre = "\n----- " . @@ -1521,7 +1533,7 @@ class IMP_Compose $compose_html = (($_SESSION['imp']['view'] != 'mimp') && $GLOBALS['prefs']->getValue('compose_html')); $msg_text = $this->_getMessageText($contents, array( - 'html' => ($GLOBALS['prefs']->getValue('reply_format') || $compose_html), + 'html' => ($GLOBALS['prefs']->getValue('forward_format') || $compose_html), 'type' => 'forward' )); @@ -1536,6 +1548,11 @@ class IMP_Compose } } + if ($attach && + in_array($type, array('forward_attach', 'forward_both'))) { + $this->attachIMAPMessage(array($contents->getUid() . IMP::IDX_SEP . $contents->getMailbox())); + } + return array( 'body' => $msg, 'encoding' => isset($msg_text) ? $msg_text['encoding'] : Horde_Nls::getCharset(), diff --git a/imp/lib/LoginTasks/SystemTask/UpgradeFromImp4.php b/imp/lib/LoginTasks/SystemTask/UpgradeFromImp4.php index 7c265332f..1bf58a42f 100644 --- a/imp/lib/LoginTasks/SystemTask/UpgradeFromImp4.php +++ b/imp/lib/LoginTasks/SystemTask/UpgradeFromImp4.php @@ -49,6 +49,31 @@ class IMP_LoginTasks_SystemTask_UpgradeFromImp4 extends Horde_LoginTasks_SystemT if ($update) { $GLOBALS['prefs']->setValue('sortpref', serialize($sortpref)); } + + switch ($GLOBALS['prefs']->getValue('forward_default')) { + case 'forward_attachments': + $GLOBALS['prefs']->setValue('forward_default', 'both'); + break; + + case 'forward_all': + $GLOBALS['prefs']->setValue('forward_default', 'attach'); + break; + + case 'forward_body': + $GLOBALS['prefs']->setValue('forward_default', 'body'); + break; + + case 'attach': + case 'body': + case 'both': + // Ignore - already converted. + break; + + default: + $GLOBALS['prefs']->setValue('forward_default', 'attach'); + $GLOBALS['prefs']->setDefault('forward_default', true); + break; + } } /** diff --git a/imp/lib/Ui/Compose.php b/imp/lib/Ui/Compose.php index 8618ba673..bbd3904b3 100644 --- a/imp/lib/Ui/Compose.php +++ b/imp/lib/Ui/Compose.php @@ -111,19 +111,6 @@ class IMP_Ui_Compose /** */ - public function getForwardData(&$imp_compose, &$imp_contents, $index) - { - $fwd_msg = $imp_compose->forwardMessage($imp_contents); - $subject_header = $imp_compose->attachIMAPMessage(array($index), $fwd_msg['headers']); - if ($subject_header !== false) { - $fwd_msg['headers']['subject'] = $subject_header; - } - - return $fwd_msg; - } - - /** - */ public function attachAutoCompleter($fields) { /* Attach autocompleters to the compose form elements. */ diff --git a/imp/mailbox.php b/imp/mailbox.php index e20b8caa1..9aa28773e 100644 --- a/imp/mailbox.php +++ b/imp/mailbox.php @@ -382,7 +382,9 @@ if ($open_compose_window === false) { if (!isset($options)) { $options = array(); } - Horde::addInlineScript(Horde::popupJs(Horde::applicationUrl('compose.php'), array('params' => array_merge(array('popup' => 1), $options, IMP::getComposeArgs()))), 'dom'); + Horde::addInlineScript(array( + Horde::popupJs(Horde::applicationUrl('compose.php'), array('params' => array_merge(array('popup' => 1), $options, IMP::getComposeArgs()))) + ), 'dom'); } if (!empty($newmsgs)) { diff --git a/imp/message.php b/imp/message.php index 2d9d04071..7b5837664 100644 --- a/imp/message.php +++ b/imp/message.php @@ -488,7 +488,13 @@ if (!$disable_compose) { $a_template->set('show_reply_all', Horde::widget(IMP::composeLink(array(), array('actionID' => 'reply_all') + $compose_params), _("To All"), 'widget', '', '', _("To _All"), true)); } - $a_template->set('forward', Horde::widget(IMP::composeLink(array(), array('actionID' => 'forward') + $compose_params), _("Forward"), 'widget', '', '', _("Fo_rward"), true)); + $fwd_locked = $prefs->isLocked('forward_default'); + $a_template->set('forward', Horde::widget(IMP::composeLink(array(), array('actionID' => 'forward_auto') + $compose_params), _("Forward"), 'widget' . ($fwd_locked ? '' : ' hasmenu'), '', '', _("Fo_rward"), true)); + if (!$fwd_locked) { + $a_template->set('forward_attach', Horde::widget(IMP::composeLink(array(), array('actionID' => 'forward_attach') + $compose_params), _("As Attachment"), 'widget', '', '', _("As Attachment"), true)); + $a_template->set('forward_body', Horde::widget(IMP::composeLink(array(), array('actionID' => 'forward_body') + $compose_params), _("In Body Text"), 'widget', '', '', _("In Body Text"), true)); + $a_template->set('forward_both', Horde::widget(IMP::composeLink(array(), array('actionID' => 'forward_both') + $compose_params), _("Attachment and Body Text"), 'widget', '', '', _("Attachment and Body Text"), true)); + } $a_template->set('redirect', Horde::widget(IMP::composeLink(array(), array('actionID' => 'redirect_compose') + $compose_params), _("Redirect"), 'widget', '', '', _("Redirec_t"), true)); } diff --git a/imp/templates/chunks/message.php b/imp/templates/chunks/message.php index 52b63620a..ee543f3e8 100644 --- a/imp/templates/chunks/message.php +++ b/imp/templates/chunks/message.php @@ -14,7 +14,7 @@
'hasmenu', 'icon' => 'Reply', 'id' => 'reply_link', 'title' => _("Reply"))) ?>
-
'Forward', 'id' => 'forward_link', 'title' => _("Forward"))) ?>
+
'hasmenu', 'icon' => 'Forward', 'id' => 'forward_link', 'title' => _("Forward"))) ?>
getValue('spam_folder'), true)))): ?>
'Spam', 'id' => 'button_spam', 'title' => _("Spam"))) ?>
@@ -129,6 +129,14 @@
+ +isLocked('forward_default')): ?> + + +isLocked('forward_default')): ?> + + +