From 602d7422df34eb3e7a023d40221f376ac316ca8f Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Mon, 20 Jul 2015 08:38:17 -0400
Subject: [PATCH] Fix bug where some messages in multi-folder search couldn't be printed/downloaded (#1490426)

---
 CHANGELOG                          |    2 +-
 plugins/zipdownload/zipdownload.js |    2 +-
 program/js/app.js                  |   29 ++++++++++++++++++-----------
 3 files changed, 20 insertions(+), 13 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index c496e9a..4a41b8d 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -17,7 +17,7 @@
 - Fix so unrecognized TNEF attachments are displayed on the list of attachments (#1490351)
 - Fix "Importing..." message does not hide on error (#1490422)
 - Fix Compose action in addressbook for results from multiple addressbooks (#1490413)
-- Fix bug where some messages in multi-folder search couldn't be opened (#1490426)
+- Fix bug where some messages in multi-folder search couldn't be viewed/printed/downloaded (#1490426)
 - Fix unintentional messages list page change on page switch in compose addressbook (#1490427)
 - Fix race-condition in saving user preferences and loading plugin config (#1490431)
 - Fix so plain text signature field uses monospace font (#1490435)
diff --git a/plugins/zipdownload/zipdownload.js b/plugins/zipdownload/zipdownload.js
index af9136c..f949508 100644
--- a/plugins/zipdownload/zipdownload.js
+++ b/plugins/zipdownload/zipdownload.js
@@ -54,7 +54,7 @@
     // default .eml download of single message
     if (mode == 'eml') {
         var uid = rcmail.get_single_uid();
-        rcmail.goto_url('viewsource', {_uid: uid, _mbox: rcmail.get_message_mailbox(uid), _save: 1});
+        rcmail.goto_url('viewsource', rcmail.params_from_uid(uid, {_save: 1}));
         return;
     }
 
diff --git a/program/js/app.js b/program/js/app.js
index 5238e58..b5d6ccd 100644
--- a/program/js/app.js
+++ b/program/js/app.js
@@ -762,7 +762,7 @@
 
       case 'open':
         if (uid = this.get_single_uid()) {
-          obj.href = this.url('show', {_mbox: this.get_message_mailbox(uid), _uid: uid});
+          obj.href = this.url('show', this.params_from_uid(uid));
           return true;
         }
         break;
@@ -1188,8 +1188,8 @@
           this.gui_objects.messagepartframe.contentWindow.print();
         }
         else if (uid = this.get_single_uid()) {
-          url = '&_action=print&_uid='+uid+'&_mbox='+urlencode(this.get_message_mailbox(uid))+(this.env.safemode ? '&_safe=1' : '');
-          if (this.open_window(this.env.comm_path + url, true, true)) {
+          url = this.url('print', this.params_from_uid(uid, {_safe: this.env.safemode ? 1 : 0}));
+          if (this.open_window(url, true, true)) {
             if (this.env.action != 'show')
               this.mark_message('read', uid);
           }
@@ -1198,7 +1198,7 @@
 
       case 'viewsource':
         if (uid = this.get_single_uid())
-          this.open_window(this.env.comm_path+'&_action=viewsource&_uid='+uid+'&_mbox='+urlencode(this.env.mailbox), true, true);
+          this.open_window(this.url('viewsource', this.params_from_uid(uid)), true, true);
         break;
 
       case 'download':
@@ -1206,7 +1206,7 @@
           location.href = location.href.replace(/_frame=/, '_download=');
         }
         else if (uid = this.get_single_uid()) {
-          this.goto_url('viewsource', { _uid: uid, _mbox: this.get_message_mailbox(uid), _save: 1 });
+          this.goto_url('viewsource', this.params_from_uid(uid, {_save: 1}));
         }
         break;
 
@@ -2233,12 +2233,7 @@
       return;
 
     var win, target = window,
-      url = {
-        _uid: String(id).split('-')[0],
-        _mbox: this.get_message_mailbox(id),
-        // add browser capabilities, so we can properly handle attachments
-        _caps: this.browser_capabilities()
-      };
+      url = this.params_from_uid(id, {_caps: this.browser_capabilities()});
 
     if (preview && (win = this.get_frame_window(this.env.contentframe))) {
       target = win;
@@ -8137,6 +8132,18 @@
     return msg.mbox || this.env.mailbox;
   };
 
+  // build request parameters from single message id (maybe with mailbox name)
+  this.params_from_uid = function(uid, params)
+  {
+    if (!params)
+      params = {};
+
+    params._uid = String(uid).split('-')[0];
+    params._mbox = this.get_message_mailbox(uid);
+
+    return params;
+  };
+
   // gets cursor position
   this.get_caret_pos = function(obj)
   {

--
Gitblit v1.9.1