Add ability to swap between forward options if using auto forward
authorMichael M Slusarz <slusarz@curecanti.org>
Fri, 5 Feb 2010 18:31:41 +0000 (11:31 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Fri, 5 Feb 2010 18:32:05 +0000 (11:32 -0700)
imp/compose-dimp.php
imp/docs/CHANGES
imp/js/compose-dimp.js
imp/js/fullmessage-dimp.js
imp/lib/Ajax/Application.php
imp/lib/Compose.php
imp/lib/Dimp.php
imp/templates/chunks/compose.php
imp/themes/ie6_or_less-dimp.css
imp/themes/ie7-dimp.css
imp/themes/screen-dimp.css

index 6c5fe2c..ae8a325 100644 (file)
@@ -88,19 +88,9 @@ case 'reply_list':
     $msg = $reply_msg['body'];
     $header = $reply_msg['headers'];
     $header['replytype'] = 'reply';
-
     if ($vars->type == 'reply_auto') {
-        switch ($reply_msg['type']) {
-        case 'reply_all':
-            $fillform_opts['reply_auto'] = 'all';
-            break;
-
-        case 'reply_list':
-            $fillform_opts['reply_auto'] = 'list';
-            break;
-        }
+        $fillform_opts['auto'] = $reply_msg['type'];
     }
-
     $vars->type = $reply_msg['type'];
 
     if ($vars->type == 'reply') {
@@ -133,6 +123,9 @@ case 'forward_both':
     if ($fwd_msg['format'] == 'html') {
         $show_editor = true;
     }
+    if ($vars->type == 'forward_auto') {
+        $fillform_opts['auto'] = $fwd_msg['type'];
+    }
     $vars->type = 'forward';
 
     if (!$prefs->isLocked('default_identity') &&
index 386dac6..c8a009b 100644 (file)
@@ -2,6 +2,8 @@
 v5.0-git
 --------
 
+[mms] Add chance to switch between forward options on compose page when using
+      auto-forward (DIMP).
 [mms] Add chance to switch reply type to single recipient on compose page when
       using auto-reply (DIMP).
 [mms] Fix printing multipage HTML messages in Mozilla browsers (Bug #8708).
index bd57eff..497e328 100644 (file)
@@ -306,7 +306,7 @@ var DimpCompose = {
             case 'AddAttachment':
                 this.uploading = false;
                 if (d.success) {
-                    this.addAttach(d.info.number, d.info.name, d.info.type, d.info.size);
+                    this.addAttach(d.atc.num, d.atc.name, d.atc.type, d.atc.size);
                 } else {
                     this.setDisabled(false);
                 }
@@ -459,7 +459,7 @@ var DimpCompose = {
         }
     },
 
-    // opts = focus, noupdate, reply_auto
+    // opts = auto, focus, fwd_list, noupdate
     fillForm: function(msg, header, opts)
     {
         // On IE, this can get loaded before DOM:loaded. Check for an init
@@ -470,15 +470,14 @@ var DimpCompose = {
         }
 
         var bcc_add,
-            identity = this.getIdentity($F('last_identity')),
-            msgval = $('composeMessage');
+            identity = this.getIdentity($F('last_identity'));
         opts = opts || {};
 
         // Set auto-save-drafts now if not already active.
         if (DIMP.conf_compose.auto_save_interval_val &&
             !this.auto_save_interval) {
             this.auto_save_interval = new PeriodicalExecuter(function() {
-                var curr_hash = MD5.hash($('to', 'cc', 'bcc', 'subject').invoke('getValue').join('\0') + (this.editor_on ? this.rte.getData() : $F(msgval)));
+                var curr_hash = MD5.hash($('to', 'cc', 'bcc', 'subject').invoke('getValue').join('\0') + (this.editor_on ? this.rte.getData() : $F('composeMessage')));
                 if (this.last_msg && curr_hash != this.last_msg) {
                     this.uniqueSubmit('AutoSaveDraft');
                 }
@@ -488,12 +487,7 @@ var DimpCompose = {
             this.auto_save_interval.execute();
         }
 
-        if (this.editor_on) {
-            this.rte.setData(msg);
-        } else {
-            msgval.setValue(msg);
-            this.setCursorPosition(msgval);
-        }
+        this.setBodyText(msg, true);
 
         $('to').setValue(header.to);
         this.resizeto.resizeNeeded();
@@ -522,15 +516,25 @@ var DimpCompose = {
         }
         $('subject').setValue(header.subject);
 
+        this.processFwdList(opts.fwd_list);
+
         Field.focus(opts.focus || 'to');
         this.resizeMsgArea();
 
-        switch (opts.reply_auto) {
-        case 'all':
+        switch (opts.auto) {
+        case 'forward_attach':
+            $('noticerow', 'fwdattachnotice').invoke('show');
+            break
+
+        case 'forward_body':
+            $('noticerow', 'fwdbodynotice').invoke('show');
+            break
+
+        case 'reply_all':
             $('noticerow', 'replyallnotice').invoke('show');
             break
 
-        case 'list':
+        case 'reply_list':
             $('noticerow', 'replylistnotice').invoke('show');
             break;
         }
@@ -545,6 +549,28 @@ var DimpCompose = {
         }
     },
 
+    setBodyText: function(msg)
+    {
+        var msgval;
+
+        if (this.editor_on) {
+            this.rte.setData(msg);
+        } else {
+            msgval = $('composeMessage');
+            msgval.setValue(msg);
+            this.setCursorPosition(msgval);
+        }
+    },
+
+    processFwdList: function(f)
+    {
+        if (f && f.size()) {
+            f.each(function(ptr) {
+                this.addAttach(ptr.num, ptr.name, ptr.type, ptr.size);
+            }, this);
+        }
+    },
+
     swapToAddressCallback: function(r)
     {
         if (r.response.header) {
@@ -554,6 +580,21 @@ var DimpCompose = {
         $('to_loading_img').hide();
     },
 
+    forwardAddCallback: function(r)
+    {
+        if (r.response.type) {
+            switch (r.response.type) {
+            case 'forward_attach':
+                this.processFwdList(r.response.opts.fwd_list);
+                break;
+
+            case 'forward_body':
+                this.setBodyText(r.response.body);
+                break;
+            }
+        }
+    },
+
     focusEditor: function()
     {
         try {
@@ -770,6 +811,8 @@ var DimpCompose = {
 
             case 'replyallnotice':
             case 'replylistnotice':
+            case 'fwdattachnotice':
+            case 'fwdbodynotice':
                 elt.fade({
                     afterFinish: function() {
                         elt.up('TR').hide();
@@ -777,8 +820,12 @@ var DimpCompose = {
                     }.bind(this),
                     duration: 0.4
                 });
-                $('to_loading_img').show();
-                DimpCore.doAction('GetReplyData', { headeronly: 1, imp_compose: $F('composeCache'), type: 'reply' }, { callback: this.swapToAddressCallback.bind(this) });
+                if (id.startsWith('reply')) {
+                    $('to_loading_img').show();
+                    DimpCore.doAction('GetReplyData', { headeronly: 1, imp_compose: $F('composeCache'), type: 'reply' }, { callback: this.swapToAddressCallback.bind(this) });
+                } else {
+                    DimpCore.doAction('GetForwardData', { dataonly: 1, imp_compose: $F('composeCache'), type: (id == 'fwdattachnotice' ? 'forward_body' : 'forward_attach') }, { callback: this.forwardAddCallback.bind(this) });
+                }
                 e.stop();
                 return;
             }
index 63b1614..a230f6a 100644 (file)
@@ -54,12 +54,6 @@ var DimpFullmessage = {
 
         DimpCompose.fillForm((i.id[2]) ? ("\n" + i.sig + r.body) : (r.body + "\n" + i.sig), r.header, r.opts);
 
-        if (r.fwd_list && r.fwd_list.length) {
-            r.fwd_list.each(function(ptr) {
-                DimpCompose.addAttach(ptr.number, ptr.name, ptr.type, ptr.size);
-            });
-        }
-
         if (editor_on) {
             DimpCompose.toggleHtmlEditor(true);
         }
index e34ec3b..a4a24eb 100644 (file)
@@ -929,6 +929,8 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base
      *                               _checkUidvalidity(). Additional variables
      *                               used:
      * <pre>
+     * 'dataonly' - (boolean) Only return data information (DEFAULT:
+     *              false).
      * 'imp_compose' - (string) The IMP_Compose cache identifier.
      * 'type' - (string) See IMP_Compose::forwardMessage().
      * 'uid' - (string) Indices of the messages to forward (IMAP sequence
@@ -944,33 +946,40 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base
      * 'header' - (array) The headers of the message.
      * 'identity' - (integer) The identity ID to use for this message.
      * 'imp_compose'- (string) The IMP_Compose cache identifier.
+     * 'opts' - (array) Additional options needed for DimpCompose.fillForm().
+     * 'type' - (string) The input 'type' value.
      * 'ViewPort' - (object) See _viewPortData().
      * </pre>
      */
     public function GetForwardData($vars)
     {
-        $header = array();
-        $msg = $header = null;
-        $indices = $GLOBALS['imp_imap']->ob()->utils->fromSequenceString($vars->uid);
-
-        $i = each($indices);
-
         try {
-            $imp_contents = IMP_Contents::singleton(reset($i['value']) . IMP::IDX_SEP . $i['key']);
             $imp_compose = IMP_Compose::singleton($vars->imp_compose);
+            if (!($imp_contents = $imp_compose->getContentsOb())) {
+                $indices = $GLOBALS['imp_imap']->ob()->utils->fromSequenceString($vars->uid);
+                $i = each($indices);
+                $imp_contents = IMP_Contents::singleton(reset($i['value']) . IMP::IDX_SEP . $i['key']);
+            }
+
             $fwd_msg = $imp_compose->forwardMessage($vars->type, $imp_contents);
-            $header = $fwd_msg['headers'];
-            $header['replytype'] = 'forward';
 
-            $result = new stdClass;
             /* Can't open session read-only since we need to store the message
              * cache id. */
-            $result->imp_compose = $imp_compose->getCacheId();
-            $result->fwd_list = IMP_Dimp::getAttachmentInfo($imp_compose);
+            $result = new stdClass;
+            $result->opts = new stdClass;
+            $result->opts->fwd_list = IMP_Dimp::getAttachmentInfo($imp_compose);
             $result->body = $fwd_msg['body'];
-            $result->header = $header;
-            $result->format = $fwd_msg['format'];
-            $result->identity = $fwd_msg['identity'];
+            $result->type = $vars->type;
+            if (!$vars->dataonly) {
+                $result->format = $fwd_msg['format'];
+                $fwd_msg['headers']['replytype'] = 'forward';
+                $result->header = $fwd_msg['headers'];
+                $result->identity = $fwd_msg['identity'];
+                $result->imp_compose = $imp_compose->getCacheId();
+                if ($vars->type == 'forward_auto') {
+                    $result->opts->auto = $fwd_msg['type'];
+                }
+            }
         } catch (Horde_Exception $e) {
             $GLOBALS['notification']->push($e, 'horde.error');
             $result = $this->_checkUidvalidity($vars);
@@ -1015,27 +1024,21 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base
                 $i = each($indices);
                 $imp_contents = IMP_Contents::singleton(reset($i['value']) . IMP::IDX_SEP . $i['key']);
             }
+
             $reply_msg = $imp_compose->replyMessage($vars->type, $imp_contents);
-            $header = $reply_msg['headers'];
-            $header['replytype'] = 'reply';
+            $reply_msg['headers']['replytype'] = 'reply';
 
+            /* Can't open session read-only since we need to store the message
+             * cache id. */
             $result = new stdClass;
-            $result->header = $header;
+            $result->header = $reply_msg['headers'];
             if (!$vars->headeronly) {
                 $result->body = $reply_msg['body'];
                 $result->format = $reply_msg['format'];
                 $result->identity = $reply_msg['identity'];
                 $result->imp_compose = $imp_compose->getCacheId();
                 if ($vars->type == 'reply_auto') {
-                    switch ($reply_msg['type']) {
-                    case 'reply_all':
-                        $result->opts = array('reply_auto' => 'all');
-                        break;
-
-                    case 'reply_list':
-                        $result->opts = array('reply_auto' => 'list');
-                        break;
-                    }
+                    $result->opts = array('auto' => $reply_msg['type']);
                 }
             }
         } catch (Horde_Exception $e) {
@@ -1397,7 +1400,9 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base
      *
      * @return object  An object with the following entries:
      * <pre>
+     * 'atc' - TODO
      * 'error' - (string) An error message.
+     * 'imp_compose' - TODO
      * 'success' - (integer) 1 on success, 0 on failure.
      * </pre>
      */
@@ -1411,9 +1416,8 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base
 
         if ($_SESSION['imp']['file_upload'] &&
             $imp_compose->addFilesFromUpload('file_')) {
-            $info = IMP_Dimp::getAttachmentInfo($imp_compose);
+            $result->atc = end(IMP_Dimp::getAttachmentInfo($imp_compose));
             $result->success = 1;
-            $result->info = end($info);
             $result->imp_compose = $imp_compose->getCacheId();
         }
 
index e42976b..dfe8809 100644 (file)
@@ -1506,10 +1506,12 @@ class IMP_Compose
      * <pre>
      * 'body'     - The text of the body part
      * 'encoding' - The guessed charset to use for the reply
-     * 'headers'  - The headers of the message to use for the reply
      * 'format'   - The format of the body message
+     * 'headers'  - The headers of the message to use for the reply
      * 'identity' - The identity to use for the reply based on the original
      *              message's addresses.
+     * 'type'     - The forward type used (either 'forward_attach',
+     *              'forward_body', or 'forward_both').
      * </pre>
      */
     public function forwardMessage($type, $contents, $attach = true)
@@ -1589,7 +1591,8 @@ class IMP_Compose
             'encoding' => isset($msg_text) ? $msg_text['encoding'] : Horde_Nls::getCharset(),
             'format' => $format,
             'headers' => $header,
-            'identity' => $this->_getMatchingIdentity($h)
+            'identity' => $this->_getMatchingIdentity($h),
+            'type' => $type
         );
     }
 
index bd79708..0e97556 100644 (file)
@@ -104,7 +104,7 @@ class IMP_Dimp
      *
      * @return array  An array of arrays with the following keys:
      * <pre>
-     * 'number' - The current attachment number
+     * 'num' - The current attachment number
      * 'name' - The HTML encoded attachment name
      * 'type' - The MIME type of the attachment
      * 'size' - The size of the attachment in KB (string)
@@ -119,8 +119,8 @@ class IMP_Dimp
                 $mime = $data['part'];
 
                 $fwd_list[] = array(
-                    'number' => $atc_num,
                     'name' => htmlspecialchars($mime->getName(true)),
+                    'num' => $atc_num,
                     'type' => $mime->getType(),
                     'size' => $mime->getSize()
                 );
index 6fe9dbb..8b85630 100644 (file)
@@ -127,6 +127,8 @@ $compose_disable = !IMP::canCompose();
      <ul class="notices">
       <li id="replyallnotice" style="display:none"><?php echo _("You are currently replying to ALL recipients. Click here to reply to the original sender instead.") ?></li>
       <li id="replylistnotice" style="display:none"><?php echo _("You are currently replying to the mailing list. Click here to reply to the original sender instead.") ?></li>
+      <li id="fwdattachnotice" style="display:none"><?php echo _("Click here to add the original message text to the body.") ?></li>
+      <li id="fwdbodynotice" style="display:none"><?php echo _("Click here to add the original message as an attachment.") ?></li>
      </ul>
     </td>
    </tr>
index 81294c6..c1d0623 100644 (file)
@@ -54,7 +54,7 @@ div.vpRow {
 }
 
 /* Fixes broken inline-block. */
-div.msgStatus div, #msgHeadersContent .subject span, span.iconImg, span.contextImg, span.spellcheckPopdownImg, span.popdownImg, #qsearch_icon, #qsearch_close, #upload_wait {
+div.msgStatus div, #msgHeadersContent .subject span, span.iconImg, span.contextImg, span.spellcheckPopdownImg, span.popdownImg, #qsearch_icon, #qsearch_close, #upload_wait, #noticerow .notices li {
     zoom: 1;
     *display: inline;
 }
index c98fbbe..2ef2a70 100644 (file)
@@ -35,7 +35,7 @@
 }
 
 /* Fixes broken inline-block. */
-div.msgStatus div, #msgHeadersContent .subject span, span.iconImg, span.contextImg, span.spellcheckPopdownImg, span.popdownImg, #qsearch_icon, #qsearch_close, #upload_wait {
+div.msgStatus div, #msgHeadersContent .subject span, span.iconImg, span.contextImg, span.spellcheckPopdownImg, span.popdownImg, #qsearch_icon, #qsearch_close, #upload_wait, #noticerow .notices li {
     zoom: 1;
     *display: inline;
 }
index cfae624..b382541 100644 (file)
@@ -637,6 +637,11 @@ div.dimpActionsCompose, div.dimpActionsMsg {
     padding: 1px;
 }
 
+#noticerow .notices li {
+    display: -moz-inline-stack;
+    display: inline-block;
+}
+
 #composeMessageParent {
     background: #fff url("graphics/backhead_shadow.png") top repeat-x;
     border-left: 1px silver solid;