Bug 1468492 - Part 1. Port Bug 873872 [Feed messages with image attachments and Display Inline set should show the remote image] to SeaMonkey. r=IanN a=IanN
authorFrank-Rainer Grahl <frgrahl@gmx.net>
Mon, 02 Jul 2018 17:40:42 +0200
changeset 28253 251973ed8f779f930137a4b7195471e8a70db53c
parent 28252 741187f6a790554ccbd7af6d9d1baa31572de357
child 28254 6dbea26cd8da41b13204abc6fb92f8436f956959
push id2091
push userfrgrahl@gmx.net
push dateMon, 02 Jul 2018 15:41:42 +0000
treeherdercomm-esr52@cd762a183d3b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersIanN, IanN
bugs1468492, 873872, 736881
Bug 1468492 - Part 1. Port Bug 873872 [Feed messages with image attachments and Display Inline set should show the remote image] to SeaMonkey. r=IanN a=IanN Also port relevant part of Bug 736881 [Improve calculation of attached message size].
suite/mailnews/msgHdrViewOverlay.js
--- a/suite/mailnews/msgHdrViewOverlay.js
+++ b/suite/mailnews/msgHdrViewOverlay.js
@@ -1,14 +1,16 @@
 /* -*- Mode: javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
+Components.utils.import("resource://gre/modules/Services.jsm");
+Components.utils.import("resource:///modules/gloda/utils.js");
 
 /* This is where functions related to displaying the headers for a selected message in the
    message pane live. */
 
 ////////////////////////////////////////////////////////////////////////////////////
 // Warning: if you go to modify any of these JS routines please get a code review from
 // scott@scott-macgregor.org. It's critical that the code in here for displaying
 // the message headers for a selected message remain as fast as possible. In particular,
@@ -605,16 +607,45 @@ var messageHeaderSink = {
         {
           this.mSaveHdr = messenger.msgHdrFromURI(messageUrl.uri);
         }
         catch (ex) {}
 
       }
       if (!currentAttachments.length && this.mSaveHdr)
         this.mSaveHdr.markHasAttachments(false);
+
+      let browser = getBrowser();
+      if (currentAttachments.length &&
+          Services.prefs.getBoolPref("mail.inline_attachments") &&
+          this.mSaveHdr && gFolderDisplay.selectedMessageIsFeed &&
+          browser && browser.contentDocument && browser.contentDocument.body) {
+        for (let img of browser.contentDocument.body.getElementsByClassName("moz-attached-image")) {
+          for (let attachment of currentAttachments) {
+            let partID = img.src.split("&part=")[1];
+            partID = partID ? partID.split("&")[0] : null;
+            if (attachment.partID && partID == attachment.partID) {
+              img.src = attachment.url;
+              break;
+            }
+            else {
+              // GlodaUtils.PART_RE fails to extract a partID for urls with
+              // an embedded ?, at least. So, check the filename too. Frontend
+              // feed parsing ensures no duplicate urls in enclosures.
+              let name = decodeURI(img.src.split("&filename=")[1]);
+              name = name ? name.split("&")[0] : null;
+              if (name == attachment.displayName) {
+                img.src = attachment.url;
+                break;
+              }
+            }
+          }
+        }
+      }
+
       OnMsgParsed(url);
     },
 
     onEndMsgHeaders: function(url)
     {
       OnMsgLoaded(url);
     },
 
@@ -1348,16 +1379,19 @@ function createNewAttachmentInfo(content
 {
   this.contentType = contentType;
   this.url = url;
   this.displayName = displayName;
   this.uri = uri;
   this.isExternalAttachment = isExternalAttachment;
   this.attachment = this;
   this.size = size;
+
+  let match = GlodaUtils.PART_RE.exec(url);
+  this.partID = match && match[1];
 }
 
 createNewAttachmentInfo.prototype.saveAttachment = function saveAttachment()
 {
   if (this.isExternalAttachment)
     // TODO: This displays "Save As" instead of "Save Attachment" in the title
     internalSave(this.url, null,
                  this.displayName, null,