Request #9132: Multiple forwards in single message (DIMP)
authorMichael M Slusarz <slusarz@curecanti.org>
Fri, 24 Sep 2010 23:11:57 +0000 (17:11 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Fri, 24 Sep 2010 23:11:57 +0000 (17:11 -0600)
imp/compose-dimp.php
imp/compose.php
imp/docs/CHANGES
imp/js/dimpbase.js
imp/js/dimpcore.js
imp/lib/Compose.php
imp/lib/Ui/Compose.php

index 4755025..6ddcea8 100644 (file)
@@ -15,6 +15,7 @@
  * 'type' - TODO
  * 'to' - TODO
  * 'uid' - TODO
+ * 'uids' - TODO
  * </pre>
  *
  * 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')) {
index 328bd84..98aa99f 100644 (file)
@@ -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;
 
index df693d3..87a8778 100644 (file)
@@ -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
index 0fa0027..07336d1 100644 (file)
@@ -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);
             }
index c16e9d3..137c915 100644 (file)
@@ -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)
index f6602b0..0311294 100644 (file)
@@ -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);
     }
 
     /**
index d455015..5d34108 100644 (file)
@@ -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;
     }
 
     /**