Bug 1600500 - Don't include (re)moved messages/folders in back/forward history menu. r=aceman a=jorgk
authorJorg K <jorgk@jorgk.com>
Tue, 03 Dec 2019 09:14:00 +0100
changeset 36035 531d991deaf663bf46d1ce41f086ad38060c97bb
parent 36034 9e072ab2b4f44525784aebe7e7ce2e3b808768fa
child 36036 57955f07b015186d453f6fa1155f9305cd564a22
push id67
push usergeoff@darktrojan.net
push dateFri, 13 Dec 2019 08:03:20 +0000
treeherdercomm-esr68@57955f07b015 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaceman, jorgk
bugs1600500
Bug 1600500 - Don't include (re)moved messages/folders in back/forward history menu. r=aceman a=jorgk
mail/base/content/mailWindowOverlay.js
--- a/mail/base/content/mailWindowOverlay.js
+++ b/mail/base/content/mailWindowOverlay.js
@@ -1482,44 +1482,55 @@ function populateHistoryMenu(menuPopup, 
   var relPos = 0;
   for (
     var i = curPos.value;
     isBackMenu ? i >= 0 : i < historyArray.length;
     i += isBackMenu ? -2 : 2
   ) {
     navDebug("history[" + i + "] = " + historyArray[i] + "\n");
     navDebug("history[" + i + "] = " + historyArray[i + 1] + "\n");
-    folder = MailUtils.getOrCreateFolder(historyArray[i + 1]);
+    folder = MailServices.folderLookup.getFolderForURL(historyArray[i + 1]);
+    if (!folder) {
+      // Where did the folder go?
+      continue;
+    }
     navDebug(
-      "folder URI = " + folder.URI + "pretty name " + folder.prettyName + "\n"
+      "folder URI = " + folder.URI + " pretty name " + folder.prettyName + "\n"
     );
+
     var menuText = "";
+    var msgHdr = messenger.msgHdrFromURI(historyArray[i]);
+    var msgSubject = msgHdr.mime2DecodedSubject;
+    var msgAuthor = msgHdr.mime2DecodedAuthor;
+
+    if (!msgAuthor && !msgSubject) {
+      // Avoid empty entries in the menu. The message was most likely (re)moved.
+      continue;
+    }
 
     // If the message was not being displayed via the current folder, prepend
     //  the folder name.  We do not need to check underlying folders for
     //  virtual folders because 'folder' is the display folder, not the
     //  underlying one.
     if (folder != gFolderDisplay.displayedFolder) {
       menuText = folder.prettyName + " - ";
     }
 
-    var msgHdr = messenger.msgHdrFromURI(historyArray[i]);
-
     var subject = "";
     if (msgHdr.flags & Ci.nsMsgMessageFlags.HasRe) {
       subject = "Re: ";
     }
-    if (msgHdr.mime2DecodedSubject) {
-      subject += msgHdr.mime2DecodedSubject;
+    if (msgSubject) {
+      subject += msgSubject;
     }
     if (subject) {
       menuText += subject + " - ";
     }
 
-    menuText += msgHdr.mime2DecodedAuthor;
+    menuText += msgAuthor;
     newMenuItem = document.createXULElement("menuitem");
     newMenuItem.setAttribute("label", menuText);
     relPos += isBackMenu ? -1 : 1;
     newMenuItem.setAttribute("value", relPos);
     newMenuItem.folder = folder;
     newMenuItem.setAttribute(
       "oncommand",
       "NavigateToUri(event.target); event.stopPropagation();"