From: Michael M Slusarz Date: Fri, 24 Sep 2010 23:11:57 +0000 (-0600) Subject: Request #9132: Multiple forwards in single message (DIMP) X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=e0da9f53f2af6c5b6c30ffca75b4b9939655d138;p=horde.git Request #9132: Multiple forwards in single message (DIMP) --- diff --git a/imp/compose-dimp.php b/imp/compose-dimp.php index 475502557..6ddcea897 100644 --- a/imp/compose-dimp.php +++ b/imp/compose-dimp.php @@ -15,6 +15,7 @@ * 'type' - TODO * 'to' - TODO * 'uid' - TODO + * 'uids' - TODO * * * Copyright 2005-2010 The Horde Project (http://www.horde.org/) @@ -60,35 +61,26 @@ if (!$prefs->isLocked('default_identity') && isset($vars->identity)) { $identity->setDefault($vars->identity); } -/* Initialize the IMP_Compose:: object. */ +/* Init objects. */ $imp_compose = $injector->getInstance('IMP_Compose')->getOb(); - -/* Init IMP_Ui_Compose:: object. */ $imp_ui = new IMP_Ui_Compose(); $show_editor = false; $title = _("New Message"); -if (in_array($vars->type, array('reply', 'reply_all', 'reply_auto', 'reply_list', 'forward_attach', 'forward_auto', 'forward_body', 'forward_both', 'forward_redirect', 'resume'))) { - if (!$vars->uid || !$vars->folder) { - $vars->type = 'new'; - } - - try { - $imp_contents = $injector->getInstance('IMP_Contents')->getOb(new IMP_Indices($vars->folder, $vars->uid)); - } catch (Horde_Exception $e) { - $notification->push(_("Requested message not found."), 'horde.error'); - $vars->uid = $vars->folder = null; - $vars->type = 'new'; - } -} - switch ($vars->type) { case 'reply': case 'reply_all': case 'reply_auto': case 'reply_list': - $reply_msg = $imp_compose->replyMessage($vars->type, $imp_contents, $header['to']); + try { + $contents = $imp_ui->getContents($vars); + } catch (IMP_Compose_Exception $e) { + $notification->push($e, 'horde.error'); + break; + } + + $reply_msg = $imp_compose->replyMessage($vars->type, reset($contents), $header['to']); $msg = $reply_msg['body']; $header = $reply_msg['headers']; $header['replytype'] = 'reply'; @@ -119,30 +111,64 @@ case 'forward_attach': case 'forward_auto': case 'forward_body': case 'forward_both': - $fwd_msg = $imp_compose->forwardMessage($vars->type, $imp_contents); - $msg = $fwd_msg['body']; - $header = $fwd_msg['headers']; - $header['replytype'] = 'forward'; - $title = $header['title']; - if ($fwd_msg['format'] == 'html') { - $show_editor = true; + if ($vars->uids) { + if (!in_array($vars->type, array('forward_attach', 'forward_auto'))) { + $notification->push(_("Multiple messages can only be forwarded as attachments."), 'horde.warning'); + } + + try { + $header = array( + 'replytype' => 'forward', + 'subject' => $imp_compose->attachImapMessage(new IMP_Indices($vars->uids)) + ); + } catch (IMP_Compose_Exception $e) { + $notification->push($e, 'horde.error'); + break; + } + + $rte = $show_editor = ($prefs->getValue('compose_html') && $_SESSION['imp']['rteavail']); + } else { + if (!($contents = $imp_ui->getContents($vars))) { + break; } - if ($vars->type == 'forward_auto') { - $fillform_opts['auto'] = $fwd_msg['type']; + try { + $contents = $imp_ui->getContents($vars); + } catch (IMP_Compose_Exception $e) { + $notification->push($e, 'horde.error'); + break; } - $vars->type = 'forward'; - if (!$prefs->isLocked('default_identity') && - !is_null($fwd_msg['identity'])) { - $identity->setDefault($fwd_msg['identity']); + $fwd_msg = $imp_compose->forwardMessage($vars->type, $contents); + $msg = $fwd_msg['body']; + $header = $fwd_msg['headers']; + $header['replytype'] = 'forward'; + $title = $header['title']; + if ($fwd_msg['format'] == 'html') { + $show_editor = true; + } + if ($vars->type == 'forward_auto') { + $fillform_opts['auto'] = $fwd_msg['type']; + } + + if (!$prefs->isLocked('default_identity') && + !is_null($fwd_msg['identity'])) { + $identity->setDefault($fwd_msg['identity']); + } } + + $vars->type = 'forward'; break; case 'forward_redirect': - $imp_compose->redirectMessage($imp_contents); - $get_sig = false; - $title = _("Redirect"); - $vars->type = 'redirect'; + try { + $contents = $imp_ui->getContents($vars); + $imp_compose->redirectMessage(reset($contents)); + $get_sig = false; + $title = _("Redirect"); + $vars->type = 'redirect'; + } catch (IMP_Compose_Exception $e) { + $notification->push($e, 'horde.error'); + } break; case 'resume': @@ -175,7 +201,6 @@ if ($vars->type == 'redirect') { } else { $imp_ui->attachAutoCompleter(array('to', 'cc', 'bcc', 'redirect_to')); $imp_ui->attachSpellChecker(); - $sig = $identity->getSignature($show_editor ? 'html' : 'text'); if ($get_sig && !empty($sig)) { if ($identity->getValue('sig_first')) { diff --git a/imp/compose.php b/imp/compose.php index 328bd84d0..98aa99f3c 100644 --- a/imp/compose.php +++ b/imp/compose.php @@ -211,10 +211,14 @@ if ($_SESSION['imp']['file_upload']) { $title = _("New Message"); switch ($vars->actionID) { case 'mailto': - if (!($imp_contents = $imp_ui->getIMPContents(new IMP_Indices(IMP::$thismailbox, IMP::$uid)))) { + try { + $contents = $imp_ui->getContents(); + } catch (IMP_Compose_Exception $e) { + $notification->push($e, 'horde.error'); break; } - $imp_headers = $imp_contents->getHeaderOb(); + + $imp_headers = $contents->getHeaderOb(); $header['to'] = ''; if ($vars->mailto) { $header['to'] = $imp_headers->getValue('to'); @@ -262,11 +266,14 @@ case 'reply': case 'reply_all': case 'reply_auto': case 'reply_list': - if (!($imp_contents = $imp_ui->getIMPContents(new IMP_Indices(IMP::$thismailbox, IMP::$uid)))) { + try { + $contents = $imp_ui->getContents(); + } catch (IMP_Compose_Exception $e) { + $notification->push($e, 'horde.error'); break; } - $reply_msg = $imp_compose->replyMessage($vars->actionID, $imp_contents, $vars->to); + $reply_msg = $imp_compose->replyMessage($vars->actionID, $contents, $vars->to); $msg = $reply_msg['body']; $header = $reply_msg['headers']; $format = $reply_msg['format']; @@ -298,11 +305,14 @@ case 'forward_attach': case 'forward_auto': case 'forward_body': case 'forward_both': - if (!($imp_contents = $imp_ui->getIMPContents(new IMP_Indices(IMP::$thismailbox, IMP::$uid)))) { + try { + $contents = $imp_ui->getContents(); + } catch (IMP_Compose_Exception $e) { + $notification->push($e, 'horde.error'); break; } - $fwd_msg = $imp_compose->forwardMessage($vars->actionID, $imp_contents); + $fwd_msg = $imp_compose->forwardMessage($vars->actionID, $contents); $msg = $fwd_msg['body']; $header = $fwd_msg['headers']; $format = $fwd_msg['format']; @@ -312,11 +322,13 @@ case 'forward_both': break; case 'redirect_compose': - if (!($imp_contents = $imp_ui->getIMPContents(new IMP_Indices(IMP::$thismailbox, IMP::$uid)))) { - break; + try { + $contents = $imp_ui->getContents(); + $imp_compose->redirectMessage($contents); + $title = _("Redirect"); + } catch (IMP_Compose_Exception $e) { + $notification->push($e, 'horde.error'); } - $imp_compose->redirectMessage($imp_contents); - $title = _("Redirect"); break; case 'redirect_send': @@ -481,9 +493,12 @@ case 'send_message': exit; case 'fwd_digest': - if (isset($vars->fwddigest) && - (($subject_header = $imp_compose->attachIMAPMessage(new IMP_Indices($vars->fwddigest))) !== false)) { - $header['subject'] = $subject_header; + if (isset($vars->fwddigest)) { + try { + $header['subject'] = $imp_compose->attachImapMessage(new IMP_Indices($vars->fwddigest)); + } catch (IMP_Compose_Exception $e) { + $notification->push($e, 'horde.error'); + } } break; diff --git a/imp/docs/CHANGES b/imp/docs/CHANGES index df693d31d..87a8778da 100644 --- a/imp/docs/CHANGES +++ b/imp/docs/CHANGES @@ -2,6 +2,8 @@ v5.0-git -------- +[mms] Allow multiple messages to be forwarded in a single outgoing message + (DIMP) (Request #9132). [mms] Add personal recipient message filter (Request #8659). [mms] Add mailing list message filter (Request #8659). [mms] Add ability to define search criteria to be applied to any mailbox diff --git a/imp/js/dimpbase.js b/imp/js/dimpbase.js index 0fa002707..07336d124 100644 --- a/imp/js/dimpbase.js +++ b/imp/js/dimpbase.js @@ -314,12 +314,9 @@ var DimpBase = { composeMailbox: function(type) { var sel = this.viewport.getSelected(); - if (!sel.size()) { - return; + if (sel.size()) { + DimpCore.compose(type, { uids: sel }); } - sel.get('dataob').each(function(s) { - DimpCore.compose(type, { folder: s.view, uid: s.imapuid }); - }); }, loadMailbox: function(f, opts) @@ -1994,9 +1991,9 @@ var DimpBase = { } if (elt) { - tmp = this.viewport.createSelection('domid', elt.identify()).get('dataob').first(); - if (tmp.draft && this.viewport.getMetaData('drafts')) { - DimpCore.compose('resume', { folder: tmp.view, uid: tmp.imapuid }) + tmp = this.viewport.createSelection('domid', elt.identify()).get('dataob'); + if (tmp.first().draft && this.viewport.getMetaData('drafts')) { + DimpCore.compose('resume', { uids: tmp }); } else { this.msgWindow(tmp); } diff --git a/imp/js/dimpcore.js b/imp/js/dimpcore.js index c16e9d32d..137c91502 100644 --- a/imp/js/dimpcore.js +++ b/imp/js/dimpcore.js @@ -263,12 +263,23 @@ var DimpCore = { compose: function(type, args) { - var url = DIMP.conf.URI_COMPOSE; - args = args || {}; + var params = {}; if (type) { - args.type = type; + params.type = type; + } + + if (type.startsWith('forward') || !args.uids) { + if (type.startsWith('forward')) { + params.uids = this.toRangeString(this.selectionToRange(args.uids)); + } + this.popupWindow(this.addURLParam(DIMP.conf.URI_COMPOSE, params), 'compose' + new Date().getTime()); + } else { + args.uids.get('dataob').each(function(d) { + params.folder = d.view; + params.uid = d.imapuid; + this.popupWindow(this.addURLParam(DIMP.conf.URI_COMPOSE, params), 'compose' + new Date().getTime()); + }, this); } - this.popupWindow(this.addURLParam(url, args), 'compose' + new Date().getTime()); }, popupWindow: function(url, name, onload) diff --git a/imp/lib/Compose.php b/imp/lib/Compose.php index f6602b060..0311294fc 100644 --- a/imp/lib/Compose.php +++ b/imp/lib/Compose.php @@ -1619,7 +1619,10 @@ class IMP_Compose if ($attach && in_array($type, array('forward_attach', 'forward_both'))) { - $this->attachIMAPMessage(new IMP_Indices($contents)); + try { + $this->attachImapMessage(new IMP_Indices($contents)); + } catch (IMP_Exception $e) { + } } if (in_array($type, array('forward_body', 'forward_both'))) { @@ -1788,9 +1791,10 @@ class IMP_Compose * * @param IMP_Indices $indices An indices object. * - * @return mixed String or false. + * @return string Subject string. + * @throws IMP_Exception */ - public function attachIMAPMessage($indices) + public function attachImapMessage($indices) { if (!count($indices)) { return false; @@ -1808,12 +1812,8 @@ class IMP_Compose $part->setName(_("Forwarded Message")); $part->setContents($contents->fullMessageText(array('stream' => true))); - try { - $this->addMIMEPartAttachment($part); - } catch (IMP_Compose_Exception $e) { - $GLOBALS['notification']->push($e); - return false; - } + // Throws IMP_Compose_Exception. + $this->addMIMEPartAttachment($part); } if ($attached == 1) { @@ -1823,9 +1823,9 @@ class IMP_Compose $name = Horde_String::truncate($name, 80); } return 'Fwd: ' . $GLOBALS['injector']->getInstance('IMP_Imap')->getOb()->getUtils()->getBaseSubject($name, array('keepblob' => true)); - } else { - return 'Fwd: ' . sprintf(_("%u Forwarded Messages"), $attached); } + + return 'Fwd: ' . sprintf(_("%u Forwarded Messages"), $attached); } /** diff --git a/imp/lib/Ui/Compose.php b/imp/lib/Ui/Compose.php index d4550158b..5d341087f 100644 --- a/imp/lib/Ui/Compose.php +++ b/imp/lib/Ui/Compose.php @@ -210,21 +210,41 @@ class IMP_Ui_Compose } /** - * Get the IMP_Contents:: object for a Mailbox/UID. + * Create the IMP_Contents objects needed to create a message. * - * @param IMP_Indices $indices An indices object. + * @param Horde_Variables $vars The variables object. * - * @return boolean|IMP_Contents The contents object, or false on error. + * @return IMP_Contents The IMP_Contents object. + * @throws IMP_Exception */ - public function getIMPContents($indices) + public function getContents($vars = null) { - try { - return $GLOBALS['injector']->getInstance('IMP_Contents')->getOb($indices); - } catch (IMP_Exception $e) { - $GLOBALS['notification']->push(_("Could not retrieve the message from the mail server."), 'horde.error'); + $ob = null; + + if (is_null($vars)) { + /* IMP: compose.php */ + $indices = new IMP_Indices(IMP::$thismailbox, IMP::$uid); + } elseif ($vars->folder && $vars->uid) { + /* DIMP: compose-dimp.php */ + $indices = new IMP_Indices($vars->folder, $vars->uid); } - return false; + if (!is_null($ob)) { + try { + $ob = $GLOBALS['injector']->getInstance('IMP_Contents')->getOb($indices); + } catch (Horde_Exception $e) {} + } + + if (is_null($ob)) { + if (!is_null($vars)) { + $vars->folder = $vars->uid = null; + $vars->type = 'new'; + } + + throw new IMP_Exception(_("Could not retrieve message data from the mail server.")); + } + + return $ob; } /**