Dynamically update message information in preview
authorMichael M Slusarz <slusarz@curecanti.org>
Fri, 5 Jun 2009 21:08:43 +0000 (15:08 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Fri, 5 Jun 2009 21:15:28 +0000 (15:15 -0600)
imp/compose-dimp.php
imp/js/src/DimpBase.js
imp/js/src/compose-dimp.js

index a51d764..34c37d0 100644 (file)
@@ -62,14 +62,14 @@ $imp_ui = new IMP_UI_Compose();
 if (count($_POST)) {
     $result = new stdClass;
     $result->action = $action;
-    $result->success = false;
+    $result->success = 0;
 
     /* Update the file attachment information. */
     if ($action == 'add_attachment') {
         if ($_SESSION['imp']['file_upload'] &&
             $imp_compose->addFilesFromUpload('file_')) {
             $info = DIMP::getAttachmentInfo($imp_compose);
-            $result->success = true;
+            $result->success = 1;
             $result->info = end($info);
             $result->imp_compose = $imp_compose->getCacheId();
         }
@@ -98,7 +98,7 @@ if (count($_POST)) {
         /* Save the draft. */
         try {
             $res = $imp_compose->saveDraft($header, Util::getFormData('message', ''), NLS::getCharset(), Util::getFormData('html'));
-            $result->success = true;
+            $result->success = 1;
 
             /* Delete existing draft. */
             _removeAutoSaveDraft(Util::getFormData('draft_index'));
@@ -140,9 +140,11 @@ if (count($_POST)) {
         $message = Util::getFormData('message');
         $html = Util::getFormData('html');
 
-        $result->reply_type = Util::getFormData('reply_type');
-        $result->index = Util::getFormData('index');
-        $result->reply_folder = Util::getFormData('folder');
+        $result->index = intval(Util::getFormData('index'));
+        if ($reply_type = Util::getFormData('reply_type')) {
+            $result->reply_folder = Util::getFormData('folder');
+            $result->reply_type = $reply_type;
+        }
 
         /* Use IMP_Tree to determine whether the sent mail folder was
          * created. */
@@ -150,14 +152,14 @@ if (count($_POST)) {
         $imptree->eltDiffStart();
 
         $options = array(
+            'readreceipt' => Util::getFormData('request_read_receipt'),
+            'reply_index' => $result->index . IMP::IDX_SEP . $result->reply_folder,
+            'reply_type' => $reply_type,
+            'save_attachments' => Util::getFormData('save_attachments_select'),
             'save_sent' => (($prefs->isLocked('save_sent_mail'))
                             ? $identity->getValue('save_sent_mail')
                             : (bool)Util::getFormData('save_sent_mail')),
             'sent_folder' => $identity->getValue('sent_mail_folder'),
-            'save_attachments' => Util::getFormData('save_attachments_select'),
-            'reply_type' => $result->reply_type,
-            'reply_index' => $result->index . IMP::IDX_SEP . $result->reply_folder,
-            'readreceipt' => Util::getFormData('request_read_receipt')
         );
 
         try {
@@ -166,19 +168,28 @@ if (count($_POST)) {
             $notification->push($e->getMessage(), 'horde.error');
             break;
         }
-        $result->success = true;
+        $result->success = 1;
 
         /* Remove any auto-saved drafts. */
         if ($prefs->getValue('auto_save_drafts') ||
             $prefs->getValue('auto_delete_drafts')) {
             _removeAutoSaveDraft(Util::getFormData('draft_index'));
-            $result->draft_delete = true;
+            $result->draft_delete = 1;
         }
 
         if ($sent && $prefs->getValue('compose_confirm')) {
             $notification->push(_("Message sent successfully."), 'horde.success');
         }
 
+        /* Update maillog information. */
+        if (!empty($header['in_reply_to']) &&
+            !empty($GLOBALS['conf']['maillog']['use_maillog'])) {
+            $result->log = array();
+            foreach (IMP_Maillog::parseLog($header['in_reply_to']) as $val) {
+                $result->log[] = htmlspecialchars($val['msg']);
+            }
+        }
+
         $res = DIMP::getFolderResponse($imptree);
         if (!empty($res)) {
             $result->folder = $res['a'][0];
index 45d8a3d..c6b8a2f 100644 (file)
@@ -904,7 +904,7 @@ var DimpBase = {
                 return;
             }
             this.pp = data;
-            pp_uid = data.imapuid + data.view;
+            pp_uid = this._getPPId(data.imapuid, data.view);
 
             if (this.ppfifo.indexOf(pp_uid) != -1) {
                   // There is a chance that the message may have been marked
@@ -952,7 +952,7 @@ var DimpBase = {
         }
 
         // Store in cache.
-        ppuid = r.index + r.folder;
+        ppuid = this._getPPId(r.index, r.folder);
         this._expirePPCache([ ppuid ]);
         this.ppcache[ppuid] = resp;
         this.ppfifo.push(ppuid);
@@ -1006,15 +1006,7 @@ var DimpBase = {
 
         // Add message information
         if (r.log) {
-            $('msgInfo').show();
-            $('infolist_col').show();
-            $('infolist_exp').hide();
-
-            tmp = '';
-            r.log.each(function(entry) {
-                tmp += '<tr><td>' + entry + '</td></tr>';
-            });
-            $('infolist').down('TABLE').update(tmp);
+            this.updateMsgInfo(r.log);
         } else {
             $('msgInfo').hide();
         }
@@ -1032,6 +1024,36 @@ var DimpBase = {
         this._addHistory('msg:' + row.view + ':' + row.imapuid);
     },
 
+    // opts = index, mailbox
+    updateMsgInfo: function(log, opts)
+    {
+        var tmp = '';
+
+        if (!opts ||
+            (this.pp.imapuid == opts.index &&
+             this.pp.view == opts.mailbox)) {
+            $('msgInfo').show();
+
+            if (opts) {
+                $('infolist_col').show();
+                $('infolist_exp').hide();
+            }
+
+            log.each(function(entry) {
+                tmp += '<tr><td>' + entry + '</td></tr>';
+            });
+
+            $('infolist').down('TABLE').update(tmp);
+        }
+
+        if (opts) {
+            tmp = this._getPPId(opts.index, opts.mailbox);
+            if (this.ppcache[tmp]) {
+                this.ppcache[tmp].response.log = log;
+            }
+        }
+    },
+
     initPreviewPane: function()
     {
         var sel = this.viewport.getSelected();
@@ -1072,6 +1094,11 @@ var DimpBase = {
         }
     },
 
+    _getPPId: function(index, mailbox)
+    {
+        return index + '|' + mailbox;
+    },
+
     // Labeling functions
     updateSeenUID: function(r, setflag)
     {
index 4590d47..3433850 100644 (file)
@@ -248,6 +248,10 @@ var DimpCompose = {
                         DIMP.baseWindow.DimpBase.poll();
                     }
 
+                    if (d.log) {
+                        DIMP.baseWindow.DimpBase.updateMsgInfo(d.log, { index: d.index, mailbox: d.reply_folder });
+                    }
+
                     DIMP.baseWindow.DimpCore.showNotifications(r.msgs);
                 }
                 return this.closeCompose();