From 5d42a9353b3df5e08b7dfc2ac6a92978a89cceca Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Thu, 22 Jan 2015 04:19:51 -0500
Subject: [PATCH] Fix bug where drafts list wasn't refreshed after draft message was sent from another window (#1490238)

---
 CHANGELOG                       |    1 +
 program/steps/mail/compose.inc  |    7 ++++---
 program/steps/mail/sendmail.inc |    2 +-
 program/js/app.js               |   18 +++++++++++++++---
 4 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index d98b4a4..007c293 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -13,6 +13,7 @@
 - Fix javascript error in "IE 8.0/Tablet PC" browser (#1490210)
 - Fix bug where Reply-To address was ignored on reply to messages sent by self (#1490233)
 - Fix bug where empty fieldmap config entries caused empty results of ldap search (#1490229)
+- Fix bug where drafts list wasn't refreshed after draft message was sent from another window (#1490238)
 
 RELEASE 1.1-rc
 --------------
diff --git a/program/js/app.js b/program/js/app.js
index d4169de..5dd9272 100644
--- a/program/js/app.js
+++ b/program/js/app.js
@@ -2484,6 +2484,16 @@
         selection.push(selected[i]);
 
     this.message_list.selection = selection;
+
+    // reset preview frame, if currently previewed message is not selected (has been removed)
+    try {
+      var win = this.get_frame_window(this.env.contentframe),
+        id = win.rcmail.env.uid;
+
+      if (id && $.inArray(id, selection) < 0)
+        this.show_contentframe(false);
+    }
+    catch (e) {};
   };
 
   // expand all threads with unread children
@@ -3971,7 +3981,6 @@
     this.local_storage_remove_item('compose.index');
   };
 
-
   this.change_identity = function(obj, show_sig)
   {
     if (!obj || !obj.options)
@@ -4340,6 +4349,7 @@
       (this.env.search_request && (this.env.search_scope || 'base') != 'base');
   };
 
+  // action executed after mail is sent
   this.sent_successfully = function(type, msg, folders)
   {
     this.display_message(msg, type);
@@ -4348,11 +4358,13 @@
     if (this.env.extwin) {
       this.lock_form(this.gui_objects.messageform);
 
-      var rc = this.opener();
+      var filter = {task: 'mail', action: ''},
+        rc = this.opener(false, filter) || this.opener(true, filter);
+
       if (rc) {
         rc.display_message(msg, type);
         // refresh the folder where sent message was saved or replied message comes from
-        if (folders && rc.env.task == 'mail' && rc.env.action == '' && $.inArray(rc.env.mailbox, folders) >= 0) {
+        if (folders && $.inArray(rc.env.mailbox, folders) >= 0) {
           rc.command('checkmail');
         }
       }
diff --git a/program/steps/mail/compose.inc b/program/steps/mail/compose.inc
index 1731a48..db4efc7 100644
--- a/program/steps/mail/compose.inc
+++ b/program/steps/mail/compose.inc
@@ -53,13 +53,14 @@
     }
 
     $COMPOSE_ID = uniqid(mt_rand());
+    $params     = rcube_utils::request2param(rcube_utils::INPUT_GET, 'task|action', true);
+
     $_SESSION['compose_data_'.$COMPOSE_ID] = array(
         'id'      => $COMPOSE_ID,
-        'param'   => rcube_utils::request2param(rcube_utils::INPUT_GET, 'task|action', true),
-        'mailbox' => $RCMAIL->storage->get_folder(),
+        'param'   => $params,
+        'mailbox' => $params['mbox'] ?: $RCMAIL->storage->get_folder(),
     );
     $COMPOSE =& $_SESSION['compose_data_'.$COMPOSE_ID];
-
     rcmail_process_compose_params($COMPOSE);
 
     // check if folder for saving sent messages exists and is subscribed (#1486802)
diff --git a/program/steps/mail/sendmail.inc b/program/steps/mail/sendmail.inc
index 4ad43e4..76a8188 100644
--- a/program/steps/mail/sendmail.inc
+++ b/program/steps/mail/sendmail.inc
@@ -686,7 +686,7 @@
 else {
     $folders = array();
 
-    if ($COMPOSE['mode'] == 'reply' || $COMPOSE['mode'] == 'forward') {
+    if (in_array($COMPOSE['mode'], array('reply', 'forward', 'draft'))) {
         $folders[] = $COMPOSE['mailbox'];
     }
 

--
Gitblit v1.9.1