Bug 1546309 - [de-xbl] Get rid of splitmenu, and rework the appmenu. r=darktrojan,aceman (in parts), rs=jorgk
authorPaul Morris <paul@paulwmorris.com>
Tue, 11 Jun 2019 22:31:51 -0400
changeset 35850 bc8ef4b819df75e637f7f191f53de0c5088520e6
parent 35849 fe4c6acd6880bdd9360662e2742dc96c24035c95
child 35851 c8cac88bbe303a3e81fd15311a18a0eeb459f3d0
push id392
push userclokep@gmail.com
push dateMon, 02 Sep 2019 20:17:19 +0000
reviewersdarktrojan, aceman, jorgk
bugs1546309
Bug 1546309 - [de-xbl] Get rid of splitmenu, and rework the appmenu. r=darktrojan,aceman (in parts), rs=jorgk
calendar/base/content/calendar-chrome-startup.js
calendar/lightning/content/lightning-menus.xul
mail/base/content/mailCore.js
mail/base/content/mailWidgets.xml
mail/base/content/mailWindowOverlay.js
mail/base/content/mainPopupSet.inc.xul
mail/base/content/messageWindow.js
mail/base/content/messageWindow.xul
mail/base/content/messenger.css
mail/base/content/messenger.xul
mail/base/content/msgMail3PaneWindow.js
mail/base/jar.mn
mail/components/customizableui/CustomizableUI.jsm
mail/components/customizableui/CustomizableWidgets.jsm
mail/components/customizableui/PanelMultiView.jsm
mail/components/customizableui/content/jar.mn
mail/components/customizableui/content/panelUI.inc.xul
mail/components/customizableui/content/panelUI.js
mail/components/customizableui/moz.build
mail/components/moz.build
mail/extensions/mailviews/content/msgViewPickerOverlay.js
mail/test/mozmill/composition/test-reply-multipart-charset.js
mail/test/mozmill/content-tabs/test-addons-mgr.js
mail/test/mozmill/folder-display/test-watch-ignore-thread.js
mail/test/mozmill/folder-pane/test-folder-pane-consumers.js
mail/test/mozmill/folder-tree-modes/test-mode-switching.js
mail/test/mozmill/folder-widget/test-message-filters.js
mail/test/mozmill/shared-modules/test-window-helpers.js
mail/themes/linux/customizableui/panelUI.css
mail/themes/linux/jar.mn
mail/themes/linux/mail/primaryToolbar.css
mail/themes/osx/customizableui/panelUI.css
mail/themes/osx/jar.mn
mail/themes/osx/mail/primaryToolbar.css
mail/themes/shared/customizableui/panelUI.css
mail/themes/shared/customizableui/panelUI.inc.css
mail/themes/shared/jar.inc.mn
mail/themes/shared/mail/icons/back-12.svg
mail/themes/windows/customizableui/panelUI.css
mail/themes/windows/jar.mn
mail/themes/windows/mail/primaryToolbar.css
--- a/calendar/base/content/calendar-chrome-startup.js
+++ b/calendar/base/content/calendar-chrome-startup.js
@@ -3,16 +3,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /* import-globals-from ../../lightning/content/messenger-overlay-sidebar.js */
 /* import-globals-from calendar-common-sets.js */
 /* import-globals-from calendar-management.js */
 /* import-globals-from calendar-unifinder-todo.js */
 /* import-globals-from calendar-ui-utils.js */
 /* import-globals-from calendar-views-utils.js */
+/* globals PanelUI */
 
 var { fixIterator } = ChromeUtils.import("resource:///modules/iteratorUtils.jsm");
 var { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
 var { AppConstants } = ChromeUtils.import("resource://gre/modules/AppConstants.jsm");
 
 /* exported commonInitCalendar, commonFinishCalendar */
 
 /**
@@ -32,16 +33,19 @@ async function commonInitCalendar() {
     prepareCalendarToDoUnifinder();
 
     // Make sure we update ourselves if the program stays open over midnight
     scheduleMidnightUpdate(refreshUIBits);
 
     // Set up the command controller from calendar-common-sets.js
     injectCalendarCommandController();
 
+    // Set up appmenus.
+    setUpCalendarAppMenus();
+
     // Set up item and day selection listeners
     getViewDeck().addEventListener("dayselect", observeViewDaySelect);
     getViewDeck().addEventListener("itemselect", calendarController.onSelectionChanged, true);
 
     // Start alarm service
     Cc["@mozilla.org/calendar/alarm-service;1"].getService(Ci.calIAlarmService).startup();
     document.getElementById("calsidebar_splitter").addEventListener("command", onCalendarViewResize);
     window.addEventListener("resize", onCalendarViewResize, true);
@@ -80,16 +84,19 @@ function commonFinishCalendar() {
     unloadCalendarManager();
 
     // clean up the unifinder
     finishCalendarToDoUnifinder();
 
     // Remove the command controller
     removeCalendarCommandController();
 
+    // Tear down calendar appmenus.
+    tearDownCalendarAppMenus();
+
     document.getElementById("calsidebar_splitter").removeEventListener("command", onCalendarViewResize);
     window.removeEventListener("resize", onCalendarViewResize, true);
 
     // Clean up the category colors
     categoryManagement.cleanupCategories();
 
     // Clean up window pref observers
     calendarWindowPrefs.cleanup();
@@ -155,16 +162,43 @@ var calendarWindowPrefs = {
                 let attributeValue = Services.prefs.getBoolPref("calendar.view.useSystemColors", false) && "true";
                 setElementValue(win.document.documentElement, attributeValue, "systemcolors");
             });
         }
     }
 };
 
 /**
+ * Set up calendar appmenus by adding event listeners to the appmenu buttons.
+ * Also used to tear down the appmenus by removing the event listeners.
+ *
+ * @param {boolean} [remove]  Whether to remove event listeners instead of adding them.
+ */
+function setUpCalendarAppMenus(remove) {
+    const addOrRemoveListener = remove ? "removeEventListener" : "addEventListener";
+    [
+        "calendar-appmenu-button",
+        "task-appmenu-button",
+        "calendar-item-appmenu-button"
+    ]
+    .forEach(id => {
+        const button = document.getElementById(id);
+        button[addOrRemoveListener]("mousedown", PanelUI);
+        button[addOrRemoveListener]("keypress", PanelUI);
+    });
+}
+
+/**
+ * Tear down calendar appmenus by removing event listeners from the appmenu button.
+ */
+function tearDownCalendarAppMenus() {
+    setUpCalendarAppMenus(true);
+}
+
+/**
  * Migrate calendar UI. This function is called at each startup and can be used
  * to change UI items that require js code intervention
  */
 function migrateCalendarUI() {
     const UI_VERSION = 3;
     let currentUIVersion = Services.prefs.getIntPref("calendar.ui.version", 0);
     if (currentUIVersion >= UI_VERSION) {
         return;
--- a/calendar/lightning/content/lightning-menus.xul
+++ b/calendar/lightning/content/lightning-menus.xul
@@ -499,20 +499,16 @@
     <menuseparator id="appmenu_afterltnNewTask"
                    insertbefore="appmenu_newFolder"
                    observes="appmenu_newFolder"/>
     <menuitem id="appmenu_ltnNewCalendar" label="&lightning.menupopup.new.calendar.label;"
                command="calendar_new_calendar_command"
                observes="calendar_new_calendar_command"
                insertafter="appmenu_newAccountMenuItem"/>
   </menupopup>
-  <splitmenu id="appmenu_customize">
-    <menupopup id="appmenu_customizeMenu"
-               onpopupshowing="onToolbarsPopupShowingForTabType(event, document.getElementById('appmenu_quickFilterBar'));"/>
-  </splitmenu>
   <menupopup id="appmenu_FilePopup">
     <menu id="appmenu_Open"
           mode="calendar"
           label="&lightning.menupopup.open.label;"
           accesskey="&lightning.menupopup.open.accesskey;"
           insertbefore="appmenu_openMessageFileMenuitem">
       <menupopup id="appmenu_OpenPopup">
         <menuitem id="appmenu_OpenMessageFileMenuitem"
--- a/mail/base/content/mailCore.js
+++ b/mail/base/content/mailCore.js
@@ -287,79 +287,95 @@ function MailToolboxCustomizeDone(aEvent
             child._teardown();
           child.remove();
         }
       }
     }
   }
 }
 
-function onViewToolbarsPopupShowing(aEvent, toolboxIds, aInsertPoint) {
-  if (!Array.isArray(toolboxIds))
+/**
+ * Sets up the menu popup that lets the user hide or display toolbars. For
+ * example, in the appmenu / Preferences view.  Adds toolbar items to the popup
+ * and sets their attributes.
+ *
+ * @param {Event} event                 Event causing the menu popup to appear.
+ * @param {string|string[]} toolboxIds  IDs of toolboxes that contain toolbars.
+ * @param {Element} insertPoint         Where to insert menu items.
+ * @param {string} [elementName]        What kind of menu item element to use.
+ *                                      E.g. "toolbarbutton" for the appmenu.
+ * @param {string} [classes]            Classes to set on menu items.
+ */
+function onViewToolbarsPopupShowing(event, toolboxIds, insertPoint,
+  elementName = "menuitem", classes) {
+  if (!Array.isArray(toolboxIds)) {
     toolboxIds = [toolboxIds];
-
-  let popup = aEvent.target;
-
-  // Empty the menu
-  for (let i = popup.childNodes.length - 1; i >= 0; --i) {
-    let deadItem = popup.childNodes[i];
-
-    // Remove all of the nodes with the iscollapsible
-    // attribute.
-    if (deadItem.hasAttribute("iscollapsible"))
-      deadItem.remove();
   }
 
-  // We'll insert the menuitems before the first item in the list if no insert
-  // point is defined.
-  let firstMenuItem = aInsertPoint || popup.firstChild;
+  const popup = event.target.querySelector(".panel-subview-body") || event.target;
+
+  // Remove all collapsible nodes from the menu.
+  for (let i = popup.childNodes.length - 1; i >= 0; --i) {
+    const deadItem = popup.childNodes[i];
 
-  for (let toolboxId of toolboxIds) {
-    let toolbox = document.getElementById(toolboxId);
+    if (deadItem.hasAttribute("iscollapsible")) {
+      deadItem.remove();
+    }
+  }
+
+  // We insert menuitems before the first child if no insert point is given.
+  const firstMenuItem = insertPoint || popup.firstChild;
 
-    // We'll consider either childnodes that have a toolbarname attribute,
-    // or externalToolbars.
-    let potentialToolbars = Array.from(
-      toolbox.querySelectorAll("[toolbarname]")
-    );
-    for (let externalToolbar of toolbox.externalToolbars) {
-      if (externalToolbar.getAttribute("prependmenuitem"))
-        potentialToolbars.unshift(externalToolbar);
-      else
-        potentialToolbars.push(externalToolbar);
+  for (const toolboxId of toolboxIds) {
+    const toolbox = document.getElementById(toolboxId);
+
+    // We consider child nodes that have a toolbarname attribute,
+    // externalToolbars.
+    const toolbars = Array.from(toolbox.querySelectorAll("[toolbarname]"));
+
+    for (const externalToolbar of toolbox.externalToolbars) {
+      if (externalToolbar.getAttribute("prependmenuitem")) {
+        toolbars.unshift(externalToolbar);
+      } else {
+        toolbars.push(externalToolbar);
+      }
     }
 
-    for (let toolbarElement of potentialToolbars) {
-      // We have to bind to toolbar because Javascript doesn't do fresh
-      // let-bindings per Iteration.
-      let toolbar = toolbarElement;
+    for (const toolbar of toolbars) {
+      const toolbarName = toolbar.getAttribute("toolbarname");
+      if (toolbarName) {
+        const menuItem = document.createXULElement(elementName);
 
-      let toolbarName = toolbar.getAttribute("toolbarname");
-      if (toolbarName) {
-        let menuItem = document.createXULElement("menuitem");
-        let hidingAttribute = toolbar.getAttribute("type") == "menubar" ?
-                              "autohide" : "collapsed";
+        const hidingAttribute = toolbar.getAttribute("type") == "menubar" ?
+          "autohide" : "collapsed";
+
         menuItem.setAttribute("type", "checkbox");
         // Mark this menuitem with an iscollapsible attribute, so we
         // know we can wipe it out later on.
         menuItem.setAttribute("iscollapsible", true);
         menuItem.setAttribute("toolbarid", toolbar.id);
         menuItem.setAttribute("label", toolbarName);
         menuItem.setAttribute("accesskey", toolbar.getAttribute("accesskey"));
         menuItem.setAttribute("checked",
                               toolbar.getAttribute(hidingAttribute) != "true");
+        if (classes) {
+          menuItem.setAttribute("class", classes);
+        }
         popup.insertBefore(menuItem, firstMenuItem);
 
-        let onMenuItemCommand = function(aEvent) {
-          let hidden = aEvent.originalTarget.getAttribute("checked") != "true";
-          toolbar.setAttribute(hidingAttribute, hidden);
+        menuItem.addEventListener("command", () => {
+          const hidden = toolbar.getAttribute(hidingAttribute) != "true";
+
+          if (hidden) {
+            toolbar.setAttribute(hidingAttribute, "true");
+          } else {
+            toolbar.removeAttribute(hidingAttribute);
+          }
           Services.xulStore.persist(toolbar, hidingAttribute);
-        };
-
-        menuItem.addEventListener("command", onMenuItemCommand);
+        });
       }
     }
   }
 }
 
 function toJavaScriptConsole() {
   HUDService.openBrowserConsoleOrFocus();
 }
deleted file mode 100644
--- a/mail/base/content/mailWidgets.xml
+++ /dev/null
@@ -1,134 +0,0 @@
-<?xml version="1.0"?>
-<!-- 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/. -->
-
-<!-- import-globals-from ../../../mailnews/base/content/dateFormat.js -->
-<!-- import-globals-from mailWindow.js -->
-<!-- import-globals-from SearchDialog.js -->
-
-<!DOCTYPE bindings [
-<!ENTITY % msgHdrViewOverlayDTD SYSTEM "chrome://messenger/locale/msgHdrViewOverlay.dtd" >
-%msgHdrViewOverlayDTD;
-<!ENTITY % messengerDTD SYSTEM "chrome://messenger/locale/messenger.dtd" >
-%messengerDTD;
-]>
-
-<bindings id="mailBindings"
-          xmlns="http://www.mozilla.org/xbl"
-          xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
-          xmlns:xbl="http://www.mozilla.org/xbl">
-
-  <binding id="splitmenu">
-    <content>
-      <xul:hbox anonid="menuitem" flex="1"
-                class="splitmenu-menuitem"
-                xbl:inherits="iconic,label,disabled,onclick=oncommand,_moz-menuactive=active"/>
-      <xul:menu anonid="menu" class="splitmenu-menu"
-                xbl:inherits="disabled,_moz-menuactive=active"
-                oncommand="event.stopPropagation();">
-        <children includes="menupopup"/>
-      </xul:menu>
-    </content>
-
-    <implementation>
-      <constructor><![CDATA[
-        this._parentMenupopup.addEventListener("DOMMenuItemActive", this);
-        this._parentMenupopup.addEventListener("popuphidden", this);
-      ]]></constructor>
-
-      <destructor><![CDATA[
-        this._parentMenupopup.removeEventListener("DOMMenuItemActive", this);
-        this._parentMenupopup.removeEventListener("popuphidden", this);
-      ]]></destructor>
-
-      <field name="menuitem" readonly="true">
-        document.getAnonymousElementByAttribute(this, "anonid", "menuitem");
-      </field>
-      <field name="menu" readonly="true">
-        document.getAnonymousElementByAttribute(this, "anonid", "menu");
-      </field>
-
-      <field name="_menuDelay">600</field>
-
-      <field name="_parentMenupopup"><![CDATA[
-        this._getParentMenupopup(this);
-      ]]></field>
-
-      <method name="_getParentMenupopup">
-        <parameter name="aNode"/>
-        <body><![CDATA[
-          let node = aNode.parentNode;
-          while (node) {
-            if (node.localName == "menupopup")
-              break;
-            node = node.parentNode;
-          }
-          return node;
-        ]]></body>
-      </method>
-
-      <method name="handleEvent">
-        <parameter name="event"/>
-        <body><![CDATA[
-          switch (event.type) {
-            case "DOMMenuItemActive":
-              if (this.getAttribute("active") == "true" &&
-                  event.target != this &&
-                  this._getParentMenupopup(event.target) == this._parentMenupopup)
-                this.removeAttribute("active");
-              break;
-            case "popuphidden":
-              if (event.target == this._parentMenupopup)
-                this.removeAttribute("active");
-              break;
-          }
-        ]]></body>
-      </method>
-    </implementation>
-
-    <handlers>
-      <handler event="mouseover"><![CDATA[
-        if (this.getAttribute("active") != "true") {
-          this.setAttribute("active", "true");
-
-          this.dispatchEvent(new Event("DOMMenuItemActive",
-                                       { bubbles: true, cancelable: false }));
-
-          if (this.getAttribute("disabled") != "true") {
-            let self = this;
-            setTimeout(function() {
-              if (self.getAttribute("active") == "true")
-                self.menu.open = true;
-            }, this._menuDelay);
-          }
-        }
-      ]]></handler>
-
-      <handler event="popupshowing"><![CDATA[
-        if (event.target == this.firstChild &&
-            this._parentMenupopup._currentPopup)
-          this._parentMenupopup._currentPopup.hidePopup();
-      ]]></handler>
-
-      <handler event="click" phase="capturing"><![CDATA[
-        if (this.getAttribute("disabled") == "true") {
-          // Prevent the command from being carried out
-          event.stopPropagation();
-          return;
-        }
-
-        let node = event.originalTarget;
-        while (true) {
-          if (node == this.menuitem)
-            break;
-          if (node == this)
-            return;
-          node = node.parentNode;
-        }
-
-        this._parentMenupopup.hidePopup();
-      ]]></handler>
-    </handlers>
-  </binding>
-</bindings>
--- a/mail/base/content/mailWindowOverlay.js
+++ b/mail/base/content/mailWindowOverlay.js
@@ -66,19 +66,21 @@ var kAllowRemoteContent = 2;
 var gMarkViewedMessageAsReadTimer = null;
 
 // the user preference,
 // if HTML is not allowed. I assume, that the user could have set this to a
 // value > 1 in his prefs.js or user.js, but that the value will not
 // change during runtime other than through the MsgBody*() functions below.
 var gDisallow_classes_no_html = 1;
 
-// Disable the new account menu item if the account preference is locked.
-// The other affected areas are the account central, the account manager
-// dialog, and the account provisioner window.
+/**
+ * Disable the new account menu item if the account preference is locked.
+ * The other affected areas are the account central, the account manager
+ * dialog, and the account provisioner window.
+ */
 function menu_new_init() {
   // If the account provisioner is pref'd off, we shouldn't display the menu
   // item.
   ShowMenuItem("newCreateEmailAccountMenuItem",
                Services.prefs.getBoolPref("mail.provider.enabled"));
 
   // If we don't have a gFolderDisplay, just get out of here and leave the menu
   // as it is.
@@ -157,17 +159,17 @@ function InitEditMessagesMenu() {
   }
 }
 
 function InitAppFolderViewsMenu() {
   goSetMenuValue("cmd_delete", "valueDefault");
   goSetAccessKey("cmd_delete", "valueDefaultAccessKey");
   document.commandDispatcher.updateCommands("create-menu-edit");
 
-  // initialize the favorite Folder checkbox in the appmenu menu
+  // Initialize the favorite Folder checkbox in the appmenu menu.
   let favoriteAppFolderMenu = document.getElementById("appmenu_favoriteFolder");
   if (!favoriteAppFolderMenu.hasAttribute("disabled")) {
     let folders = gFolderTreeView.getSelectedFolders();
     if (folders.length == 1 && !folders[0].isServer) {
       // Adjust the checked state on the menu item.
       favoriteAppFolderMenu.setAttribute("checked",
         folders[0].getFlag(Ci.nsMsgFolderFlags.Favorite));
       favoriteAppFolderMenu.hidden = false;
@@ -288,22 +290,27 @@ function view_init() {
   // Disable the charset item if there's nothing to enable
   document.getElementById("charsetMenu")
           .setAttribute("disabled", !gMessageDisplay.displayedMessage);
   let appmenuCharset = document.getElementById("appmenu_charsetMenu");
   if (appmenuCharset)
     appmenuCharset.setAttribute("disabled", !gMessageDisplay.displayedMessage);
 }
 
-function InitViewLayoutStyleMenu(event) {
+function InitViewLayoutStyleMenu(event, appmenu) {
   // Prevent submenus from unnecessarily triggering onViewToolbarsPopupShowing
   // via bubbling of events.
   event.stopImmediatePropagation();
-  var paneConfig = Services.prefs.getIntPref("mail.pane_config.dynamic");
-  var layoutStyleMenuitem = event.target.childNodes[paneConfig];
+  let paneConfig = Services.prefs.getIntPref("mail.pane_config.dynamic");
+
+  let parent = appmenu
+    ? event.target.querySelector(".panel-subview-body")
+    : event.target;
+
+  let layoutStyleMenuitem = parent.childNodes[paneConfig];
   if (layoutStyleMenuitem)
     layoutStyleMenuitem.setAttribute("checked", "true");
 }
 
 /**
  * Initialize (check) appropriate folder mode under the View | Folder menu.
  */
 function InitViewFolderViewsMenu(event) {
@@ -563,20 +570,22 @@ function InitAppMessageMenu() {
                              Ci.nsMsgFolderFlags.Templates);
 
   // Initialize the Open Message menuitem
   let winType = document.documentElement.getAttribute("windowtype");
   if (winType == "mail:3pane")
     document.getElementById("appmenu_openMessageWindowMenuitem").hidden = isFeed;
 
   // Initialize the Open Feed Message handler menu
+  const openFeedView = document.getElementById("appMenu-messageOpenFeedView")
+    .querySelector(".panel-subview-body");
+
+  openFeedView.childNodes.forEach(node => node.removeAttribute("checked"));
   let index = FeedMessageHandler.onOpenPref;
-  document.getElementById("appmenu_openFeedMessagePopup")
-          .childNodes[index]
-          .setAttribute("checked", true);
+  openFeedView.childNodes[index].setAttribute("checked", true);
 
   let openRssMenu = document.getElementById("appmenu_openFeedMessage");
   openRssMenu.hidden = !isFeed;
   if (winType != "mail:3pane")
     openRssMenu.hidden = true;
 
   // Disable mark menu when we're not in a folder.
   document.getElementById("appmenu_markMenu").disabled = gMessageDisplay.isDummy;
@@ -725,16 +734,24 @@ function InitAppmenuViewBodyMenu() {
   let Sanitized_menuitem = document.getElementById(menuIDs[1]);
   let AsPlaintext_menuitem = document.getElementById(menuIDs[2]);
   let AllBodyParts_menuitem = menuIDs[3] ? document.getElementById(menuIDs[3])
                                          : null;
 
   document.getElementById("appmenu_bodyAllParts").hidden =
     !Services.prefs.getBoolPref("mailnews.display.show_all_body_parts_menu");
 
+  // Clear all checkmarks.
+  AllowHTML_menuitem.removeAttribute("checked");
+  Sanitized_menuitem.removeAttribute("checked");
+  AsPlaintext_menuitem.removeAttribute("checked");
+  if (AllBodyParts_menuitem) {
+    AllBodyParts_menuitem.removeAttribute("checked");
+  }
+
   if (!prefer_plaintext && !html_as && !disallow_classes &&
       AllowHTML_menuitem)
     AllowHTML_menuitem.setAttribute("checked", true);
   else if (!prefer_plaintext && html_as == 3 && disallow_classes > 0 &&
            Sanitized_menuitem)
     Sanitized_menuitem.setAttribute("checked", true);
   else if (prefer_plaintext && html_as == 1 && disallow_classes > 0 &&
            AsPlaintext_menuitem)
@@ -958,89 +975,127 @@ function SetMessageTagLabel(menuitem, in
     menuitem.setAttribute("acceltext", accesskey);
   }
   let label = document.getElementById("bundle_messenger")
                       .getFormattedString("mailnews.tags.format",
                                           [accesskey, name]);
   menuitem.setAttribute("label", label);
 }
 
-function InitMessageTags(menuPopup) {
-  let tagArray = MailServices.tags.getAllTags({});
-  var tagCount = tagArray.length;
-
-  // Remove any existing non-static entries... (clear tags list before rebuilding it)
-  // "5" is the number of menu items (including separators) on the top of the menu
-  // that should not be cleared.
-  for (let i = menuPopup.childNodes.length; i > 5; --i)
-    menuPopup.lastChild.remove();
-
-  // create label and accesskey for the static remove item
-  var tagRemoveLabel = document.getElementById("bundle_messenger")
-                               .getString("mailnews.tags.remove");
-  SetMessageTagLabel(menuPopup.lastChild.previousSibling, 0, tagRemoveLabel);
-
-  // now rebuild the list
-  var msgHdr = gFolderDisplay.selectedMessage;
-  var curKeys = msgHdr.getStringProperty("keywords");
-  if (msgHdr.label)
-    curKeys += " $label" + msgHdr.label;
-
-  for (var i = 0; i < tagCount; ++i) {
-    var taginfo = tagArray[i];
-    let removeKey = (" " + curKeys + " ").includes(" " + taginfo.key + " ");
-    if (taginfo.ordinal.includes("~AUTOTAG") && !removeKey)
-      continue;
-
-    // TODO we want to either remove or "check" the tags that already exist
-    var newMenuItem = document.createXULElement("menuitem");
-    SetMessageTagLabel(newMenuItem, i + 1, taginfo.tag);
-    newMenuItem.setAttribute("value", taginfo.key);
-    newMenuItem.setAttribute("type", "checkbox");
-    newMenuItem.setAttribute("checked", removeKey);
-    newMenuItem.setAttribute("oncommand", "ToggleMessageTagMenu(event.target);");
-    var color = taginfo.color;
-    if (color)
-      newMenuItem.setAttribute("style", "color: " + color + ";");
-    menuPopup.appendChild(newMenuItem);
+/**
+ * Refresh the contents of the tag popup menu/panel.
+ * Used for example for appmenu/Message/Tag panel.
+ *
+ * @param {Element} parent          Parent element that will contain the menu items.
+ * @param {string} [elementName]    Type of menu item, e.g. "menuitem", "toolbarbutton".
+ * @param {string} [classes]        Classes to set on the menu items.
+ */
+function InitMessageTags(parent, elementName = "menuitem", classes) {
+  const tagArray = MailServices.tags.getAllTags({});
+  const elementNameUpperCase = elementName.toUpperCase();
+
+  // Remove any existing non-static items (clear tags list before rebuilding it).
+  // There is a separator element above the dynamically added tag elements, so
+  // remove dynamically added elements below the separator.
+  while (parent.lastChild.tagName.toUpperCase() == elementNameUpperCase) {
+    parent.lastChild.remove();
   }
+
+  // Create label and accesskey for the static "remove all tags" item.
+  const tagRemoveLabel = document.getElementById("bundle_messenger")
+                                 .getString("mailnews.tags.remove");
+  SetMessageTagLabel(parent.lastChild.previousSibling, 0, tagRemoveLabel);
+
+  // Rebuild the list.
+  const msgHdr = gFolderDisplay.selectedMessage;
+  const suffix = msgHdr.label ? (" $label" + msgHdr.label) : "";
+  const curKeys = msgHdr.getStringProperty("keywords") + suffix;
+
+  tagArray.forEach((tagInfo, index) => {
+    const removeKey = (` ${curKeys} `).includes(` ${tagInfo.key} `);
+
+    if (tagInfo.ordinal.includes("~AUTOTAG") && !removeKey) {
+      return;
+    }
+    // TODO We want to either remove or "check" the tags that already exist.
+    let item = document.createXULElement(elementName);
+    SetMessageTagLabel(item, index + 1, tagInfo.tag);
+
+    if (removeKey) {
+      item.setAttribute("checked", "true");
+    }
+    item.setAttribute("value", tagInfo.key);
+    item.setAttribute("type", "checkbox");
+    item.setAttribute("oncommand", "ToggleMessageTagMenu(event.target);");
+
+    if (tagInfo.color) {
+      item.setAttribute("style", `color: ${tagInfo.color};`);
+    }
+    if (classes) {
+      item.setAttribute("class", classes);
+    }
+    parent.appendChild(item);
+  });
 }
 
-function InitRecentlyClosedTabsPopup(menuPopup) {
-  let tabs = document.getElementById("tabmail").recentlyClosedTabs;
-
-  // show Popup only when there are restorable tabs.
-  if (!tabs.length)
+/**
+ * Refresh the contents of the recently closed tags popup menu/panel.
+ * Used for example for appmenu/Go/Recently_Closed_Tabs panel.
+ *
+ * @param {Element} parent          Parent element that will contain the menu items.
+ * @param {string} [elementName]    Type of menu item, e.g. "menuitem", "toolbarbutton".
+ * @param {string} [classes]        Classes to set on the menu items.
+ * @param {string} [separatorName]  Type of separator, e.g. "menuseparator", "toolbarseparator".
+ */
+function InitRecentlyClosedTabsPopup(
+  parent,
+  elementName = "menuitem",
+  classes,
+  separatorName = "menuseparator",
+) {
+  const tabs = document.getElementById("tabmail").recentlyClosedTabs;
+
+  // Show Popup only when there are restorable tabs.
+  if (!tabs.length) {
     return false;
-
-  // Clear the list before rebuilding it.
-  while (menuPopup.hasChildNodes())
-    menuPopup.lastChild.remove();
-
-  // Rebuild the recently closed tab list
-  for (let i = 0; i < tabs.length; i++) {
-    let menuItem = document.createXULElement("menuitem");
-    menuItem.setAttribute("label", tabs[i].title);
-    menuItem.setAttribute("oncommand", `document.getElementById("tabmail").undoCloseTab(${i});`);
-
-    if (i == 0)
-      menuItem.setAttribute("key", "key_undoCloseTab");
-
-    menuPopup.appendChild(menuItem);
+  }
+
+  // Clear the list.
+  while (parent.hasChildNodes()) {
+    parent.lastChild.remove();
   }
 
-  // "Restore All Tabs" with only one entry does not make sense
+  // Insert menu items to rebuild the recently closed tab list.
+  tabs.forEach((tab, index) => {
+    const item = document.createXULElement(elementName);
+    item.setAttribute("label", tab.title);
+    item.setAttribute("oncommand", `document.getElementById("tabmail").undoCloseTab(${index});`);
+    if (classes) {
+      item.setAttribute("class", classes);
+    }
+
+    if (index == 0) {
+      item.setAttribute("key", "key_undoCloseTab");
+    }
+    parent.appendChild(item);
+  });
+
+  // Only show "Restore All Tabs" if there is more than one tab to restore.
   if (tabs.length > 1) {
-    menuPopup.appendChild(document.createXULElement("menuseparator"));
-
-    let menuItem = document.createXULElement("menuitem");
-    menuItem.setAttribute("label", document.getElementById("bundle_messenger")
+    parent.appendChild(document.createXULElement(separatorName));
+
+    const item = document.createXULElement(elementName);
+    item.setAttribute("label", document.getElementById("bundle_messenger")
                                            .getString("restoreAllTabs"));
-    menuItem.setAttribute("oncommand", "goRestoreAllTabs();");
-    menuPopup.appendChild(menuItem);
+    item.setAttribute("oncommand", "goRestoreAllTabs();");
+
+    if (classes) {
+      item.setAttribute("class", classes);
+    }
+    parent.appendChild(item);
   }
 
   return true;
 }
 
 function goRestoreAllTabs() {
   let tabmail = document.getElementById("tabmail");
 
@@ -3176,45 +3231,45 @@ function OpenOrFocusWindow(args, windowT
     desiredWindow.focus();
     if ("refresh" in args && args.refresh)
       desiredWindow.refresh(args);
   } else {
     window.openDialog(chromeURL, "", "chrome,resizable,status,centerscreen,dialog=no", args);
   }
 }
 
-function initAppMenuPopup(aMenuPopup, aEvent) {
+function initAppMenuPopup() {
   file_init();
   view_init();
   InitGoMessagesMenu();
   menu_new_init();
   CommandUpdate_UndoRedo();
   InitAppFolderViewsMenu();
   document.commandDispatcher.updateCommands("create-menu-tasks");
-
-  // If the onpopupshowing event's target is on one of the splitmenu
-  // menuitem popups, stash that popup in aMenuPopup (the menupopup one
-  // level up) so that splitmenu knows which popup to close when it opens
-  // up it's popupmenu.
-  if (aEvent.target.parentNode.parentNode.parentNode.parentNode == aMenuPopup)
-    aMenuPopup._currentPopup = aEvent.target;
 }
 
 /**
- *  Generates menu items for opening preferences dialog/tab for each installed addon.
+ * Generate menu items that open a preferences dialog/tab for an installed addon,
+ * and add them to a menu popup. E.g. in the appmenu or Tools menu > addon prefs.
  *
- *  @option aMenupopup  The menupopup element to populate.
+ * @param {Element} parent        The element (e.g. menupopup) to populate.
+ * @param {string} [elementName]  The kind of menu item elements to create (e.g. "toolbarbutton").
+ * @param {string} [classes]      Classes for menu item elements with no icon.
+ * @param {string} [iconClasses]  Classes for menu item elements with an icon.
  */
-async function initAddonPrefsMenu(aMenupopup) {
+async function initAddonPrefsMenu(parent,
+  elementName = "menuitem",
+  classes,
+  iconClasses = "menuitem-iconic") {
   // Starting at the bottom, clear all menu items until we hit
   // "no add-on prefs", which is the only disabled element. Above this element
   // there may be further items that we want to preserve.
-  let noPrefsElem = aMenupopup.querySelector('[disabled="true"]');
-  while (aMenupopup.lastChild != noPrefsElem) {
-    aMenupopup.lastChild.remove();
+  let noPrefsElem = parent.querySelector('[disabled="true"]');
+  while (parent.lastChild != noPrefsElem) {
+    parent.lastChild.remove();
   }
 
   // Enumerate all enabled addons with URL to XUL document with prefs.
   let addonsFound = [];
   for (let addon of await AddonManager.getAddonsByTypes(["extension"])) {
     if (addon.userDisabled || addon.appDisabled || addon.softDisabled) {
       continue;
     }
@@ -3241,28 +3296,30 @@ async function initAddonPrefsMenu(aMenup
   }
 
   // Populate the menu with addon names and icons.
   // Note: Having the following code in the getAddonsByTypes() async callback
   // above works on Windows and Linux but doesn't work on Mac, see bug 1419145.
   if (addonsFound.length > 0) {
     addonsFound.sort((a, b) => a.addon.name.localeCompare(b.addon.name));
     for (let { addon, optionsURL, optionsOpenInTab } of addonsFound) {
-      let newItem = document.createXULElement("menuitem");
+      let newItem = document.createXULElement(elementName);
       newItem.setAttribute("label", addon.name);
       newItem.setAttribute("value", optionsURL);
       if (optionsOpenInTab) {
         newItem.setAttribute("optionsType", "tab");
       }
       let iconURL = addon.iconURL || addon.icon64URL;
       if (iconURL) {
-        newItem.setAttribute("class", "menuitem-iconic");
+        newItem.setAttribute("class", iconClasses);
         newItem.setAttribute("image", iconURL);
+      } else if (classes) {
+        newItem.setAttribute("class", classes);
       }
-      aMenupopup.appendChild(newItem);
+      parent.appendChild(newItem);
     }
     noPrefsElem.setAttribute("collapsed", "true");
   } else {
     // Only show message that there are no addons with prefs.
     noPrefsElem.setAttribute("collapsed", "false");
   }
 }
 
--- a/mail/base/content/mainPopupSet.inc.xul
+++ b/mail/base/content/mainPopupSet.inc.xul
@@ -1,1193 +1,12 @@
 # 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/.
 
-  <menupopup id="appmenu-popup"
-             onpopupshowing="initAppMenuPopup(this, event);">
-    <hbox>
-      <vbox id="appmenuPrimaryPane">
-        <splitmenu id="appmenu_newMessage"
-                   label="&appmenuNewMsgCmd.label;"
-                   command="cmd_newMessage">
-            <menupopup id="appmenu_newMenupopup">
-              <menuitem id="appmenu_newNewMsgCmd"
-                        label="&newNewMsgCmd.label;"
-                        key="key_newMessage2"
-                        command="cmd_newMessage"/>
-              <menuitem id="appmenu_newFolder"
-                        label="&newFolderCmd.label;"
-                        command="cmd_newFolder"/>
-              <menuitem id="appmenu_newVirtualFolder"
-                        label="&newVirtualFolderCmd.label;"
-                        command="cmd_newVirtualFolder"/>
-              <menuseparator id="appmenu_newAccountPopupMenuSeparator"/>
-              <menuitem id="appmenu_newCreateEmailAccountMenuItem"
-                        label="&newCreateEmailAccountCmd.label;"
-                        oncommand="NewMailAccountProvisioner(msgWindow);"/>
-              <menuitem id="appmenu_newMailAccountMenuItem"
-                        label="&newExistingEmailAccountCmd.label;"
-                        oncommand="NewMailAccount(msgWindow);"/>
-              <menuitem id="appmenu_newIMAccountMenuItem"
-                        label="&newIMAccountCmd.label;"
-                        oncommand="openIMAccountWizard();"/>
-              <menuitem id="appmenu_newFeedAccountMenuItem"
-                        label="&newFeedAccountCmd.label;"
-                        accesskey="&newFeedAccountCmd.accesskey;"
-                        oncommand="AddFeedAccount();"/>
-              <menuitem id="appmenu_newAccountMenuItem"
-                        label="&newOtherAccountsCmd.label;"
-                        oncommand="MsgAccountWizard();"/>
-              <menuseparator id="appmenu_newPopupMenuSeparator"/>
-              <menuitem id="appmenu_newCard"
-                        label="&appmenuNewContactCmd.label;"
-                        command="cmd_newCard"/>
-              <menuitem id="appmenu_newIMContactMenuItem"
-                        label="&newIMContactCmd.label;"
-                        command="cmd_addChatBuddy"/>
-            </menupopup>
-        </splitmenu>
-        <menu id="appmenu_msgAttachmentMenu"
-              label="&openAttachmentListCmd.label;"
-              disabled="true">
-          <menupopup id="appmenu_attachmentMenuList"
-                     onpopupshowing="FillAttachmentListPopup(event, this);">
-            <menuseparator/>
-            <menuitem label="&openAllAttachmentsCmd.label;"
-                      accesskey="&openAllAttachmentsCmd.accesskey;"
-                      command="cmd_openAllAttachments"/>
-            <menuitem label="&saveAllAttachmentsCmd.label;"
-                      accesskey="&saveAllAttachmentsCmd.accesskey;"
-                      command="cmd_saveAllAttachments"/>
-            <menuitem label="&detachAllAttachmentsCmd.label;"
-                      accesskey="&detachAllAttachmentsCmd.accesskey;"
-                      command="cmd_detachAllAttachments"/>
-            <menuitem label="&deleteAllAttachmentsCmd.label;"
-                      accesskey="&deleteAllAttachmentsCmd.accesskey;"
-                      command="cmd_deleteAllAttachments"/>
-          </menupopup>
-        </menu>
-        <menuseparator class="appmenu-menuseparator"/>
-        <hbox>
-          <menuitem id="appmenu-edit-label"
-                    label="&appmenuEditMenu.label;"
-                    disabled="true"/>
-          <toolbarbutton id="appmenu-cut"
-                         class="appmenu-edit-button"
-                         command="cmd_cut"
-                         onclick="if (!this.disabled) hidePopup();"
-                         tooltiptext="&cutCmd.label;"/>
-          <toolbarbutton id="appmenu-copy"
-                         class="appmenu-edit-button"
-                         command="cmd_copy"
-                         onclick="if (!this.disabled) hidePopup();"
-                         tooltiptext="&copyCmd.label;"/>
-          <toolbarbutton id="appmenu-paste"
-                         class="appmenu-edit-button"
-                         command="cmd_paste"
-                         onclick="if (!this.disabled) hidePopup();"
-                         tooltiptext="&pasteCmd.label;"/>
-          <spacer flex="1"/>
-          <menu id="appmenu-editmenu">
-            <menupopup id="appmenu-editmenu-menupopup">
-              <menuitem id="appmenu-editmenu-cut"
-                        class="menuitem-iconic"
-                        label="&cutCmd.label;"
-                        key="key_cut"
-                        command="cmd_cut"/>
-              <menuitem id="appmenu-editmenu-copy"
-                        class="menuitem-iconic"
-                        label="&copyCmd.label;"
-                        key="key_copy"
-                        command="cmd_copy"/>
-              <menuitem id="appmenu-editmenu-paste"
-                        class="menuitem-iconic"
-                        label="&pasteCmd.label;"
-                        key="key_paste"
-                        command="cmd_paste"/>
-              <menuseparator/>
-              <menuitem id="appmenu-editmenu-undo"
-                        label="&undoCmd.label;"
-                        key="key_undo"
-                        command="cmd_undo"/>
-              <menuitem id="appmenu-editmenu-redo"
-                        label="&redoCmd.label;"
-                        key="key_redo"
-                        command="cmd_redo"/>
-              <menuseparator id="appmenu_messageAfterRedoEditSeparator"/>
-              <menuitem id="appmenu_delete"
-                        label="&deleteCmd.label;"
-#ifdef XP_MACOSX
-                        acceltext="⌫"
-#else
-                        key="key_delete"
-#endif
-                        command="cmd_delete"/>
-              <menuseparator id="appmenu_messageAfterDeleteEditSeparator"/>
-              <menuitem id="appmenu-editmenu-selectAll"
-                        label="&selectAllCmd.label;"
-                        key="key_selectAll"
-                        command="cmd_selectAll"/>
-              <menuitem id="appmenu_selectThread"
-                        label="&appmenuSelectThread.label;"
-                        key="key_selectThread"
-                        command="cmd_selectThread"/>
-              <menuitem id="appmenu_selectFlagged"
-                        label="&appmenuSelectFlagged.label;"
-                        command="cmd_selectFlagged"/>
-            </menupopup>
-          </menu>
-        </hbox>
-        <menu id="appmenu_find"
-              label="&findMenu.label;">
-          <menupopup id="appmenu_FindPopup">
-            <menuitem id="appmenu_findCmd"
-                      label="&findCmd.label;"
-                      key="key_find"
-                      command="cmd_find"/>
-            <menuitem id="appmenu_findAgainCmd"
-                      label="&findAgainCmd.label;"
-                      key="key_findAgain"
-                      command="cmd_findAgain"/>
-            <menuseparator id="appMenuAfterFindSeparator"/>
-            <menuitem id="appmenu_searchMailCmd"
-                      label="&searchMailCmd.label;"
-                      key="key_searchMail"
-                      command="cmd_search"/>
-            <menuitem id="appmenu_searchAddressesCmd"
-                      label="&searchAddressesCmd.label;"
-                      oncommand="MsgSearchAddresses()"/>
-          </menupopup>
-        </menu>
-        <splitmenu id="appmenu_print"
-                   iconic="true"
-                   label="&printCmd.label;"
-                   key="printKb"
-                   command="cmd_print">
-            <menupopup>
-              <menuitem id="appmenu_print_popup"
-                        class="menuitem-iconic"
-                        label="&printCmd.label;"
-                        key="key_print"
-                        command="cmd_print"/>
-#ifndef XP_MACOSX
-              <menuitem id="appmenu_printPreview"
-                        label="&printPreviewCmd.label;"
-                        command="cmd_printpreview"/>
-#endif
-              <menuitem id="appmenu_printSetup"
-                        label="&printSetupCmd.label;"
-                        command="cmd_printSetup"/>
-            </menupopup>
-        </splitmenu>
-        <menuseparator class="appmenu-menuseparator"/>
-        <menu id="appmenu_saveAs"
-              label="&saveAsMenu.label;">
-          <menupopup id="menu_SavePopup">
-            <menuitem id="appmenu_saveAsFile"
-                      label="&saveAsFileCmd.label;"
-                      key="key_saveAsFile"
-                      command="cmd_saveAsFile"/>
-            <menuitem id="appmenu_saveAsTemplate"
-                      label="&saveAsTemplateCmd.label;"
-                      command="cmd_saveAsTemplate"/>
-          </menupopup>
-        </menu>
-        <menu id="appmenu_FolderViews"
-              label="&folderView.label;">
-          <menupopup id="appmenu_FolderViewsPopup"
-                     onpopupshowing="InitAppFolderViewsMenu();
-                                     InitViewFolderViewsMenu(event);">
-            <menuitem id="appmenu_allFolders"
-                      value="all"
-                      label="&allFolders.label;"
-                      type="radio"
-                      name="viewmessages"
-                      oncommand="gFolderTreeView.toggleMode(this.value);"/>
-            <menuitem id="appmenu_smartFolders"
-                      value="smart"
-                      label="&unifiedFolders.label;"
-                      type="radio"
-                      name="viewmessages"
-                      oncommand="gFolderTreeView.toggleMode(this.value);"/>
-            <menuitem id="appmenu_unreadFolders"
-                      value="unread"
-                      label="&unreadFolders.label;"
-                      type="radio"
-                      name="viewmessages"
-                      oncommand="gFolderTreeView.toggleMode(this.value);"/>
-            <menuitem id="appmenu_favoriteFolders"
-                      value="favorite"
-                      label="&favoriteFolders.label;"
-                      type="radio"
-                      name="viewmessages"
-                      oncommand="gFolderTreeView.toggleMode(this.value);"/>
-            <menuitem id="appmenu_recentFolders"
-                      value="recent"
-                      label="&recentFolders.label;"
-                      type="radio"
-                      name="viewmessages"
-                      oncommand="gFolderTreeView.toggleMode(this.value);"/>
-            <menuseparator id="appmenu_compactViewSeparator"/>
-            <menuitem id="appmenu_compactFolderView"
-                      label="&compactVersion.label;"
-                      type="checkbox"
-                      oncommand="gFolderTreeView.toggleCompact(this.getAttribute('checked') == 'true');"/>
-            <menuseparator id="appmenu_favoritePropertiesSeparator"/>
-            <menuitem id="appmenu_favoriteFolder"
-                      type="checkbox"
-                      label="&menuFavoriteFolder.label;"
-                      checked="false"
-                      oncommand="ToggleFavoriteFolderFlag();"/>
-            <menuitem id="appmenu_properties"
-                      label="&folderPropsCmd2.label;"
-                      command="cmd_properties"/>
-          </menupopup>
-        </menu>
-        <menuitem id="appmenu_emptyTrash"
-                  label="&emptyTrashCmd.label;"
-                  command="cmd_emptyTrash"/>
-        <spacer flex="1"/>
-        <menuitem id="appmenu-quit"
-                  class="menuitem-iconic"
-#ifdef XP_WIN
-                  label="&quitApplicationCmd.label;"
-#else
-                  label="&quitApplicationCmdUnix.label;"
-#endif
-                  command="cmd_quit"/>
-      </vbox>
-      <vbox id="appmenuSecondaryPane">
-        <menuitem id="appmenu_activityManager"
-                  label="&activitymanager.label;"
-                  oncommand="openActivityMgr();"/>
-        <splitmenu id="appmenu_filters"
-                  label="&filtersCmd2.label;"
-                  command="cmd_displayMsgFilters">
-          <menupopup id="appmenu_FilterMenu">
-            <menuitem id="appmenu_filtersCmd"
-                      label="&filtersCmd2.label;"
-                      command="cmd_displayMsgFilters"/>
-            <menuitem id="appmenu_applyFilters"
-                      label="&filtersApply.label;"
-                      command="cmd_applyFilters"/>
-            <menuitem id="appmenu_applyFiltersToSelection"
-                      label="&filtersApplyToMessage.label;"
-                      command="cmd_applyFiltersToSelection"/>
-          </menupopup>
-        </splitmenu>
-        <spacer class="appmenuPane-spacer"/>
-        <splitmenu id="appmenu_addons"
-                   class="menuitem-iconic"
-                   label="&addons.label;"
-                   oncommand="openAddonsMgr();">
-          <menupopup id="appmenu_addonPrefs"
-                     onpopupshowing="initAddonPrefsMenu(this);"
-                     oncommand="openAddonPrefs(event.target.getAttribute('value'), event.target.getAttribute('optionsType'));">
-            <menuitem label="&addons.label;" oncommand="openAddonsMgr(); event.stopPropagation();"/>
-            <menuseparator class="appmenu-menuseparator"/>
-            <menuitem label="&addonNoPrefs.label;" disabled="true"/>
-          </menupopup>
-        </splitmenu>
-        <splitmenu id="appmenu_customize"
-#ifdef XP_WIN
-                   label="&preferencesCmd2.label;"
-#else
-                   label="&preferencesCmdUnix.label;"
-#endif
-                   oncommand="openOptionsDialog();">
-          <menupopup id="appmenu_customizeMenu"
-                     onpopupshowing="onViewToolbarsPopupShowing(event, 'mail-toolbox', document.getElementById('appmenu_quickFilterBar'));">
-            <menuitem id="appmenu_preferences"
-#ifdef XP_WIN
-                      label="&preferencesCmd2.label;"
-#else
-                      label="&preferencesCmdUnix.label;"
-#endif
-                      oncommand="openOptionsDialog();"/>
-            <menuitem id="appmenu_accountmgr"
-                      label="&accountManagerCmd2.label;"
-                      oncommand="MsgAccountManager(null);"/>
-            <menuseparator/>
-            <menuitem id="appmenu_quickFilterBar"
-                      type="checkbox"
-                      label="&quickFilterBar.toggleBarVisibility.appmenu.label;"
-                      command="cmd_toggleQuickFilterBar">
-              <observes element="view_toolbars_popup_quickFilterBar"
-                        attribute="checked"/>
-            </menuitem>
-            <menuitem id="appmenu_showStatusbar"
-                      type="checkbox"
-                      label="&showTaskbarCmd.label;"
-                      oncommand="goToggleToolbar('status-bar', 'menu_showTaskbar')"
-                      checked="true"
-                      observes="menu_showTaskbar"/>
-            <menuseparator id="appmenu_toggleToolbarsSeparator"/>
-            <menuitem id="appmenu_toolbarLayout"
-                      label="&appmenuToolbarLayout.label;"
-                      command="cmd_CustomizeMailToolbar"/>
-            <menuseparator id="appmenu_paneViewSeparator"/>
-            <menu id="appmenu_MessagePaneLayout"
-                  label="&messagePaneLayoutStyle.label;">
-              <menupopup id="appmenu_view_layout_popup"
-                         onpopupshowing="InitViewLayoutStyleMenu(event)">
-                <menuitem id="appmenu_messagePaneClassic"
-                          type="radio"
-                          label="&messagePaneClassic.label;"
-                          name="viewlayoutgroup"
-                          command="cmd_viewClassicMailLayout"/>
-                <menuitem id="appmenu_messagePaneWide"
-                          type="radio"
-                          label="&messagePaneWide.label;"
-                          name="viewlayoutgroup"
-                          command="cmd_viewWideMailLayout"/>
-                <menuitem id="appmenu_messagePaneVertical"
-                          type="radio"
-                          label="&messagePaneVertical.label;"
-                          name="viewlayoutgroup"
-                          command="cmd_viewVerticalMailLayout"/>
-                <menuseparator id="appmenu_viewMenuAfterPaneVerticalSeparator"/>
-                <menuitem id="appmenu_showFolderPane"
-                          type="checkbox"
-                          label="&showFolderPaneCmd.label;"
-                          command="cmd_toggleFolderPane"/>
-                <menuitem id="appmenu_showFolderPaneCols"
-                          type="checkbox"
-                          label="&showFolderPaneColsCmd.label;"
-                          command="cmd_toggleFolderPaneCols"/>
-                <menuitem id="appmenu_showMessage"
-                          type="checkbox"
-                          label="&showMessageCmd.label;"
-                          key="key_toggleMessagePane"
-                          command="cmd_toggleMessagePane"/>
-              </menupopup>
-            </menu>
-          </menupopup>
-        </splitmenu>
-        <spacer class="appmenuPane-spacer"/>
-        <!-- File menu -->
-        <menu id="appmenu_File"
-              label="&fileMenu.label;">
-          <menupopup id="appmenu_FilePopup">
-            <menuitem id="appmenu_openMessageFileMenuitem"
-                      label="&openMessageFileCmd.label;"
-                      oncommand="MsgOpenFromFile();"/>
-            <menuitem id="appmenu_close"
-                      label="&closeCmd.label;"
-                      key="key_close"
-                      command="cmd_close"/>
-            <menuseparator id="appmenu_fileMenuAfterCloseSeparator"/>
-            <menu id="appmenu_getNewMsgFor"
-                  label="&getNewMsgForCmd.label;"
-                  oncommand="MsgGetMessagesForAccount();">
-              <menupopup is="folder-menupopup" id="appmenu_getAllNewMsgPopup"
-                         mode="getMail"
-                         expandFolders="false"
-                         oncommand="MsgGetMessagesForAccount(event.target._folder); event.stopPropagation();">
-                <menuitem id="appmenu_getnewmsgs_all_accounts"
-                          label="&getAllNewMsgCmdPopupMenu.label;"
-                          key="key_getAllNewMessages"
-                          command="cmd_getMsgsForAuthAccounts"/>
-                <menuitem id="appmenu_getnewmsgs_current_account"
-                          label="&getNewMsgCurrentAccountCmdPopupMenu.label;"
-                          key="key_getNewMessages"
-                          command="cmd_getNewMessages"/>
-                <menuseparator/>
-              </menupopup>
-            </menu>
-            <menuitem id="appmenu_getNextNMsgs"
-                      label="&getNextNMsgCmd2.label;"
-                      command="cmd_getNextNMessages"/>
-            <menuitem id="appmenu_sendUnsentMsgs"
-                      label="&sendUnsentCmd.label;"
-                      command="cmd_sendUnsentMsgs"/>
-            <menuitem id="appmenu_subscribe"
-                      label="&subscribeCmd.label;"
-                      command="cmd_subscribe"/>
-            <menuseparator id="appmenu_fileMenuAfterSubscribeSeparator"/>
-            <menuitem id="appmenu_deleteFolder"
-                      label="&deleteFolder.label;"
-                      command="cmd_deleteFolder"/>
-            <menuitem id="appmenu_renameFolder"
-                      label="&renameFolder.label;"
-                      key="key_renameFolder"
-                      command="cmd_renameFolder"/>
-            <menuseparator id="appmenu_fileMenuAfterRenameSeparator"/>
-            <menuitem id="appmenu_compactFolder"
-                      label="&compactFolders.label;"
-                      command="cmd_compactFolder"/>
-            <menuseparator id="appmenu_fileMenuAfterCompactSeparator"/>
-            <menu id="appmenu_offline"
-                  label="&offlineMenu.label;">
-              <menupopup id="appmenu_OfflinePopup">
-                <menuitem id="appmenu_goOffline"
-                          type="checkbox"
-                          label="&offlineGoOfflineCmd.label;"
-                          oncommand="MailOfflineMgr.toggleOfflineStatus();"/>
-                <menuseparator id="appmenu_offlineMenuAfterGoSeparator"/>
-                <menuitem id="appmenu_synchronizeOffline"
-                          label="&synchronizeOfflineCmd.label;"
-                          command="cmd_synchronizeOffline"/>
-                <menuitem id="appmenu_settingsOffline"
-                          label="&settingsOfflineCmd2.label;"
-                          command="cmd_settingsOffline"/>
-                <menuseparator id="app_offlineMenuAfterSettingsSeparator"/>
-                <menuitem id="appmenu_downloadFlagged"
-                          label="&downloadStarredCmd.label;"
-                          command="cmd_downloadFlagged"/>
-                <menuitem id="appmenu_downloadSelected"
-                          label="&downloadSelectedCmd.label;"
-                          command="cmd_downloadSelected"/>
-              </menupopup>
-            </menu>
-          </menupopup>
-        </menu>
-        <!-- View menu -->
-        <menu id="appmenu_View"
-              label="&viewMenu.label;">
-          <menupopup id="appmenu_View_Popup">
-            <menu id="appmenu_viewSortMenu"
-                  label="&sortMenu.label;">
-              <menupopup id="appmenu_viewSortPopup" onpopupshowing="InitAppViewSortByMenu()">
-                <menuitem id="appmenu_sortByDateMenuitem"
-                          type="radio"
-                          name="sortby"
-                          label="&sortByDateCmd.label;"
-                          oncommand="MsgSortThreadPane('byDate')"/>
-                <menuitem id="appmenu_sortByReceivedMenuitem"
-                          type="radio"
-                          name="sortby"
-                          label="&sortByReceivedCmd.label;"
-                          oncommand="MsgSortThreadPane('byReceived')"/>
-                <menuitem id="appmenu_sortByFlagMenuitem"
-                          type="radio"
-                          name="sortby"
-                          label="&sortByStarCmd.label;"
-                          oncommand="MsgSortThreadPane('byFlagged')"/>
-                <menuitem id="appmenu_sortByOrderReceivedMenuitem"
-                          type="radio"
-                          name="sortby"
-                          label="&sortByOrderReceivedCmd.label;"
-                          oncommand="MsgSortThreadPane('byId')"/>
-                <menuitem id="appmenu_sortByPriorityMenuitem"
-                          type="radio"
-                          name="sortby"
-                          label="&sortByPriorityCmd.label;"
-                          oncommand="MsgSortThreadPane('byPriority')"/>
-                <menuitem id="appmenu_sortByFromMenuitem"
-                          type="radio"
-                          name="sortby"
-                          label="&sortByFromCmd.label;"
-                          oncommand="MsgSortThreadPane('byAuthor')"/>
-                <menuitem id="appmenu_sortByRecipientMenuitem"
-                          type="radio"
-                          name="sortby"
-                          label="&sortByRecipientCmd.label;"
-                          oncommand="MsgSortThreadPane('byRecipient')"/>
-                <menuitem id="appmenu_sortByCorrespondentMenuitem"
-                          type="radio"
-                          name="sortby"
-                          label="&sortByCorrespondentCmd.label;"
-                          oncommand="MsgSortThreadPane('byCorrespondent')"/>
-                <menuitem id="appmenu_sortBySizeMenuitem"
-                          type="radio"
-                          name="sortby"
-                          label="&sortBySizeCmd.label;"
-                          oncommand="MsgSortThreadPane('bySize')"/>
-                <menuitem id="appmenu_sortByStatusMenuitem"
-                          type="radio"
-                          name="sortby"
-                          label="&sortByStatusCmd.label;"
-                          oncommand="MsgSortThreadPane('byStatus')"/>
-                <menuitem id="appmenu_sortBySubjectMenuitem"
-                          type="radio"
-                          name="sortby"
-                          label="&sortBySubjectCmd.label;"
-                          oncommand="MsgSortThreadPane('bySubject')"/>
-                <menuitem id="appmenu_sortByUnreadMenuitem"
-                          type="radio"
-                          name="sortby"
-                          label="&sortByUnreadCmd.label;"
-                          oncommand="MsgSortThreadPane('byUnread')"/>
-                <menuitem id="appmenu_sortByTagsMenuitem"
-                          type="radio"
-                          name="sortby"
-                          label="&sortByTagsCmd.label;"
-                          oncommand="MsgSortThreadPane('byTags')"/>
-                <menuitem id="appmenu_sortByJunkStatusMenuitem"
-                          type="radio"
-                          name="sortby"
-                          label="&sortByJunkStatusCmd.label;"
-                          oncommand="MsgSortThreadPane('byJunkStatus')"/>
-                <menuitem id="appmenu_sortByAttachmentsMenuitem"
-                          type="radio"
-                          name="sortby"
-                          label="&sortByAttachmentsCmd.label;"
-                          oncommand="MsgSortThreadPane('byAttachments')"/>
-                <menuseparator id="appmenu_sortAfterAttachmentSeparator"/>
-                <menuitem id="appmenu_sortAscending"
-                          type="radio"
-                          name="sortdirection"
-                          label="&sortAscending.label;"
-                          oncommand="MsgSortAscending()"/>
-                <menuitem id="appmenu_sortDescending"
-                          type="radio"
-                          name="sortdirection"
-                          label="&sortDescending.label;"
-                          oncommand="MsgSortDescending()"/>
-                <menuseparator id="appmenu_sortAfterDescendingSeparator"/>
-                <menuitem id="appmenu_sortThreaded"
-                          type="radio"
-                          name="threaded"
-                          label="&sortThreaded.label;"
-                          oncommand="MsgSortThreaded();"/>
-                <menuitem id="appmenu_sortUnthreaded"
-                          type="radio"
-                          name="threaded"
-                          label="&sortUnthreaded.label;"
-                          oncommand="MsgSortUnthreaded();"/>
-                <menuitem id="appmenu_groupBySort"
-                          type="radio"
-                          name="group"
-                          label="&groupBySort.label;"
-                          oncommand="MsgGroupBySort();"/>
-              </menupopup>
-            </menu>
-            <menu id="appmenu_viewMessageViewMenu"
-                  label="&msgsMenu.label;"
-                  command="mailHideMenus"
-                  oncommand="ViewChangeByMenuitem(event.target);">
-              <menupopup id="appmenu_viewMessagePopup"
-                         onpopupshowing="RefreshViewPopup(this);">
-                <menuitem id="appmenu_viewMessageAll"
-                          value="0"
-                          type="radio"
-                          label="&viewAll.label;"/>
-                <menuitem id="appmenu_viewMessageUnread"
-                          value="1"
-                          type="radio"
-                          label="&viewUnread.label;"/>
-                <menuitem id="appmenu_viewMessageNotDeleted"
-                          value="3"
-                          type="radio"
-                          label="&viewNotDeleted.label;"/>
-                <menuseparator id="appmenu_messageViewAfterUnreadSeparator"/>
-                <menu id="viewMessageTags"
-                      label="&viewTags.label;">
-                  <menupopup id="appmenu_viewMessageTagsPopup"
-                             onpopupshowing="RefreshTagsPopup(this);"/>
-                </menu>
-                <menu id="appmenu_viewMessageCustomViews"
-                      label="&viewCustomViews.label;">
-                  <menupopup id="appmenu_viewMessageCustomViewsPopup"
-                             onpopupshowing="RefreshCustomViewsPopup(this);"/>
-                </menu>
-                <menuseparator id="appmenu_messageViewAfterCustomSeparator"/>
-                <menuitem id="appmenu_viewMessageVirtualFolder"
-                          value="7"
-                          label="&viewVirtualFolder.label;"/>
-                <menuitem id="appmenu_viewMessageCustomize"
-                          value="8"
-                          label="&viewCustomizeView.label;"/>
-              </menupopup>
-            </menu>
-            <menu label="&threads.label;"
-                  id="appmenu_viewMessagesMenu">
-              <menupopup id="appmenu_ThreadsPopup"
-                         onpopupshowing="InitAppmenuViewMessagesMenu()">
-                <menuitem id="appmenu_viewAllMessagesMenuItem"
-                          type="radio"
-                          name="viewmessages"
-                          label="&allMsgsCmd.label;"
-                          disabled="true"
-                          command="cmd_viewAllMsgs"/>
-                <menuitem id="appmenu_viewUnreadMessagesMenuItem"
-                          type="radio"
-                          name="viewmessages"
-                          label="&unreadMsgsCmd.label;"
-                          disabled="true"
-                          command="cmd_viewUnreadMsgs"/>
-                <menuitem id="appmenu_viewThreadsWithUnreadMenuItem"
-                          type="radio"
-                          name="viewmessages"
-                          label="&threadsWithUnreadCmd.label;"
-                          disabled="true"
-                          command="cmd_viewThreadsWithUnread"/>
-                <menuitem id="appmenu_viewWatchedThreadsWithUnreadMenuItem"
-                          type="radio"
-                          name="viewmessages"
-                          label="&watchedThreadsWithUnreadCmd.label;"
-                          disabled="true"
-                          command="cmd_viewWatchedThreadsWithUnread"/>
-                <menuseparator id="appmenu_threadsAfterWatchedSeparator"/>
-                <menuitem id="appmenu_viewIgnoredThreadsMenuItem"
-                          type="checkbox"
-                          label="&ignoredThreadsCmd.label;"
-                          disabled="true"
-                          command="cmd_viewIgnoredThreads"/>
-                <menuseparator id="appmenu_threadsAfterIgnoredSeparator"/>
-                <menuitem id="appmenu_expandAllThreads"
-                          label="&expandAllThreadsCmd.label;"
-                          key="key_expandAllThreads"
-                          disabled="true"
-                          command="cmd_expandAllThreads"/>
-                <menuitem id="appmenu_collapseAllThreads"
-                          label="&collapseAllThreadsCmd.label;"
-                          key="key_collapseAllThreads"
-                          disabled="true"
-                          command="cmd_collapseAllThreads"/>
-              </menupopup>
-            </menu>
-            <menuseparator id="appmenu_viewAfterThreadsSeparator"/>
-            <menu id="appmenu_viewHeadersMenu"
-                  label="&headersMenu.label;">
-              <menupopup id="appmenu_HeadersPopup" onpopupshowing="InitViewHeadersMenu();">
-                <menuitem id="appmenu_viewallheaders"
-                          type="radio"
-                          name="viewheadergroup"
-                          label="&headersAllCmd.label;"
-                          command="cmd_viewAllHeader"/>
-                <menuitem id="appmenu_viewnormalheaders"
-                          type="radio"
-                          name="viewheadergroup"
-                          label="&headersNormalCmd.label;"
-                          command="cmd_viewNormalHeader"/>
-              </menupopup>
-            </menu>
-            <menu id="appmenu_viewBodyMenu"
-                  label="&bodyMenu.label;">
-              <menupopup id="appmenu_viewBodyPopMenu"
-                         onpopupshowing="InitAppmenuViewBodyMenu()">
-                <menuitem id="appmenu_bodyAllowHTML"
-                          type="radio"
-                          name="bodyPlaintextVsHTMLPref"
-                          label="&bodyAllowHTML.label;"
-                          oncommand="MsgBodyAllowHTML()"/>
-                <menuitem id="appmenu_bodySanitized"
-                          type="radio"
-                          name="bodyPlaintextVsHTMLPref"
-                          label="&bodySanitized.label;"
-                          oncommand="MsgBodySanitized()"/>
-                <menuitem id="appmenu_bodyAsPlaintext"
-                          type="radio"
-                          name="bodyPlaintextVsHTMLPref"
-                          label="&bodyAsPlaintext.label;"
-                          oncommand="MsgBodyAsPlaintext()"/>
-                <menuitem id="appmenu_bodyAllParts"
-                          type="radio"
-                          name="bodyPlaintextVsHTMLPref"
-                          label="&bodyAllParts.label;"
-                          oncommand="MsgBodyAllParts()"/>
-              </menupopup>
-            </menu>
-            <menu id="appmenu_viewFeedSummary"
-                  label="&bodyMenuFeed.label;">
-              <menupopup id="appmenu_viewFeedSummaryPopupMenu"
-                         onpopupshowing="InitAppmenuViewBodyMenu()">
-                <menuitem id="appmenu_bodyFeedGlobalWebPage"
-                          type="radio"
-                          name="viewFeedSummaryGroup"
-                          label="&viewFeedWebPage.label;"
-                          observes="bodyFeedGlobalWebPage"
-                          oncommand="FeedMessageHandler.onSelectPref = 0"/>
-                <menuitem id="appmenu_bodyFeedGlobalSummary"
-                          type="radio"
-                          name="viewFeedSummaryGroup"
-                          label="&viewFeedSummary.label;"
-                          observes="bodyFeedGlobalSummary"
-                          oncommand="FeedMessageHandler.onSelectPref = 1"/>
-                <menuitem id="appmenu_bodyFeedPerFolderPref"
-                          type="radio"
-                          name="viewFeedSummaryGroup"
-                          label="&viewFeedSummaryFeedPropsPref.label;"
-                          observes="bodyFeedPerFolderPref"
-                          oncommand="FeedMessageHandler.onSelectPref = 2"/>
-                <menuseparator id="appmenu_viewFeedSummarySeparator"/>
-                <menuitem id="appmenu_bodyFeedSummaryAllowHTML"
-                          type="radio"
-                          name="viewFeedBodyHTMLGroup"
-                          label="&bodyAllowHTML.label;"
-                          oncommand="MsgFeedBodyRenderPrefs(false, 0, 0)"/>
-                <menuitem id="appmenu_bodyFeedSummarySanitized"
-                          type="radio"
-                          name="viewFeedBodyHTMLGroup"
-                          label="&bodySanitized.label;"
-                          oncommand="MsgFeedBodyRenderPrefs(false, 3, gDisallow_classes_no_html)"/>
-                <menuitem id="appmenu_bodyFeedSummaryAsPlaintext"
-                          type="radio"
-                          name="viewFeedBodyHTMLGroup"
-                          label="&bodyAsPlaintext.label;"
-                          oncommand="MsgFeedBodyRenderPrefs(true, 1, gDisallow_classes_no_html)"/>
-              </menupopup>
-            </menu>
-            <menuitem id="appmenu_viewAttachmentsInlineMenuitem"
-                      label="&viewAttachmentsInlineCmd.label;"
-                      oncommand="ToggleInlineAttachment(event.target)"
-                      type="checkbox"
-                      checked="true"/>
-            <menuseparator id="appmenu_viewAfterAttachmentsSeparator"/>
-            <menu id="appmenu_viewFullZoomMenu"
-                  label="&fullZoom.label;"
-                  onpopupshowing="UpdateFullZoomMenu()">
-              <menupopup id="appmenu_viewFullZoomPopupMenu">
-                <menuitem id="appmenu_fullZoomEnlarge"
-                          label="&fullZoomEnlargeCmd.label;"
-                          key="key_fullZoomEnlarge"
-                          command="cmd_fullZoomEnlarge"/>
-                <menuitem id="appmenu_fullZoomReduce"
-                          label="&fullZoomReduceCmd.label;"
-                          key="key_fullZoomReduce"
-                          command="cmd_fullZoomReduce"/>
-                <menuseparator id="appmenu_fullZoomAfterReduceSeparator"/>
-                <menuitem id="appmenu_fullZoomReset"
-                          label="&fullZoomResetCmd.label;"
-                          key="key_fullZoomReset"
-                          command="cmd_fullZoomReset"/>
-                <menuseparator id="appmenu_fullZoomAfterResetSeparator"/>
-                <menuitem id="appmenu_fullZoomToggle"
-                          label="&fullZoomToggleCmd.label;"
-                          type="checkbox"
-                          command="cmd_fullZoomToggle"
-                          checked="false"/>
-              </menupopup>
-            </menu>
-            <menu id="appmenu_charsetMenu"
-                  onpopupshowing="UpdateCharsetMenu(msgWindow.mailCharacterSet, this);"
-                  oncommand="MailSetCharacterSet(event)"
-                  label="&charsetMenu2.label;"
-                  accesskey="&charsetMenu2.accesskey;">
-              <menupopup id="appmenu_charsetPopup"
-                         onpopupshowing="CharsetMenu.build(this, true, this.getAttribute('detectors') != 'false');"/>
-            </menu>
-            <menuseparator id="appmenu_viewAfterCharsetSeparator"/>
-            <menuitem id="appmenu_pageSourceMenuItem"
-                      label="&pageSourceCmd.label;"
-                      key="key_viewPageSource"
-                      command="cmd_viewPageSource"/>
-            <menuitem id="appmenu_securityStatus"
-                      label="&menu_securityStatus.label;"
-                      accesskey="&menu_securityStatus.accesskey;"
-                      command="cmd_viewSecurityStatus"/>
-          </menupopup>
-        </menu>
-        <!-- Go menu -->
-        <menu id="appmenu_Go"
-              label="&goMenu.label;">
-          <menupopup id="appmenu_GoPopup">
-            <menu id="appmenu_goNextMenu"
-                  label="&nextMenu.label;">
-              <menupopup id="appmenu_GoNextPopup">
-                <menuitem id="appmenu_nextMsg"
-                          label="&nextMsgCmd.label;"
-                          key="key_nextMsg"
-                          command="cmd_nextMsg"/>
-                <menuitem id="appmenu_nextUnreadMsg"
-                          label="&nextUnreadMsgCmd.label;"
-                          key="key_nextUnreadMsg"
-                          command="cmd_nextUnreadMsg"/>
-                <menuitem id="appmenu_nextFlaggedMsg"
-                          label="&nextStarredMsgCmd.label;"
-                          command="cmd_nextFlaggedMsg"/>
-                <menuseparator id="appmenu_goNextAfterFlaggedSeparator"/>
-                <menuitem id="appmenu_nextUnreadThread"
-                          label="&nextUnreadThread.label;"
-                          key="key_nextUnreadThread"
-                          command="cmd_nextUnreadThread"/>
-              </menupopup>
-            </menu>
-            <menu id="appmenu_goPreviousMenu"
-                  label="&prevMenu.label;">
-              <menupopup id="appmenu_GoPreviousPopup">
-                <menuitem id="appmenu_prevMsg"
-                          label="&prevMsgCmd.label;"
-                          key="key_previousMsg"
-                          command="cmd_previousMsg"/>
-                <menuitem id="appmenu_prevUnreadMsg"
-                          label="&prevUnreadMsgCmd.label;"
-                          key="key_previousUnreadMsg"
-                          command="cmd_previousUnreadMsg"/>
-                <menuitem id="appmenu_prevFlaggedMsg"
-                          label="&prevStarredMsgCmd.label;"
-                          command="cmd_previousFlaggedMsg"/>
-              </menupopup>
-            </menu>
-            <menuitem id="appmenu_goForward"
-                      label="&goForwardCmd.label;"
-                      key="key_goForward"
-                      command="cmd_goForward"/>
-            <menuitem id="appmenu_goBack"
-                      label="&goBackCmd.label;"
-                      key="key_goBack"
-                      command="cmd_goBack"/>
-            <menuseparator id="appmenu_goNextSeparator"/>
-            <menuitem id="appmenu_goChat"
-                      label="&goChatCmd.label;"
-                      key="key_goChat"
-                      command="cmd_chat"/>
-            <menuseparator id="appmenu_goChatSeparator"/>
-            <menu id="appmenu_goFolderMenu"
-                  label="&folderMenu.label;"
-                  command="cmd_goFolder">
-              <menupopup is="folder-menupopup" id="appmenu_GoFolderPopup"
-                         showFileHereLabel="true"
-                         showRecent="true"
-                         recentLabel="&contextMoveCopyMsgRecentMenu.label;"/>
-            </menu>
-            <menuseparator id="appmenu_goFolderSeparator"/>
-            <menu id="appmenu_goRecentlyClosedTabs"
-                  label="&goRecentlyClosedTabs.label;"
-                  observes="cmd_undoCloseTab">
-              <menupopup id="appmenu_GoRecentlyClosedTabsPopup"
-                         onpopupshowing="return InitRecentlyClosedTabsPopup(this)" />
-            </menu>
-            <menuseparator id="appmenu_goRecentlyClosedTabsSeparator"/>
-            <menuitem id="appmenu_goStartPage"
-                      label="&startPageCmd.label;"
-                      key="key_goStartPage"
-                      command="cmd_goStartPage"/>
-          </menupopup>
-        </menu>
-        <!-- Message menu -->
-        <menu id="appmenu_messageMenu"
-              label="&msgMenu.label;">
-          <menupopup id="appmenu_messageMenuPopup"
-                     onpopupshowing="InitAppMessageMenu();">
-            <menuitem id="appmenu_newMsgCmd"
-                      label="&newMsgCmd.label;"
-                      key="key_newMessage2"
-                      command="cmd_newMessage"/>
-            <menuitem id="appmenu_replyMainMenu"
-                      label="&replyMsgCmd.label;"
-                      key="key_reply"
-                      command="cmd_reply"/>
-            <menuitem id="appmenu_replyNewsgroupMainMenu"
-                      label="&replyNewsgroupCmd2.label;"
-                      key="key_reply"
-                      command="cmd_replyGroup"/>
-            <menuitem id="appmenu_replySenderMainMenu"
-                      label="&replySenderCmd.label;"
-                      command="cmd_replySender"/>
-            <menuitem id="appmenu_replyToAll"
-                      label="&replyToAllMsgCmd.label;"
-                      key="key_replyall"
-                      command="cmd_replyall"/>
-            <menuitem id="appmenu_replyToList"
-                      label="&replyToListMsgCmd.label;"
-                      key="key_replylist"
-                      command="cmd_replylist"/>
-            <menuitem id="appmenu_forwardMsg"
-                      label="&forwardMsgCmd.label;"
-                      key="key_forward"
-                      command="cmd_forward"/>
-            <menu id="appmenu_forwardAsMenu"
-                  label="&forwardAsMenu.label;">
-              <menupopup id="appmenu_forwardAsPopup">
-                <menuitem id="appmenu_forwardAsInline"
-                          label="&forwardAsInline.label;"
-                          command="cmd_forwardInline"/>
-                <menuitem id="appmenu_forwardAsAttachment"
-                          label="&forwardAsAttachmentCmd.label;"
-                          command="cmd_forwardAttachment"/>
-              </menupopup>
-            </menu>
-            <menuitem id="appmenu_editMsgAsNew"
-                      label="&editAsNewMsgCmd.label;"
-                      key="key_editAsNew"
-                      command="cmd_editAsNew"/>
-            <menuitem id="appmenu_editDraftMsg"
-                      label="&editDraftMsgCmd.label;"
-                      command="cmd_editDraftMsg"/>
-            <menuitem id="appmenu_newMsgFromTemplateCmd"
-                      label="&newMsgFromTemplateCmd.label;"
-                      key="key_newMsgFromTemplate"
-                      command="cmd_newMsgFromTemplate"/>
-            <menuitem id="appmenu_editTemplateMsgCmd"
-                      label="&editTemplateMsgCmd.label;"
-                      command="cmd_editTemplateMsg"/>
-            <menuseparator id="appmenu_messageMenuAfterCompositionCommandsSeparator"/>
-            <menuitem id="appmenu_openMessageWindowMenuitem"
-                      label="&openMessageWindowCmd.label;"
-                      key="key_openMessage"
-                      command="cmd_openMessage"/>
-#ifdef MAIN_WINDOW
-            <menuitem id="appmenu_openConversationMenuitem"
-                      label="&openInConversationCmd.label;"
-                      key="key_openConversation"
-                      command="cmd_openConversation"/>
-#endif
-            <menu id="appmenu_openFeedMessage"
-                  label="&openFeedMessage1.label;">
-              <menupopup id="appmenu_openFeedMessagePopup">
-                <menuitem id="appmenu_openFeedWebPage"
-                          type="radio"
-                          name="openFeedGroup"
-                          label="&openFeedWebPage.label;"
-                          oncommand="FeedMessageHandler.onOpenPref = 0"/>
-                <menuitem id="appmenu_openFeedSummary"
-                          type="radio"
-                          name="openFeedGroup"
-                          label="&openFeedSummary.label;"
-                          oncommand="FeedMessageHandler.onOpenPref = 1"/>
-                <menuitem id="appmenu_openFeedWebPageInMessagePane"
-                          type="radio"
-                          name="openFeedGroup"
-                          label="&openFeedWebPageInMP.label;"
-                          oncommand="FeedMessageHandler.onOpenPref = 2"/>
-              </menupopup>
-            </menu>
-#ifdef MAIN_WINDOW
-            <menuseparator id="appmenu_messageAfterOpenMsgSeparator"/>
-#endif
-            <menu id="appmenu_tagMenu"
-                  label="&tagMenu.label;"
-                  command="cmd_tag">
-              <menupopup id="appmenu_tagMenu-tagpopup"
-                         onpopupshowing="InitMessageTags(this);">
-                <menuitem id="appmenu_addNewTag"
-                          label="&addNewTag.label;"
-                          command="cmd_addTag"/>
-                <menuitem id="appmenu_manageTags"
-                          label="&manageTags.label;"
-                          command="cmd_manageTags"/>
-                <menuseparator id="appmenu_tagMenu-sep-afterTagAddNew"/>
-                <menuitem id="appmenu_tagMenu-tagRemoveAll"
-                          command="cmd_removeTags"/>
-                <menuseparator id="appmenu_tagMenuAfterRemoveSeparator"/>
-              </menupopup>
-            </menu>
-            <menu id="appmenu_markMenu"
-                  label="&markMenu.label;">
-              <menupopup id="appmenu_MarkPopup"
-                         onpopupshowing="InitMessageMark()">
-                <menuitem id="appmenu_markReadMenuItem"
-                          label="&markAsReadCmd.label;"
-                          command="cmd_markAsRead"/>
-                <menuitem id="appmenu_markUnreadMenuItem"
-                          label="&markAsUnreadCmd.label;"
-                          command="cmd_markAsUnread"/>
-                <menuitem id="appmenu_markThreadAsRead"
-                          label="&markThreadAsReadCmd.label;"
-                          key="key_markThreadAsRead"
-                          command="cmd_markThreadAsRead"/>
-                <menuitem id="appmenu_markReadByDate"
-                          label="&markReadByDateCmd.label;"
-                          key="key_markReadByDate"
-                          command="cmd_markReadByDate"/>
-                <menuitem id="appmenu_markAllRead"
-                          label="&markAllReadCmd.label;"
-                          key="key_markAllRead"
-                          command="cmd_markAllRead"/>
-                <menuseparator id="markMenuAfterAllReadSeparator"/>
-                <menuitem id="appmenu_markFlaggedMenuItem"
-                          type="checkbox"
-                          label="&markStarredCmd.label;"
-                          key="key_toggleFlagged"
-                          command="cmd_markAsFlagged"/>
-                <menuseparator id="markMenuAfterFlaggedSeparator"/>
-                <menuitem id="appmenu_markAsJunk"
-                          label="&markAsJunkCmd.label;"
-                          key="key_markJunk"
-                          command="cmd_markAsJunk"/>
-                <menuitem id="appmenu_markAsNotJunk"
-                          label="&markAsNotJunkCmd.label;"
-                          key="key_markNotJunk"
-                          command="cmd_markAsNotJunk"/>
-                <menuitem id="appmenu_recalculateJunkScore"
-                          label="&recalculateJunkScoreCmd.label;"
-                          command="cmd_recalculateJunkScore"/>
-              </menupopup>
-            </menu>
-            <menuseparator id="appmenu_messageMenuAfterMarkSeparator"/>
-            <menuitem id="appmenu_archiveMainMenu"
-                      label="&archiveMsgCmd.label;"
-                      key="key_archive"
-                      command="cmd_archive"/>
-            <menuitem id="appmenu_cancel"
-                      command="cmd_cancel"
-                      label="&cancelNewsMsgCmd.label;"/>
-            <menu id="appmenu_moveMenu"
-                  label="&moveMsgToMenu.label;"
-                  oncommand="MsgMoveMessage(event.target._folder)">
-              <menupopup is="folder-menupopup"
-                         mode="filing"
-                         showFileHereLabel="true"
-                         showRecent="true"
-                         recentLabel="&moveCopyMsgRecentMenu.label;"
-                         showFavorites="true"
-                         favoritesLabel="&contextMoveCopyMsgFavoritesMenu.label;"
-                         favoritesAccessKey="&contextMoveCopyMsgFavoritesMenu.accesskey;"/>
-            </menu>
-            <menu id="appmenu_copyMenu"
-                  label="&copyMsgToMenu.label;"
-                  oncommand="MsgCopyMessage(event.target._folder)">
-              <menupopup is="folder-menupopup"
-                         mode="filing"
-                         showFileHereLabel="true"
-                         showRecent="true"
-                         recentLabel="&moveCopyMsgRecentMenu.label;"
-                         showFavorites="true"
-                         favoritesLabel="&contextMoveCopyMsgFavoritesMenu.label;"
-                         favoritesAccessKey="&contextMoveCopyMsgFavoritesMenu.accesskey;"/>
-            </menu>
-            <menuitem id="appmenu_moveToFolderAgain"
-                      command="cmd_moveToFolderAgain"
-                      key="key_moveToFolderAgain"
-                      label="&moveToFolderAgain.label;"/>
-            <menuseparator id="appmenu_messageMenuAfterMoveCommandsSeparator"/>
-            <menuitem id="appmenu_createFilter"
-                      label="&createFilter.label;"
-                      command="cmd_createFilterFromMenu"/>
-            <menuseparator id="appmenu_threadItemsSeparator"/>
-            <menuitem label="&killThreadMenu.label;"
-                      id="appmenu_killThread"
-                      key="key_killThread"
-                      type="checkbox"
-                      command="cmd_killThread"/>
-            <menuitem label="&killSubthreadMenu.label;"
-                      id="appmenu_killSubthread"
-                      key="key_killSubthread"
-                      type="checkbox"
-                      command="cmd_killSubthread"/>
-            <menuitem label="&watchThreadMenu.label;"
-                      id="appmenu_watchThread"
-                      key="key_watchThread"
-                      type="checkbox"
-                      command="cmd_watchThread"/>
-          </menupopup>
-        </menu>
-        <!-- Tools menu -->
-        <menu id="appmenu_tasksMenu"
-              label="&tasksMenu.label;">
-          <menupopup id="appmenu_taskPopup">
-            <menuitem hidden="true"
-                      id="appmenu_tasksMenuMail"
-                      class="menuitem-iconic menu-iconic"
-                      label="&messengerCmd.label;"
-                      key="key_mail"
-                      oncommand="toMessengerWindow();"/>
-            <menuitem id="appmenu_addressBook"
-                      label="&addressBookCmd.label;"
-                      key="key_addressbook"
-                      oncommand="toOpenWindowByType('mail:addressbook', 'chrome://messenger/content/addressbook/addressbook.xul');"/>
-            <menuseparator id="devToolsSeparator"/>
-            <menuitem id="appmenu_openSavedFilesWnd"
-                      label="&savedFiles.label;"
-                      key="key_savedFiles"
-                      oncommand="openSavedFilesWnd();"/>
-            <menu id="appmenu_imAccountsStatus"
-                  label="&imAccountsStatus.label;"
-                  command="cmd_chatStatus">
-              <menupopup id="appmenu_imStatusMenupopup">
-                <menuitem id="appmenu_imStatusAvailable"
-                          status="available"
-                          label="&imStatus.available;"
-                          class="menuitem-iconic"/>
-                <menuitem id="appmenu_imStatusUnavailable"
-                          status="unavailable"
-                          label="&imStatus.unavailable;"
-                          class="menuitem-iconic"/>
-                <menuseparator id="appmenu_imStatusOfflineSeparator"/>
-                <menuitem id="appmenu_imStatusOffline"
-                          status="offline"
-                          label="&imStatus.offline;"
-                          class="menuitem-iconic"/>
-                <menuseparator id="appmenu_imStatusShowAccountsSeparator"/>
-                <menuitem id="appmenu_imStatusShowAccounts"
-                          label="&imStatus.showAccounts;"/>
-              </menupopup>
-            </menu>
-            <menuitem id="appmenu_joinChatMenuItem"
-                      label="&joinChatCmd.label;"
-                      command="cmd_joinChat"/>
-            <menuseparator id="appmenu_afterChatSeparator"/>
-            <menuitem id="appmenu_runJunkControls"
-                      label="&runJunkControls.label;"
-                      command="cmd_runJunkControls"/>
-            <menuitem id="appmenu_deleteJunk"
-                      label="&deleteJunk.label;"
-                      command="cmd_deleteJunk"/>
-            <menuseparator id="tasksMenuAfterDeleteSeparator"/>
-            <menuitem id="appmenu_import"
-                      label="&importCmd.label;"
-                      oncommand="toImport();"/>
-            <menu id="appmenu_devtoolsMenu"
-                  label="&devtoolsMenu.label;"
-                  accesskey="&devtoolsMenu.accesskey;">
-              <menupopup id="appmenu_devtoolsPopup">
-                <menuitem id="appmenu_devtoolsToolbox"
-                          label="&devToolboxCmd.label;"
-                          accesskey="&devToolboxCmd.accesskey;"
-                          key="key_devtoolsToolbox"
-                          oncommand="BrowserToolboxProcess.init();"/>
-                <menuitem id="appmenu_addonDebugging"
-                          label="&debugAddonsCmd.label;"
-                          accesskey="&debugAddonsCmd.accesskey;"
-                          oncommand="openAboutDebugging('addons')"/>
-                <menuitem id="appmenu_tabsDebugging"
-                          label="&tabsDebugCmd.label;"
-                          accesskey="&tabsDebugCmd.accesskey;"
-                          oncommand="openAboutDebugging('tabs')"/>
-                <menuseparator id="appmenu_debuggingSeparator"/>
-                <menuitem id="appmenu_javascriptConsole"
-                          label="&errorConsoleCmd.label;"
-                          accesskey="&errorConsoleCmd.accesskey;"
-                          key="key_errorConsole"
-                          oncommand="toJavaScriptConsole();"/>
-                <menuitem id="appmenu_openScratchpad"
-                          label="&scratchpadCmd.label;"
-                          accesskey="&scratchpadCmd.accesskey;"
-                          key="key_scratchpad"
-                          oncommand="ScratchpadManager.openScratchpad({ executionContext: 2 });"/>
-              </menupopup>
-            </menu>
-            <menuitem id="appmenu_sanitizeHistory"
-                      label="&clearRecentHistory.label;"
-                      key="key_sanitizeHistory"
-                      oncommand="toSanitize();"/>
-          </menupopup>
-        </menu>
-        <!-- Help menu -->
-        <splitmenu id="appmenu_help"
-                   label="&helpMenuWin.label;"
-                   oncommand="openSupportURL();">
-            <menupopup id="appmenu_helpMenupopup">
-              <menuitem id="appmenu_openHelp"
-                        label="&productHelp.label;"
-                        key="key_openHelp"
-                        oncommand="openSupportURL();"/>
-              <menuitem id="menu_keyboardShortcuts"
-                        label="&helpKeyboardShortcuts.label;"
-                        oncommand="openLinkText(event, 'keyboardShortcutsURL');"/>
-              <menuitem id="getInvolved"
-                        label="&helpGetInvolvedPage.label;"
-                        oncommand="openLinkText(event, 'getInvolvedURL');"/>
-              <menuitem id="donationsPage"
-                        label="&helpDonationsPage.label;"
-                        oncommand="openLinkText(event, 'donateURL');"/>
-              <menuitem id="feedbackPage" hidden="true"
-                        label="&helpFeedbackPage.label;"
-                        oncommand="openFormattedURL('app.feedback.baseURL');"/>
-              <menuseparator/>
-              <menuitem id="appmenu_troubleshootingInfo"
-                        label="&helpTroubleshootingInfo.label;"
-                        oncommand="openAboutSupport();"/>
-              <menuitem id="appmenu_safeMode"
-                        label="&helpSafeMode.label;"
-                        oncommand="safeModeRestart();"/>
-              <menuseparator/>
-              <menuitem id="appmenu_about"
-                        label="&aboutProduct2.label;"
-                        oncommand="openAboutDialog();"/>
-            </menupopup>
-        </splitmenu>
-      </vbox>
-    </hbox>
-  </menupopup>
-
   <menupopup id="emailAddressPopup" position="after_start" class="emailAddressPopup"
              onpopupshowing="setupEmailAddressPopup(document.popupNode); goUpdateCommand('cmd_createFilterFromPopup')"
              onpopuphiding="hideEmailNewsPopup(document.popupNode);">
     <menuitem id="emailAddressPlaceHolder"
               disabled="true"/>
     <menuseparator/>
     <menuitem id="addToAddressBookItem"
               label="&AddDirectlyToAddressBook.label;"
--- a/mail/base/content/messageWindow.js
+++ b/mail/base/content/messageWindow.js
@@ -17,23 +17,29 @@
 /* import-globals-from mailWindow.js */
 /* import-globals-from mailWindowOverlay.js */
 /* import-globals-from messageDisplay.js */
 /* import-globals-from msgHdrView.js */
 /* import-globals-from msgViewNavigation.js */
 /* import-globals-from nsDragAndDrop.js */
 /* import-globals-from phishingDetector.js */
 /* import-globals-from toolbarIconColor.js */
+/* globals PanelUI */
 
 var {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
 var {MailUtils} = ChromeUtils.import("resource:///modules/MailUtils.jsm");
 var {AppConstants} = ChromeUtils.import("resource://gre/modules/AppConstants.jsm");
 var {XPCOMUtils} = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
 var {MsgHdrSyntheticView} = ChromeUtils.import("resource:///modules/MsgHdrSyntheticView.jsm");
 
+XPCOMUtils.defineLazyModuleGetters(this, {
+  CustomizableUI: "resource:///modules/CustomizableUI.jsm",
+  ShortcutUtils: "resource://gre/modules/ShortcutUtils.jsm",
+});
+
 // from MailNewsTypes.h
 var nsMsgKey_None = 0xFFFFFFFF;
 var nsMsgViewIndex_None = 0xFFFFFFFF;
 
 /* globals for a particular window */
 
 // we have no tree view; let people know that.
 var gFolderTreeView = null;
@@ -250,16 +256,19 @@ StandaloneMessageDisplayWidget.prototype
                              .getAttribute("titlemodifier");
 
     document.title = docTitle;
 
     this.isDummy = aMsgHdr.folder == null;
     if (!this.isDummy)
       this.displayedUri = null;
 
+    // Initialize the appmenu.
+    PanelUI.init();
+
     // We've loaded a message, so this should be set to false
     this.aboutToLoadMessage = false;
   },
 
   onSelectedMessagesChanged() {
     // When switching folders, we won't have any selection for a while.
     if (!this.folderDisplay.view.dbView)
       return true;
--- a/mail/base/content/messageWindow.xul
+++ b/mail/base/content/messageWindow.xul
@@ -9,16 +9,17 @@
 <?xml-stylesheet href="chrome://messenger/skin/messageWindow.css" type="text/css"?>
 <?xml-stylesheet href="chrome://messenger/skin/editContactPanel.css" type="text/css"?>
 <?xml-stylesheet href="chrome://messenger/skin/messageHeader.css" type="text/css"?>
 <?xml-stylesheet href="chrome://messenger/skin/folderMenus.css" type="text/css"?>
 <?xml-stylesheet href="chrome://messenger/skin/attachmentList.css" type="text/css"?>
 <?xml-stylesheet href="chrome://messenger/skin/smime/msgHdrViewSMIMEOverlay.css" type="text/css"?>
 <?xml-stylesheet href="chrome://messenger/skin/smime/msgReadSMIMEOverlay.css" type="text/css"?>
 <?xml-stylesheet href="chrome://messenger/skin/searchBox.css" type="text/css"?>
+<?xml-stylesheet href="chrome://messenger/skin/customizableui/panelUI.css" type="text/css"?>
 
 <!DOCTYPE window [
 <!ENTITY % brandDTD SYSTEM "chrome://branding/locale/brand.dtd" >
 %brandDTD;
 <!ENTITY % msgHdrViewOverlayDTD SYSTEM "chrome://messenger/locale/msgHdrViewOverlay.dtd">
 %msgHdrViewOverlayDTD;
 <!ENTITY % messengerDTD SYSTEM "chrome://messenger/locale/messenger.dtd" >
 %messengerDTD;
@@ -107,16 +108,18 @@
   <script src="chrome://messenger-newsblog/content/newsblogOverlay.js"/>
   <script src="chrome://messenger/content/mail-offline.js"/>
   <script src="chrome://global/content/printUtils.js"/>
   <script src="chrome://messenger/content/msgViewPickerOverlay.js"/>
   <script src="chrome://messenger/content/viewZoomOverlay.js"/>
   <script src="chrome://communicator/content/utilityOverlay.js"/>
   <script src="chrome://messenger/content/mailCore.js"/>
   <script src="chrome://messenger/content/quickFilterBar.js"/>
+  <!-- panelUI.js is for the appmenus. -->
+  <script src="chrome://messenger/content/customizableui/panelUI.js"/>
 #ifdef XP_MACOSX
   <script src="chrome://global/content/macWindowMenu.js"/>
 #endif
   <script src="chrome://messenger/content/newmailaccount/uriListener.js"/>
 
   <commandset id="mailCommands">
 #include mainCommandSet.inc.xul
     <commandset id="mailSearchMenuItems"/>
@@ -158,16 +161,20 @@
            modifiers="accel"/>
 #endif
     </keyset>
   </keyset>
 
   <!-- Popup menus provided by mailWindowOverlay.xul -->
   <popupset id="mainPopupSet">
 #include mainPopupSet.inc.xul
+
+<!-- The panelUI is for the appmenu. -->
+#include ../../components/customizableui/content/panelUI.inc.xul
+
 #include msgHdrPopup.inc.xul
   </popupset>
 #include editContactPanel.inc.xul
 
 #ifdef XP_MACOSX
   <vbox id="titlebar">
     <hbox id="titlebar-content">
       <spacer id="titlebar-spacer" flex="1"/>
--- a/mail/base/content/messenger.css
+++ b/mail/base/content/messenger.css
@@ -12,16 +12,18 @@
 :root {
   --lwt-additional-images: none;
   --lwt-background-alignment: right top;
   --lwt-background-tiling: no-repeat;
 
   --toolbar-bgcolor: var(--toolbar-non-lwt-bgcolor);
   --toolbar-bgimage: var(--toolbar-non-lwt-bgimage);
   --toolbar-color: var(--toolbar-non-lwt-textcolor);
+
+  --panelui-subview-transition-duration: 150ms;
 }
 
 /* message header widgets */
 .emailDisplayButton {
   -moz-user-focus: normal;
 }
 
 .emailStar {
@@ -39,20 +41,16 @@ mail-tagfield[collapsed="true"] {
 #searchTermList > richlistitem {
   -moz-binding: url("chrome://messenger/content/searchWidgets.xml#filterlistitem");
 }
 
 search-value {
   display: -moz-deck;
 }
 
-searchterm {
-  -moz-binding: url("chrome://messenger/content/mailWidgets.xml#searchterm");
-}
-
 .ruleaction {
   -moz-binding: url("chrome://messenger/content/searchWidgets.xml#ruleaction");
 }
 
 .ruleactiontype {
   -moz-binding: url("chrome://messenger/content/searchWidgets.xml#ruleactiontype-menulist");
 }
 
@@ -126,39 +124,16 @@ tabmail {
 #status-bar:-moz-lwtheme {
   background-repeat: no-repeat, var(--lwt-background-tiling);
   background-position: bottom right, var(--lwt-background-alignment);
   background-color: var(--lwt-accent-color);
   background-image: var(--lwt-header-image), var(--lwt-additional-images);
   color: var(--lwt-text-color);
 }
 
-/* AppButton support */
-
-splitmenu {
-  -moz-binding: url("chrome://messenger/content/mailWidgets.xml#splitmenu");
-}
-
-.splitmenu-menuitem {
-/*  -moz-binding: url("chrome://global/content/bindings/menu.xml#menuitem"); */
-  list-style-image: inherit;
-  -moz-image-region: inherit;
-}
-/*
-.splitmenu-menuitem[iconic="true"] {
-  -moz-binding: url("chrome://global/content/bindings/menu.xml#menuitem-iconic");
-}
-*/
-.splitmenu-menu > .menu-text,
-:-moz-any(.splitmenu-menu, .splitmenu-menuitem) > .menu-accel-container,
-#appmenu-editmenu > .menu-text,
-#appmenu-editmenu > .menu-accel-container {
-  display: none;
-}
-
 #titlebar {
   -moz-window-dragging: drag;
 }
 
 #messengerWindow:not([chromemargin]) > #titlebar {
   display: none;
 }
 
--- a/mail/base/content/messenger.xul
+++ b/mail/base/content/messenger.xul
@@ -17,16 +17,17 @@
 <?xml-stylesheet href="chrome://messenger/skin/chat.css" type="text/css"?>
 <?xml-stylesheet href="chrome://chat/skin/imtooltip.css" type="text/css"?>
 <?xml-stylesheet href="chrome://messenger/skin/messageHeader.css" type="text/css"?>
 <?xml-stylesheet href="chrome://messenger/skin/folderMenus.css" type="text/css"?>
 <?xml-stylesheet href="chrome://messenger/skin/attachmentList.css" type="text/css"?>
 <?xml-stylesheet href="chrome://messenger/skin/smime/msgHdrViewSMIMEOverlay.css" type="text/css"?>
 <?xml-stylesheet href="chrome://messenger/skin/smime/msgReadSMIMEOverlay.css" type="text/css"?>
 <?xml-stylesheet href="chrome://messenger/skin/searchBox.css" type="text/css"?>
+<?xml-stylesheet href="chrome://messenger/skin/customizableui/panelUI.css" type="text/css"?>
 
 <!DOCTYPE window [
 <!ENTITY % brandDTD SYSTEM "chrome://branding/locale/brand.dtd" >
 %brandDTD;
 <!ENTITY % chatDTD SYSTEM "chrome://messenger/locale/chat.dtd">
 %chatDTD;
 <!ENTITY % msgHdrViewOverlayDTD SYSTEM "chrome://messenger/locale/msgHdrViewOverlay.dtd">
 %msgHdrViewOverlayDTD;
@@ -149,16 +150,18 @@
 <script src="chrome://messenger/content/newmailaccount/uriListener.js"/>
 <script src="chrome://messenger/content/chat/chat-conversation-info.js"/>
 <script src="chrome://gloda/content/autocomplete-richlistitem.js"/>
 <script src="chrome://messenger/content/chat/chat-contact.js"/>
 <script src="chrome://messenger/content/chat/chat-group.js"/>
 <script src="chrome://messenger/content/chat/chat-imconv.js"/>
 <script src="chrome://messenger/content/tabbrowser-tab.js"/>
 <script src="chrome://messenger/content/chat/toolbarbutton-badge-button.js"/>
+<!-- panelUI.js is for the appmenus. -->
+<script src="chrome://messenger/content/customizableui/panelUI.js"/>
 #ifdef XP_MACOSX
 <script src="chrome://messenger/content/macMessengerMenu.js"/>
 <script src="chrome://global/content/macWindowMenu.js"/>
 #endif
 
 <!-- move needed functions into a single js file -->
 <script src="chrome://messenger/content/threadPane.js"/>
 
@@ -222,16 +225,20 @@
          modifiers="accel"/>
 #endif
   </keyset>
 </keyset>
 
 <!-- Popup menus provided by mailWindowOverlay.xul -->
 <popupset id="mainPopupSet">
 #include mainPopupSet.inc.xul
+
+<!-- The panelUI is for the appmenu. -->
+#include ../../components/customizableui/content/panelUI.inc.xul
+
 #include msgHdrPopup.inc.xul
   <panel type="glodacomplete-richlistbox"
          id="PopupGlodaAutocomplete"
          noautofocus="true" />
   <panel type="autocomplete"
          id="PopupAutoComplete"
          noautofocus="true"/>
 
@@ -806,11 +813,10 @@
       <!-- notificationbox will be added here lazily. -->
   </hbox>
   <statuspanel id="statusbar-display"/>
   <hbox id="status-bar" class="statusbar chromeclass-status">
 #include mainStatusbar.inc.xul
     <statusbarpanel id="unreadMessageCount"/>
     <statusbarpanel id="totalMessageCount"/>
   </hbox>
-
 </window>
 
--- a/mail/base/content/msgMail3PaneWindow.js
+++ b/mail/base/content/msgMail3PaneWindow.js
@@ -14,16 +14,17 @@
 /* import-globals-from glodaFacetTab.js */
 /* import-globals-from mailTabs.js */
 /* import-globals-from mailWindow.js */
 /* import-globals-from quickFilterBar.js */
 /* import-globals-from searchBar.js */
 /* import-globals-from searchBar.js */
 /* import-globals-from specialTabs.js */
 /* import-globals-from toolbarIconColor.js */
+/* globals PanelUI */
 
 ChromeUtils.import("resource:///modules/activity/activityModules.jsm");
 var { logException } = ChromeUtils.import("resource:///modules/errUtils.js");
 var {IOUtils} = ChromeUtils.import("resource:///modules/IOUtils.js");
 var { JSTreeSelection } = ChromeUtils.import("resource:///modules/jsTreeSelection.js");
 var {MailConsts} = ChromeUtils.import("resource:///modules/MailConsts.jsm");
 var {MailInstrumentation} = ChromeUtils.import("resource:///modules/MailInstrumentation.jsm");
 var {migrateMailnews} = ChromeUtils.import("resource:///modules/mailnewsMigrator.js");
@@ -35,16 +36,18 @@ var {Services} = ChromeUtils.import("res
 var {MailUtils} = ChromeUtils.import("resource:///modules/MailUtils.jsm");
 var {AppConstants} = ChromeUtils.import("resource://gre/modules/AppConstants.jsm");
 var {Color} = ChromeUtils.import("resource://gre/modules/Color.jsm");
 var {TagUtils} = ChromeUtils.import("resource:///modules/TagUtils.jsm");
 var {PeriodicFilterManager} = ChromeUtils.import("resource:///modules/PeriodicFilterManager.jsm");
 
 XPCOMUtils.defineLazyModuleGetters(this, {
   LightweightThemeManager: "resource://gre/modules/LightweightThemeManager.jsm",
+  CustomizableUI: "resource:///modules/CustomizableUI.jsm",
+  ShortcutUtils: "resource://gre/modules/ShortcutUtils.jsm",
 });
 
 XPCOMUtils.defineLazyGetter(this, "PopupNotifications", function() {
   let {PopupNotifications} = ChromeUtils.import("resource:///modules/GlobalPopupNotifications.jsm");
   try {
     // Hide all notifications while the URL is being edited and the address bar
     // has focus, including the virtual focus in the results popup.
     // We also have to hide notifications explicitly when the window is
@@ -529,16 +532,19 @@ function OnLoadMessenger() {
 
   // Set up the summary frame manager to handle loading pages in the
   // multi-message pane
   gSummaryFrameManager = new SummaryFrameManager(
                          document.getElementById("multimessage"));
 
   window.addEventListener("AppCommand", HandleAppCommandEvent, true);
 
+  // Set up the appmenus. (This has to happen after the DOM has loaded.)
+  PanelUI.init();
+
   // Load the periodic filter timer.
   PeriodicFilterManager.setupFiltering();
 }
 
 function LoadPostAccountWizard() {
   InitMsgWindow();
   messenger.setWindow(window, msgWindow);
 
--- a/mail/base/jar.mn
+++ b/mail/base/jar.mn
@@ -21,17 +21,16 @@ messenger.jar:
     content/messenger/messageWindow.js              (content/messageWindow.js)
     content/messenger/mailContextMenus.js           (content/mailContextMenus.js)
     content/messenger/nsContextMenu.js              (content/nsContextMenu.js)
 *   content/messenger/messenger.xul                 (content/messenger.xul)
 *   content/messenger/hiddenWindow.xul              (content/hiddenWindow.xul)
     content/messenger/hiddenWindow.js               (content/hiddenWindow.js)
     content/messenger/msgHdrView.js                 (content/msgHdrView.js)
     content/messenger/msgViewNavigation.js          (content/msgViewNavigation.js)
-    content/messenger/mailWidgets.xml               (content/mailWidgets.xml)
     content/messenger/mailWidgets.js                (content/mailWidgets.js)
     content/messenger/button-menu-button.js         (content/button-menu-button.js)
     content/messenger/toolbarbutton-menu-button.js  (content/toolbarbutton-menu-button.js)
     content/messenger/toolbarbutton-appmenu.js      (content/toolbarbutton-appmenu.js)
     content/messenger/customElements.js             (content/customElements.js)
     content/messenger/customizeToolbar.css          (../../common/src/customizeToolbar.css)
     content/messenger/customizeToolbar.js           (../../common/src/customizeToolbar.js)
 *   content/messenger/customizeToolbar.xul          (../../common/src/customizeToolbar.xul)
--- a/mail/components/customizableui/CustomizableUI.jsm
+++ b/mail/components/customizableui/CustomizableUI.jsm
@@ -816,16 +816,17 @@ var CustomizableUIInternal = {
         kid.id = aSpecialIDs.shift();
       }
       if (!aSpecialIDs.length) {
         return;
       }
     }
   },
 
+  // eslint-disable-next-line complexity
   buildArea(aArea, aPlacements, aAreaNode) {
     let document = aAreaNode.ownerDocument;
     let window = document.defaultView;
     let inPrivateWindow = PrivateBrowsingUtils.isWindowPrivate(window);
     let container = this.getCustomizationTarget(aAreaNode);
     let areaIsPanel = gAreas.get(aArea).get("type") == CustomizableUI.TYPE_MENU_PANEL;
 
     if (!container) {
@@ -4047,16 +4048,17 @@ function WidgetGroupWrapper(aWidget) {
   this.__defineSetter__("disabled", function(aValue) {
     aValue = !!aValue;
     aWidget.disabled = aValue;
     for (let [, instance] of aWidget.instances) {
       instance.disabled = aValue;
     }
   });
 
+  // eslint-disable-next-line func-names
   this.forWindow = function WidgetGroupWrapper_forWindow(aWindow) {
     let wrapperMap;
     if (!gSingleWrapperCache.has(aWindow)) {
       wrapperMap = new Map();
       gSingleWrapperCache.set(aWindow, wrapperMap);
     } else {
       wrapperMap = gSingleWrapperCache.get(aWindow);
     }
@@ -4157,16 +4159,17 @@ function WidgetSingleWrapper(aWidget, aN
  */
 // XXXunf Going to need to hook this up to some events to keep it all live.
 function XULWidgetGroupWrapper(aWidgetId) {
   this.isGroup = true;
   this.id = aWidgetId;
   this.type = "custom";
   this.provider = CustomizableUI.PROVIDER_XUL;
 
+  // eslint-disable-next-line func-names
   this.forWindow = function XULWidgetGroupWrapper_forWindow(aWindow) {
     let wrapperMap;
     if (!gSingleWrapperCache.has(aWindow)) {
       wrapperMap = new Map();
       gSingleWrapperCache.set(aWindow, wrapperMap);
     } else {
       wrapperMap = gSingleWrapperCache.get(aWindow);
     }
--- a/mail/components/customizableui/CustomizableWidgets.jsm
+++ b/mail/components/customizableui/CustomizableWidgets.jsm
@@ -7,23 +7,25 @@
 var EXPORTED_SYMBOLS = ["CustomizableWidgets"];
 
 const {CustomizableUI} = ChromeUtils.import("resource:///modules/CustomizableUI.jsm");
 const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
 const {XPCOMUtils} = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
 const {AppConstants} = ChromeUtils.import("resource://gre/modules/AppConstants.jsm");
 
 XPCOMUtils.defineLazyModuleGetters(this, {
-  PanelView: "resource:///modules/PanelMultiView.jsm",
+  // TODO appmenu - The usage of these commented-out modules is commented out below.
+  // Commenting them out here for eslint compliance.
+  // PanelView: "resource:///modules/PanelMultiView.jsm",
   RecentlyClosedTabsAndWindowsMenuUtils: "resource:///modules/sessionstore/RecentlyClosedTabsAndWindowsMenuUtils.jsm",
   ShortcutUtils: "resource://gre/modules/ShortcutUtils.jsm",
   CharsetMenu: "resource://gre/modules/CharsetMenu.jsm",
   PrivateBrowsingUtils: "resource://gre/modules/PrivateBrowsingUtils.jsm",
-  Sanitizer: "resource:///modules/Sanitizer.jsm",
-  SyncedTabs: "resource://services-sync/SyncedTabs.jsm",
+  // Sanitizer: "resource:///modules/Sanitizer.jsm",
+  // SyncedTabs: "resource://services-sync/SyncedTabs.jsm",
 });
 
 XPCOMUtils.defineLazyGetter(this, "CharsetBundle", function() {
   const kCharsetBundle = "chrome://global/locale/charsetMenu.properties";
   return Services.strings.createBundle(kCharsetBundle);
 });
 
 const kPrefCustomizationDebug = "browser.uiCustomization.debug";
@@ -499,247 +501,249 @@ const CustomizableWidgets = [
     id: "email-link-button",
     tooltiptext: "email-link-button.tooltiptext3",
     onCommand(aEvent) {
       let win = aEvent.view;
       win.MailIntegration.sendLinkForBrowser(win.gBrowser.selectedBrowser);
     },
   }];
 
-if (Services.prefs.getBoolPref("identity.fxaccounts.enabled")) {
-  CustomizableWidgets.push({
-    id: "sync-button",
-    label: "remotetabs-panelmenu.label",
-    tooltiptext: "remotetabs-panelmenu.tooltiptext2",
-    type: "view",
-    viewId: "PanelUI-remotetabs",
-    deckIndices: {
-      DECKINDEX_TABS: 0,
-      DECKINDEX_TABSDISABLED: 1,
-      DECKINDEX_FETCHING: 2,
-      DECKINDEX_NOCLIENTS: 3,
-    },
-    TABS_PER_PAGE: 25,
-    NEXT_PAGE_MIN_TABS: 5, // Minimum number of tabs displayed when we click "Show All"
-    onViewShowing(aEvent) {
-      let doc = aEvent.target.ownerDocument;
-      this._tabsList = doc.getElementById("PanelUI-remotetabs-tabslist");
-      Services.obs.addObserver(this, SyncedTabs.TOPIC_TABS_CHANGED);
+// TODO appmenu - This errors when _defineBuiltInWidgets runs in
+// CustomizableUI.jsm. (We aren't using Firefox accounts, so no problem.)
+// if (Services.prefs.getBoolPref("identity.fxaccounts.enabled")) {
+//   CustomizableWidgets.push({
+//     id: "sync-button",
+//     label: "remotetabs-panelmenu.label",
+//     tooltiptext: "remotetabs-panelmenu.tooltiptext2",
+//     type: "view",
+//     viewId: "PanelUI-remotetabs",
+//     deckIndices: {
+//       DECKINDEX_TABS: 0,
+//       DECKINDEX_TABSDISABLED: 1,
+//       DECKINDEX_FETCHING: 2,
+//       DECKINDEX_NOCLIENTS: 3,
+//     },
+//     TABS_PER_PAGE: 25,
+//     NEXT_PAGE_MIN_TABS: 5, // Minimum number of tabs displayed when we click "Show All"
+//     onViewShowing(aEvent) {
+//       let doc = aEvent.target.ownerDocument;
+//       this._tabsList = doc.getElementById("PanelUI-remotetabs-tabslist");
+//       Services.obs.addObserver(this, SyncedTabs.TOPIC_TABS_CHANGED);
 
-      if (SyncedTabs.isConfiguredToSyncTabs) {
-        if (SyncedTabs.hasSyncedThisSession) {
-          this.setDeckIndex(this.deckIndices.DECKINDEX_TABS);
-        } else {
-          // Sync hasn't synced tabs yet, so show the "fetching" panel.
-          this.setDeckIndex(this.deckIndices.DECKINDEX_FETCHING);
-        }
-        // force a background sync.
-        SyncedTabs.syncTabs().catch(ex => {
-          Cu.reportError(ex);
-        });
-        // show the current list - it will be updated by our observer.
-        this._showTabs();
-      } else {
-        // not configured to sync tabs, so no point updating the list.
-        this.setDeckIndex(this.deckIndices.DECKINDEX_TABSDISABLED);
-      }
-    },
-    onViewHiding() {
-      Services.obs.removeObserver(this, SyncedTabs.TOPIC_TABS_CHANGED);
-      this._tabsList = null;
-    },
-    _tabsList: null,
-    observe(subject, topic, data) {
-      switch (topic) {
-        case SyncedTabs.TOPIC_TABS_CHANGED:
-          this._showTabs();
-          break;
-        default:
-          break;
-      }
-    },
-    setDeckIndex(index) {
-      let deck = this._tabsList.ownerDocument.getElementById("PanelUI-remotetabs-deck");
-      // We call setAttribute instead of relying on the XBL property setter due
-      // to things going wrong when we try and set the index before the XBL
-      // binding has been created - see bug 1241851 for the gory details.
-      deck.setAttribute("selectedIndex", index);
-    },
+//       if (SyncedTabs.isConfiguredToSyncTabs) {
+//         if (SyncedTabs.hasSyncedThisSession) {
+//           this.setDeckIndex(this.deckIndices.DECKINDEX_TABS);
+//         } else {
+//           // Sync hasn't synced tabs yet, so show the "fetching" panel.
+//           this.setDeckIndex(this.deckIndices.DECKINDEX_FETCHING);
+//         }
+//         // force a background sync.
+//         SyncedTabs.syncTabs().catch(ex => {
+//           Cu.reportError(ex);
+//         });
+//         // show the current list - it will be updated by our observer.
+//         this._showTabs();
+//       } else {
+//         // not configured to sync tabs, so no point updating the list.
+//         this.setDeckIndex(this.deckIndices.DECKINDEX_TABSDISABLED);
+//       }
+//     },
+//     onViewHiding() {
+//       Services.obs.removeObserver(this, SyncedTabs.TOPIC_TABS_CHANGED);
+//       this._tabsList = null;
+//     },
+//     _tabsList: null,
+//     observe(subject, topic, data) {
+//       switch (topic) {
+//         case SyncedTabs.TOPIC_TABS_CHANGED:
+//           this._showTabs();
+//           break;
+//         default:
+//           break;
+//       }
+//     },
+//     setDeckIndex(index) {
+//       let deck = this._tabsList.ownerDocument.getElementById("PanelUI-remotetabs-deck");
+//       // We call setAttribute instead of relying on the XBL property setter due
+//       // to things going wrong when we try and set the index before the XBL
+//       // binding has been created - see bug 1241851 for the gory details.
+//       deck.setAttribute("selectedIndex", index);
+//     },
 
-    _showTabsPromise: Promise.resolve(),
-    // Update the tab list after any existing in-flight updates are complete.
-    _showTabs(paginationInfo) {
-      this._showTabsPromise = this._showTabsPromise.then(() => {
-        return this.__showTabs(paginationInfo);
-      }, e => {
-        Cu.reportError(e);
-      });
-    },
-    // Return a new promise to update the tab list.
-    __showTabs(paginationInfo) {
-      if (!this._tabsList) {
-        // Closed between the previous `this._showTabsPromise`
-        // resolving and now.
-        return undefined;
-      }
-      let doc = this._tabsList.ownerDocument;
-      return SyncedTabs.getTabClients().then(clients => {
-        // The view may have been hidden while the promise was resolving.
-        if (!this._tabsList) {
-          return;
-        }
-        if (clients.length === 0 && !SyncedTabs.hasSyncedThisSession) {
-          // the "fetching tabs" deck is being shown - let's leave it there.
-          // When that first sync completes we'll be notified and update.
-          return;
-        }
+//     _showTabsPromise: Promise.resolve(),
+//     // Update the tab list after any existing in-flight updates are complete.
+//     _showTabs(paginationInfo) {
+//       this._showTabsPromise = this._showTabsPromise.then(() => {
+//         return this.__showTabs(paginationInfo);
+//       }, e => {
+//         Cu.reportError(e);
+//       });
+//     },
+//     // Return a new promise to update the tab list.
+//     __showTabs(paginationInfo) {
+//       if (!this._tabsList) {
+//         // Closed between the previous `this._showTabsPromise`
+//         // resolving and now.
+//         return undefined;
+//       }
+//       let doc = this._tabsList.ownerDocument;
+//       return SyncedTabs.getTabClients().then(clients => {
+//         // The view may have been hidden while the promise was resolving.
+//         if (!this._tabsList) {
+//           return;
+//         }
+//         if (clients.length === 0 && !SyncedTabs.hasSyncedThisSession) {
+//           // the "fetching tabs" deck is being shown - let's leave it there.
+//           // When that first sync completes we'll be notified and update.
+//           return;
+//         }
 
-        if (clients.length === 0) {
-          this.setDeckIndex(this.deckIndices.DECKINDEX_NOCLIENTS);
-          return;
-        }
+//         if (clients.length === 0) {
+//           this.setDeckIndex(this.deckIndices.DECKINDEX_NOCLIENTS);
+//           return;
+//         }
 
-        this.setDeckIndex(this.deckIndices.DECKINDEX_TABS);
-        this._clearTabList();
-        SyncedTabs.sortTabClientsByLastUsed(clients);
-        let fragment = doc.createDocumentFragment();
+//         this.setDeckIndex(this.deckIndices.DECKINDEX_TABS);
+//         this._clearTabList();
+//         SyncedTabs.sortTabClientsByLastUsed(clients);
+//         let fragment = doc.createDocumentFragment();
 
-        for (let client of clients) {
-          // add a menu separator for all clients other than the first.
-          if (fragment.lastElementChild) {
-            let separator = doc.createXULElement("menuseparator");
-            fragment.appendChild(separator);
-          }
-          if (paginationInfo && paginationInfo.clientId == client.id) {
-            this._appendClient(client, fragment, paginationInfo.maxTabs);
-          } else {
-            this._appendClient(client, fragment);
-          }
-        }
-        this._tabsList.appendChild(fragment);
-        PanelView.forNode(this._tabsList.closest("panelview"))
-                 .descriptionHeightWorkaround();
-      }).catch(err => {
-        Cu.reportError(err);
-      }).then(() => {
-        // an observer for tests.
-        Services.obs.notifyObservers(null, "synced-tabs-menu:test:tabs-updated");
-      });
-    },
-    _clearTabList() {
-      let list = this._tabsList;
-      while (list.lastChild) {
-        list.lastChild.remove();
-      }
-    },
-    _showNoClientMessage() {
-      this._appendMessageLabel("notabslabel");
-    },
-    _appendMessageLabel(messageAttr, appendTo = null) {
-      if (!appendTo) {
-        appendTo = this._tabsList;
-      }
-      let message = this._tabsList.getAttribute(messageAttr);
-      let doc = this._tabsList.ownerDocument;
-      let messageLabel = doc.createXULElement("label");
-      messageLabel.textContent = message;
-      appendTo.appendChild(messageLabel);
-      return messageLabel;
-    },
-    _appendClient(client, attachFragment, maxTabs = this.TABS_PER_PAGE) {
-      let doc = attachFragment.ownerDocument;
-      // Create the element for the remote client.
-      let clientItem = doc.createXULElement("label");
-      clientItem.setAttribute("itemtype", "client");
-      let window = doc.defaultView;
-      clientItem.setAttribute("tooltiptext",
-        window.gSync.formatLastSyncDate(new Date(client.lastModified)));
-      clientItem.textContent = client.name;
+//         for (let client of clients) {
+//           // add a menu separator for all clients other than the first.
+//           if (fragment.lastElementChild) {
+//             let separator = doc.createXULElement("menuseparator");
+//             fragment.appendChild(separator);
+//           }
+//           if (paginationInfo && paginationInfo.clientId == client.id) {
+//             this._appendClient(client, fragment, paginationInfo.maxTabs);
+//           } else {
+//             this._appendClient(client, fragment);
+//           }
+//         }
+//         this._tabsList.appendChild(fragment);
+//         PanelView.forNode(this._tabsList.closest("panelview"))
+//                  .descriptionHeightWorkaround();
+//       }).catch(err => {
+//         Cu.reportError(err);
+//       }).then(() => {
+//         // an observer for tests.
+//         Services.obs.notifyObservers(null, "synced-tabs-menu:test:tabs-updated");
+//       });
+//     },
+//     _clearTabList() {
+//       let list = this._tabsList;
+//       while (list.lastChild) {
+//         list.lastChild.remove();
+//       }
+//     },
+//     _showNoClientMessage() {
+//       this._appendMessageLabel("notabslabel");
+//     },
+//     _appendMessageLabel(messageAttr, appendTo = null) {
+//       if (!appendTo) {
+//         appendTo = this._tabsList;
+//       }
+//       let message = this._tabsList.getAttribute(messageAttr);
+//       let doc = this._tabsList.ownerDocument;
+//       let messageLabel = doc.createXULElement("label");
+//       messageLabel.textContent = message;
+//       appendTo.appendChild(messageLabel);
+//       return messageLabel;
+//     },
+//     _appendClient(client, attachFragment, maxTabs = this.TABS_PER_PAGE) {
+//       let doc = attachFragment.ownerDocument;
+//       // Create the element for the remote client.
+//       let clientItem = doc.createXULElement("label");
+//       clientItem.setAttribute("itemtype", "client");
+//       let window = doc.defaultView;
+//       clientItem.setAttribute("tooltiptext",
+//         window.gSync.formatLastSyncDate(new Date(client.lastModified)));
+//       clientItem.textContent = client.name;
 
-      attachFragment.appendChild(clientItem);
+//       attachFragment.appendChild(clientItem);
 
-      if (client.tabs.length == 0) {
-        let label = this._appendMessageLabel("notabsforclientlabel", attachFragment);
-        label.setAttribute("class", "PanelUI-remotetabs-notabsforclient-label");
-      } else {
-        // If this page will display all tabs, show no additional buttons.
-        // If the next page will display all the remaining tabs, show a "Show All" button
-        // Otherwise, show a "Shore More" button
-        let hasNextPage = client.tabs.length > maxTabs;
-        let nextPageIsLastPage = hasNextPage && maxTabs + this.TABS_PER_PAGE >= client.tabs.length;
-        if (nextPageIsLastPage) {
-          // When the user clicks "Show All", try to have at least NEXT_PAGE_MIN_TABS more tabs
-          // to display in order to avoid user frustration
-          maxTabs = Math.min(client.tabs.length - this.NEXT_PAGE_MIN_TABS, maxTabs);
-        }
-        if (hasNextPage) {
-          client.tabs = client.tabs.slice(0, maxTabs);
-        }
-        for (let tab of client.tabs) {
-          let tabEnt = this._createTabElement(doc, tab);
-          attachFragment.appendChild(tabEnt);
-        }
-        if (hasNextPage) {
-          let showAllEnt = this._createShowMoreElement(doc, client.id,
-                                                       nextPageIsLastPage ?
-                                                       Infinity :
-                                                       maxTabs + this.TABS_PER_PAGE);
-          attachFragment.appendChild(showAllEnt);
-        }
-      }
-    },
-    _createTabElement(doc, tabInfo) {
-      let item = doc.createXULElement("toolbarbutton");
-      let tooltipText = (tabInfo.title ? tabInfo.title + "\n" : "") + tabInfo.url;
-      item.setAttribute("itemtype", "tab");
-      item.setAttribute("class", "subviewbutton");
-      item.setAttribute("targetURI", tabInfo.url);
-      item.setAttribute("label", tabInfo.title != "" ? tabInfo.title : tabInfo.url);
-      item.setAttribute("image", tabInfo.icon);
-      item.setAttribute("tooltiptext", tooltipText);
-      // We need to use "click" instead of "command" here so openUILink
-      // respects different buttons (eg, to open in a new tab).
-      item.addEventListener("click", e => {
-        doc.defaultView.openUILink(tabInfo.url, e, {
-          triggeringPrincipal: Services.scriptSecurityManager.createNullPrincipal({}),
-        });
-        if (doc.defaultView.whereToOpenLink(e) != "current") {
-          e.preventDefault();
-          e.stopPropagation();
-        } else {
-          CustomizableUI.hidePanelForNode(item);
-        }
-      });
-      return item;
-    },
-    _createShowMoreElement(doc, clientId, showCount) {
-      let labelAttr, tooltipAttr;
-      if (showCount === Infinity) {
-        labelAttr = "showAllLabel";
-        tooltipAttr = "showAllTooltipText";
-      } else {
-        labelAttr = "showMoreLabel";
-        tooltipAttr = "showMoreTooltipText";
-      }
-      let showAllItem = doc.createXULElement("toolbarbutton");
-      showAllItem.setAttribute("itemtype", "showmorebutton");
-      showAllItem.setAttribute("class", "subviewbutton");
-      let label = this._tabsList.getAttribute(labelAttr);
-      showAllItem.setAttribute("label", label);
-      let tooltipText = this._tabsList.getAttribute(tooltipAttr);
-      showAllItem.setAttribute("tooltiptext", tooltipText);
-      showAllItem.addEventListener("click", e => {
-        e.preventDefault();
-        e.stopPropagation();
-        this._showTabs({ clientId, maxTabs: showCount });
-      });
-      return showAllItem;
-    },
-  });
-}
+//       if (client.tabs.length == 0) {
+//         let label = this._appendMessageLabel("notabsforclientlabel", attachFragment);
+//         label.setAttribute("class", "PanelUI-remotetabs-notabsforclient-label");
+//       } else {
+//         // If this page will display all tabs, show no additional buttons.
+//         // If the next page will display all the remaining tabs, show a "Show All" button
+//         // Otherwise, show a "Shore More" button
+//         let hasNextPage = client.tabs.length > maxTabs;
+//         let nextPageIsLastPage = hasNextPage && maxTabs + this.TABS_PER_PAGE >= client.tabs.length;
+//         if (nextPageIsLastPage) {
+//           // When the user clicks "Show All", try to have at least NEXT_PAGE_MIN_TABS more tabs
+//           // to display in order to avoid user frustration
+//           maxTabs = Math.min(client.tabs.length - this.NEXT_PAGE_MIN_TABS, maxTabs);
+//         }
+//         if (hasNextPage) {
+//           client.tabs = client.tabs.slice(0, maxTabs);
+//         }
+//         for (let tab of client.tabs) {
+//           let tabEnt = this._createTabElement(doc, tab);
+//           attachFragment.appendChild(tabEnt);
+//         }
+//         if (hasNextPage) {
+//           let showAllEnt = this._createShowMoreElement(doc, client.id,
+//                                                        nextPageIsLastPage ?
+//                                                        Infinity :
+//                                                        maxTabs + this.TABS_PER_PAGE);
+//           attachFragment.appendChild(showAllEnt);
+//         }
+//       }
+//     },
+//     _createTabElement(doc, tabInfo) {
+//       let item = doc.createXULElement("toolbarbutton");
+//       let tooltipText = (tabInfo.title ? tabInfo.title + "\n" : "") + tabInfo.url;
+//       item.setAttribute("itemtype", "tab");
+//       item.setAttribute("class", "subviewbutton");
+//       item.setAttribute("targetURI", tabInfo.url);
+//       item.setAttribute("label", tabInfo.title != "" ? tabInfo.title : tabInfo.url);
+//       item.setAttribute("image", tabInfo.icon);
+//       item.setAttribute("tooltiptext", tooltipText);
+//       // We need to use "click" instead of "command" here so openUILink
+//       // respects different buttons (eg, to open in a new tab).
+//       item.addEventListener("click", e => {
+//         doc.defaultView.openUILink(tabInfo.url, e, {
+//           triggeringPrincipal: Services.scriptSecurityManager.createNullPrincipal({}),
+//         });
+//         if (doc.defaultView.whereToOpenLink(e) != "current") {
+//           e.preventDefault();
+//           e.stopPropagation();
+//         } else {
+//           CustomizableUI.hidePanelForNode(item);
+//         }
+//       });
+//       return item;
+//     },
+//     _createShowMoreElement(doc, clientId, showCount) {
+//       let labelAttr, tooltipAttr;
+//       if (showCount === Infinity) {
+//         labelAttr = "showAllLabel";
+//         tooltipAttr = "showAllTooltipText";
+//       } else {
+//         labelAttr = "showMoreLabel";
+//         tooltipAttr = "showMoreTooltipText";
+//       }
+//       let showAllItem = doc.createXULElement("toolbarbutton");
+//       showAllItem.setAttribute("itemtype", "showmorebutton");
+//       showAllItem.setAttribute("class", "subviewbutton");
+//       let label = this._tabsList.getAttribute(labelAttr);
+//       showAllItem.setAttribute("label", label);
+//       let tooltipText = this._tabsList.getAttribute(tooltipAttr);
+//       showAllItem.setAttribute("tooltiptext", tooltipText);
+//       showAllItem.addEventListener("click", e => {
+//         e.preventDefault();
+//         e.stopPropagation();
+//         this._showTabs({ clientId, maxTabs: showCount });
+//       });
+//       return showAllItem;
+//     },
+//   });
+// }
 
 let preferencesButton = {
   id: "preferences-button",
   onCommand(aEvent) {
     let win = aEvent.target.ownerGlobal;
     win.openPreferences(undefined);
   },
 };
@@ -749,110 +753,112 @@ if (AppConstants.platform == "win") {
 } else if (AppConstants.platform == "macosx") {
   preferencesButton.tooltiptext = "preferences-button.tooltiptext.withshortcut";
   preferencesButton.shortcutId = "key_preferencesCmdMac";
 } else {
   preferencesButton.tooltiptext = "preferences-button.tooltiptext2";
 }
 CustomizableWidgets.push(preferencesButton);
 
-if (Services.prefs.getBoolPref("privacy.panicButton.enabled")) {
-  CustomizableWidgets.push({
-    id: "panic-button",
-    type: "view",
-    viewId: "PanelUI-panicView",
+// TODO appmenu - This errors when _defineBuiltInWidgets runs in
+// CustomizableUI.jsm.
+// if (Services.prefs.getBoolPref("privacy.panicButton.enabled")) {
+//   CustomizableWidgets.push({
+//     id: "panic-button",
+//     type: "view",
+//     viewId: "PanelUI-panicView",
 
-    forgetButtonCalled(aEvent) {
-      let doc = aEvent.target.ownerDocument;
-      let group = doc.getElementById("PanelUI-panic-timeSpan");
-      let itemsToClear = [
-        "cookies", "history", "openWindows", "formdata", "sessions", "cache", "downloads", "offlineApps",
-      ];
-      let newWindowPrivateState = PrivateBrowsingUtils.isWindowPrivate(doc.defaultView) ?
-                                  "private" : "non-private";
-      let promise = Sanitizer.sanitize(itemsToClear, {
-        ignoreTimespan: false,
-        range: Sanitizer.getClearRange(+group.value),
-        privateStateForNewWindow: newWindowPrivateState,
-      });
-      promise.then(function() {
-        let otherWindow = Services.wm.getMostRecentWindow("navigator:browser");
-        if (otherWindow.closed) {
-          Cu.reportError("Got a closed window!");
-        }
-        if (otherWindow.PanicButtonNotifier) {
-          otherWindow.PanicButtonNotifier.notify();
-        } else {
-          otherWindow.PanicButtonNotifierShouldNotify = true;
-        }
-      });
-    },
-    handleEvent(aEvent) {
-      switch (aEvent.type) {
-        case "command":
-          this.forgetButtonCalled(aEvent);
-          break;
-      }
-    },
-    onViewShowing(aEvent) {
-      let win = aEvent.target.ownerGlobal;
-      let doc = win.document;
-      let eventBlocker = null;
-      if (!doc.querySelector("#PanelUI-panic-timeframe")) {
-        win.MozXULElement.insertFTLIfNeeded("browser/panicButton.ftl");
-        let frag = win.MozXULElement.parseXULToFragment(`
-          <vbox class="panel-subview-body">
-            <hbox id="PanelUI-panic-timeframe">
-              <image id="PanelUI-panic-timeframe-icon" alt=""/>
-              <vbox flex="1">
-                <description data-l10n-id="panic-main-timeframe-desc" id="PanelUI-panic-mainDesc"></description>
-                <radiogroup id="PanelUI-panic-timeSpan" aria-labelledby="PanelUI-panic-mainDesc" closemenu="none">
-                  <radio id="PanelUI-panic-5min" data-l10n-id="panic-button-5min" selected="true"
-                        value="5" class="subviewradio"/>
-                  <radio id="PanelUI-panic-2hr" data-l10n-id="panic-button-2hr"
-                        value="2" class="subviewradio"/>
-                  <radio id="PanelUI-panic-day" data-l10n-id="panic-button-day"
-                        value="6" class="subviewradio"/>
-                </radiogroup>
-              </vbox>
-            </hbox>
-            <vbox id="PanelUI-panic-explanations">
-              <label id="PanelUI-panic-actionlist-main-label" data-l10n-id="panic-button-action-desc"></label>
+//     forgetButtonCalled(aEvent) {
+//       let doc = aEvent.target.ownerDocument;
+//       let group = doc.getElementById("PanelUI-panic-timeSpan");
+//       let itemsToClear = [
+//         "cookies", "history", "openWindows", "formdata", "sessions", "cache", "downloads", "offlineApps",
+//       ];
+//       let newWindowPrivateState = PrivateBrowsingUtils.isWindowPrivate(doc.defaultView) ?
+//                                   "private" : "non-private";
+//       let promise = Sanitizer.sanitize(itemsToClear, {
+//         ignoreTimespan: false,
+//         range: Sanitizer.getClearRange(+group.value),
+//         privateStateForNewWindow: newWindowPrivateState,
+//       });
+//       promise.then(function() {
+//         let otherWindow = Services.wm.getMostRecentWindow("navigator:browser");
+//         if (otherWindow.closed) {
+//           Cu.reportError("Got a closed window!");
+//         }
+//         if (otherWindow.PanicButtonNotifier) {
+//           otherWindow.PanicButtonNotifier.notify();
+//         } else {
+//           otherWindow.PanicButtonNotifierShouldNotify = true;
+//         }
+//       });
+//     },
+//     handleEvent(aEvent) {
+//       switch (aEvent.type) {
+//         case "command":
+//           this.forgetButtonCalled(aEvent);
+//           break;
+//       }
+//     },
+//     onViewShowing(aEvent) {
+//       let win = aEvent.target.ownerGlobal;
+//       let doc = win.document;
+//       let eventBlocker = null;
+//       if (!doc.querySelector("#PanelUI-panic-timeframe")) {
+//         win.MozXULElement.insertFTLIfNeeded("browser/panicButton.ftl");
+//         let frag = win.MozXULElement.parseXULToFragment(`
+//           <vbox class="panel-subview-body">
+//             <hbox id="PanelUI-panic-timeframe">
+//               <image id="PanelUI-panic-timeframe-icon" alt=""/>
+//               <vbox flex="1">
+//                 <description data-l10n-id="panic-main-timeframe-desc" id="PanelUI-panic-mainDesc"></description>
+//                 <radiogroup id="PanelUI-panic-timeSpan" aria-labelledby="PanelUI-panic-mainDesc" closemenu="none">
+//                   <radio id="PanelUI-panic-5min" data-l10n-id="panic-button-5min" selected="true"
+//                         value="5" class="subviewradio"/>
+//                   <radio id="PanelUI-panic-2hr" data-l10n-id="panic-button-2hr"
+//                         value="2" class="subviewradio"/>
+//                   <radio id="PanelUI-panic-day" data-l10n-id="panic-button-day"
+//                         value="6" class="subviewradio"/>
+//                 </radiogroup>
+//               </vbox>
+//             </hbox>
+//             <vbox id="PanelUI-panic-explanations">
+//               <label id="PanelUI-panic-actionlist-main-label" data-l10n-id="panic-button-action-desc"></label>
 
-              <label id="PanelUI-panic-actionlist-windows" class="PanelUI-panic-actionlist" data-l10n-id="panic-button-delete-tabs-and-windows"></label>
-              <label id="PanelUI-panic-actionlist-cookies" class="PanelUI-panic-actionlist" data-l10n-id="panic-button-delete-cookies"></label>
-              <label id="PanelUI-panic-actionlist-history" class="PanelUI-panic-actionlist" data-l10n-id="panic-button-delete-history"></label>
-              <label id="PanelUI-panic-actionlist-newwindow" class="PanelUI-panic-actionlist" data-l10n-id="panic-button-open-new-window"></label>
+//               <label id="PanelUI-panic-actionlist-windows" class="PanelUI-panic-actionlist" data-l10n-id="panic-button-delete-tabs-and-windows"></label>
+//               <label id="PanelUI-panic-actionlist-cookies" class="PanelUI-panic-actionlist" data-l10n-id="panic-button-delete-cookies"></label>
+//               <label id="PanelUI-panic-actionlist-history" class="PanelUI-panic-actionlist" data-l10n-id="panic-button-delete-history"></label>
+//               <label id="PanelUI-panic-actionlist-newwindow" class="PanelUI-panic-actionlist" data-l10n-id="panic-button-open-new-window"></label>
 
-              <label id="PanelUI-panic-warning" data-l10n-id="panic-button-undo-warning"></label>
-            </vbox>
-            <button id="PanelUI-panic-view-button"
-                    data-l10n-id="panic-button-forget-button"/>
-          </vbox>
-        `);
+//               <label id="PanelUI-panic-warning" data-l10n-id="panic-button-undo-warning"></label>
+//             </vbox>
+//             <button id="PanelUI-panic-view-button"
+//                     data-l10n-id="panic-button-forget-button"/>
+//           </vbox>
+//         `);
 
-        aEvent.target.appendChild(frag);
-        eventBlocker = doc.l10n.translateElements([aEvent.target]);
-      }
+//         aEvent.target.appendChild(frag);
+//         eventBlocker = doc.l10n.translateElements([aEvent.target]);
+//       }
 
-      let forgetButton = aEvent.target.querySelector("#PanelUI-panic-view-button");
-      let group = doc.getElementById("PanelUI-panic-timeSpan");
-      group.selectedItem = doc.getElementById("PanelUI-panic-5min");
-      forgetButton.addEventListener("command", this);
+//       let forgetButton = aEvent.target.querySelector("#PanelUI-panic-view-button");
+//       let group = doc.getElementById("PanelUI-panic-timeSpan");
+//       group.selectedItem = doc.getElementById("PanelUI-panic-5min");
+//       forgetButton.addEventListener("command", this);
 
-      if (eventBlocker) {
-        aEvent.detail.addBlocker(eventBlocker);
-      }
-    },
-    onViewHiding(aEvent) {
-      let forgetButton = aEvent.target.querySelector("#PanelUI-panic-view-button");
-      forgetButton.removeEventListener("command", this);
-    },
-  });
-}
+//       if (eventBlocker) {
+//         aEvent.detail.addBlocker(eventBlocker);
+//       }
+//     },
+//     onViewHiding(aEvent) {
+//       let forgetButton = aEvent.target.querySelector("#PanelUI-panic-view-button");
+//       forgetButton.removeEventListener("command", this);
+//     },
+//   });
+// }
 
 if (PrivateBrowsingUtils.enabled) {
   CustomizableWidgets.push({
     id: "privatebrowsing-button",
     shortcutId: "key_privatebrowsing",
     onCommand(e) {
       let win = e.target.ownerGlobal;
       win.OpenBrowserWindow({private: true});
--- a/mail/components/customizableui/PanelMultiView.jsm
+++ b/mail/components/customizableui/PanelMultiView.jsm
@@ -99,25 +99,28 @@
 
 "use strict";
 
 var EXPORTED_SYMBOLS = [
   "PanelMultiView",
   "PanelView",
 ];
 
-const {XPCOMUtils} = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
+// TODO appmenu - Usage is commented out below.  Keep eslint happy.
+// const {XPCOMUtils} = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
 const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
+
 ChromeUtils.defineModuleGetter(this, "CustomizableUI",
   "resource:///modules/CustomizableUI.jsm");
 
-XPCOMUtils.defineLazyGetter(this, "gBundle", function() {
-  return Services.strings.createBundle(
-    "chrome://browser/locale/browser.properties");
-});
+// TODO appmenu - Needs updating for Thunderbird. Usage is commented out below.
+// XPCOMUtils.defineLazyGetter(this, "gBundle", function() {
+//   return Services.strings.createBundle(
+//     "chrome://browser/locale/browser.properties");
+// });
 
 /**
  * Safety timeout after which asynchronous events will be canceled if any of the
  * registered blockers does not return.
  */
 const BLOCKERS_TIMEOUT_MS = 10000;
 
 const TRANSITION_PHASES = Object.freeze({
@@ -717,19 +720,21 @@ var PanelMultiView = class extends Assoc
     let nextPanelView = this.openViews[this.openViews.length - 2];
 
     // Like in the showSubView method, do not re-enter navigation while it is
     // in progress, and make the view inactive immediately. From this point
     // onwards, "await" statements can be used safely.
     if (!prevPanelView.active) {
       return;
     }
+
     prevPanelView.active = false;
 
     prevPanelView.captureKnownSize();
+
     await this._transitionViews(prevPanelView.node, nextPanelView.node, true);
 
     this._closeLatestView();
 
     this._activateView(nextPanelView);
   }
 
   /**
@@ -972,18 +977,21 @@ var PanelMultiView = class extends Assoc
     if (!nextPanelView.isOpenIn(this)) {
       return;
     }
 
     // Now set the viewContainer dimensions to that of the new view, which
     // kicks of the height animation.
     this._viewContainer.style.height = viewRect.height + "px";
     this._viewContainer.style.width = viewRect.width + "px";
-    this._panel.removeAttribute("width");
+
+    // TODO appmenu - Removing the width here causes a double-wide panel flicker.
+    // this._panel.removeAttribute("width");
     this._panel.removeAttribute("height");
+
     // We're setting the width property to prevent flickering during the
     // sliding animation with smaller views.
     viewNode.style.width = viewRect.width + "px";
 
     // Kick off the transition!
     details.phase = TRANSITION_PHASES.TRANSITION;
     this._viewStack.style.transform = "translateX(" + (moveToLeft ? "" : "-") + deltaX + "px)";
 
@@ -1268,18 +1276,22 @@ var PanelView = class extends Associated
     header = this.document.createXULElement("box");
     header.classList.add("panel-header");
 
     let backButton = this.document.createXULElement("toolbarbutton");
     backButton.className =
       "subviewbutton subviewbutton-iconic subviewbutton-back";
     backButton.setAttribute("closemenu", "none");
     backButton.setAttribute("tabindex", "0");
-    backButton.setAttribute("aria-label",
-      gBundle.GetStringFromName("panel.back"));
+
+    // TODO appmenu gBundle.GetStringFromName is undefined call
+    // Possible string addition/change.
+    // backButton.setAttribute("aria-label",
+    //   gBundle.GetStringFromName("panel.back"));
+
     backButton.addEventListener("command", () => {
       // The panelmultiview element may change if the view is reused.
       this.node.panelMultiView.goBack();
       backButton.blur();
     });
 
     let label = this.document.createXULElement("label");
     label.setAttribute("value", value);
@@ -1557,16 +1569,17 @@ var PanelView = class extends Associated
    *  - The Right key functions the same as the Enter key, simulating a click
    *  - The Left key triggers a navigation back to the previous view.
    *
    * Key navigation is only enabled while the view is active, meaning that this
    * method will return early if it is invoked during a sliding transition.
    *
    * @param {KeyEvent} event
    */
+  /* eslint-disable-next-line complexity */
   keyNavigation(event) {
     if (!this.active) {
       return;
     }
 
     let focus = this.document.activeElement;
     // Make sure the focus is actually inside the panel. (It might not be if
     // the panel was opened with the mouse.) If it isn't, we don't care
--- a/mail/components/customizableui/content/jar.mn
+++ b/mail/components/customizableui/content/jar.mn
@@ -1,6 +1,6 @@
 # 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/.
 
-browser.jar:
-  content/browser/customizableui/panelUI.js
+messenger.jar:
+  content/messenger/customizableui/panelUI.js
--- a/mail/components/customizableui/content/panelUI.inc.xul
+++ b/mail/components/customizableui/content/panelUI.inc.xul
@@ -14,84 +14,24 @@
                context="toolbar-context-menu">
       <vbox class="panel-subview-body">
         <vbox id="widget-overflow-list" class="widget-overflow-list"
               overflowfortoolbar="nav-bar"/>
         <toolbarseparator id="widget-overflow-fixed-separator" hidden="true"/>
         <vbox id="widget-overflow-fixed-list" class="widget-overflow-list" hidden="true" />
       </vbox>
       <toolbarbutton command="cmd_CustomizeToolbars"
-                      id="overflowMenu-customize-button"
-                      class="subviewbutton panel-subview-footer"
-                      accesskey="&overflowCustomizeToolbar.accesskey;"
-                      label="&overflowCustomizeToolbar.label;"/>
+                     id="overflowMenu-customize-button"
+                     class="subviewbutton panel-subview-footer"/>
+                     <!-- TODO appmenu
+                     accesskey="overflowCustomizeToolbar.accesskey;"
+                     label="overflowCustomizeToolbar.label;"/>
+                     -->
     </panelview>
   </panelmultiview>
-  <!-- This menu is here because not having it in the menu in which it's used flickers
-       when hover styles overlap. See https://bugzilla.mozilla.org/show_bug.cgi?id=1378427 .
-       -->
-  <menupopup id="customizationPanelItemContextMenu"
-             onpopupshowing="gCustomizeMode.onPanelContextMenuShowing(event); ToolbarContextMenu.updateExtension(this)">
-    <menuitem oncommand="ToolbarContextMenu.openAboutAddonsForContextAction(this.parentElement)"
-              accesskey="&customizeMenu.manageExtension.accesskey;"
-              label="&customizeMenu.manageExtension.label;"
-              contexttype="toolbaritem"
-              class="customize-context-manageExtension"/>
-    <menuitem oncommand="ToolbarContextMenu.removeExtensionForContextAction(this.parentElement)"
-              accesskey="&customizeMenu.removeExtension.accesskey;"
-              label="&customizeMenu.removeExtension.label;"
-              contexttype="toolbaritem"
-              class="customize-context-removeExtension"/>
-    <menuitem oncommand="ToolbarContextMenu.reportExtensionForContextAction(this.parentElement, 'toolbar_context_menu')"
-              accesskey="&customizeMenu.reportExtension.accesskey;"
-              label="&customizeMenu.reportExtension.label;"
-              contexttype="toolbaritem"
-              class="customize-context-reportExtension"/>
-    <menuseparator/>
-    <menuitem oncommand="gCustomizeMode.addToPanel(document.popupNode)"
-              id="customizationPanelItemContextMenuPin"
-              accesskey="&customizeMenu.pinToOverflowMenu.accesskey;"
-              label="&customizeMenu.pinToOverflowMenu.label;"
-              closemenu="single"
-              class="customize-context-moveToPanel"/>
-    <menuitem oncommand="gCustomizeMode.addToToolbar(document.popupNode)"
-              id="customizationPanelItemContextMenuUnpin"
-              closemenu="single"
-              class="customize-context-moveToToolbar"
-              accesskey="&customizeMenu.unpinFromOverflowMenu.accesskey;"
-              label="&customizeMenu.unpinFromOverflowMenu.label;"/>
-    <menuitem oncommand="gCustomizeMode.removeFromArea(document.popupNode)"
-              closemenu="single"
-              class="customize-context-removeFromPanel"
-              accesskey="&customizeMenu.removeFromToolbar.accesskey;"
-              label="&customizeMenu.removeFromToolbar.label;"/>
-    <menuseparator/>
-    <menuitem command="cmd_CustomizeToolbars"
-              class="viewCustomizeToolbar"
-              accesskey="&viewCustomizeToolbar.accesskey;"
-              label="&viewCustomizeToolbar.label;"/>
-  </menupopup>
-</panel>
-
-<panel id="panic-button-success-notification"
-       type="arrow"
-       position="bottomcenter topright"
-       hidden="true"
-       role="alert"
-       orient="vertical">
-  <hbox id="panic-button-success-header">
-    <image id="panic-button-success-icon" alt=""/>
-    <vbox>
-      <description>&panicButton.thankyou.msg1;</description>
-      <description>&panicButton.thankyou.msg2;</description>
-    </vbox>
-  </hbox>
-  <button label="&panicButton.thankyou.buttonlabel;"
-          id="panic-button-success-closebutton"
-          oncommand="PanicButtonNotifier.close()"/>
 </panel>
 
 <panel id="appMenu-notification-popup"
        class="popup-notification-panel"
        type="arrow"
        position="after_start"
        hidden="true"
        flip="slide"
@@ -125,30 +65,16 @@
                      buttonhighlight="true"
                      hidden="true">
     <popupnotificationcontent id="update-manual-notification-content" orient="vertical">
       <description id="update-manual-description" data-lazy-l10n-id="appmenu-update-manual-message"></description>
       <label id="update-manual-whats-new" is="text-link"  data-lazy-l10n-id="appmenu-update-whats-new"/>
     </popupnotificationcontent>
   </popupnotification>
 
-  <popupnotification id="appMenu-update-unsupported-notification"
-                     popupid="update-unsupported"
-                     data-lazy-l10n-id="appmenu-update-unsupported"
-                     data-l10n-attrs="buttonlabel, buttonaccesskey, secondarybuttonlabel, secondarybuttonaccesskey"
-                     closebuttonhidden="true"
-                     dropmarkerhidden="true"
-                     checkboxhidden="true"
-                     buttonhighlight="true"
-                     hidden="true">
-    <popupnotificationcontent id="update-unsupported-notification-content" orient="vertical">
-      <description id="update-unsupported-description" data-lazy-l10n-id="appmenu-update-unsupported-message"></description>
-    </popupnotificationcontent>
-  </popupnotification>
-
   <popupnotification id="appMenu-update-restart-notification"
                      popupid="update-restart"
                      data-lazy-l10n-id="appmenu-update-restart"
                      data-l10n-attrs="buttonlabel, buttonaccesskey, secondarybuttonlabel, secondarybuttonaccesskey"
                      closebuttonhidden="true"
                      dropmarkerhidden="true"
                      checkboxhidden="true"
                      buttonhighlight="true"
@@ -191,683 +117,1772 @@
     <popupnotificationcontent class="addon-private-browsing-notification-content" orient="vertical">
       <description id="addon-private-browsing-description" data-lazy-l10n-id="appmenu-addon-private-browsing-message"></description>
       <label id="addon-private-browsing-learn-more"
              class="text-link" is="text-link" data-lazy-l10n-id="appmenu-addon-private-browsing-learn-more"></label>
     </popupnotificationcontent>
   </popupnotification>
 </panel>
 
-<menupopup id="customizationPaletteItemContextMenu"
-           onpopupshowing="gCustomizeMode.onPaletteContextMenuShowing(event)">
-  <menuitem oncommand="gCustomizeMode.addToToolbar(document.popupNode)"
-            class="customize-context-addToToolbar"
-            accesskey="&customizeMenu.addToToolbar.accesskey;"
-            label="&customizeMenu.addToToolbar.label;"/>
-  <menuitem oncommand="gCustomizeMode.addToPanel(document.popupNode)"
-            class="customize-context-addToPanel"
-            accesskey="&customizeMenu.addToOverflowMenu.accesskey;"
-            label="&customizeMenu.addToOverflowMenu.label;"/>
-</menupopup>
-
-<menupopup id="customizationPanelContextMenu">
-  <menuitem command="cmd_CustomizeToolbars"
-            accesskey="&customizeMenu.addMoreItems.accesskey;"
-            label="&customizeMenu.addMoreItems.label;"/>
-</menupopup>
-
 <panel id="appMenu-popup"
        class="cui-widget-panel"
        role="group"
        type="arrow"
        hidden="true"
        flip="slide"
        position="bottomcenter topright"
        noautofocus="true">
-  <panelmultiview id="appMenu-multiView" mainViewId="appMenu-mainView"
+  <panelmultiview id="appMenu-multiView"
+                  mainViewId="appMenu-mainView"
                   viewCacheId="appMenu-viewCache">
+
+    <!-- Main Appmenu View -->
     <panelview id="appMenu-mainView" class="PanelUI-subView"
                descriptionheightworkaround="true">
       <vbox class="panel-subview-body">
         <vbox id="appMenu-addon-banners"/>
-        <toolbarbutton class="panel-banner-item"
-                       label-update-available="&updateAvailable.panelUI.label;"
-                       label-update-manual="&updateManual.panelUI.label;"
-                       label-update-unsupported="&updateUnsupported.panelUI.label;"
-                       label-update-restart="&updateRestart.panelUI.label2;"
-                       oncommand="PanelUI._onBannerItemSelected(event)"
-                       wrap="true"
-                       hidden="true"/>
-        <toolbaritem id="appMenu-fxa-container" class="toolbaritem-combined-buttons sync-ui-item">
-          <hbox id="appMenu-fxa-status"
-                flex="1"
-                defaultlabel="&fxaSignIn.label;"
-# Despite the name, the tooltip says "Open Sync Preferences" and it is only used when *not* signed in.
-# Bug 1542334 changed the behaviour of the item when signed in so the tooltip was no longer appropriate there.
-                tooltiptext="&fxaSignedIn.tooltip;"
-                errorlabel="&fxaSignInError.label;"
-                unverifiedlabel="&fxaUnverified.label;"
-                onclick="if (event.which == 1) gSync.onMenuPanelCommand();">
-            <image id="appMenu-fxa-avatar"/>
-            <toolbarbutton id="appMenu-fxa-label"
-                class="subviewbutton subviewbutton-iconic"
-                label="&fxaSignIn.label;"
-                fxabrandname="&syncBrand.fxAccount.label;"
-                closemenu="none"/>
-          </hbox>
-        </toolbaritem>
-        <toolbarseparator class="sync-ui-item"/>
-        <toolbaritem>
-          <toolbarbutton id="appMenu-tp-button"
-               class="subviewbutton subviewbutton-iconic"
-               oncommand="ContentBlocking.openPreferences('appMenu-trackingprotection');">
-            <image id="appMenu-tp-icon" class="toolbarbutton-icon"/>
-            <label id="appMenu-tp-label" class="toolbarbutton-text"/>
-            <label id="appMenu-tp-category"/>
-          </toolbarbutton>
-        </toolbaritem>
-        <toolbarseparator id="appMenu-tp-separator"/>
-        <toolbarbutton id="appMenu-new-window-button"
-                       class="subviewbutton subviewbutton-iconic"
-                       label="&newNavigatorCmd.label;"
-                       key="key_newNavigator"
-                       command="cmd_newNavigator"/>
-        <toolbarbutton id="appMenu-private-window-button"
-                       class="subviewbutton subviewbutton-iconic"
-                       label="&newPrivateWindow.label;"
-                       key="key_privatebrowsing"
-                       command="Tools:PrivateBrowsing"/>
-        <toolbarbutton id="appMenuRestoreLastSession"
-                       label="&appMenuHistory.restoreSession.label;"
-                       class="subviewbutton subviewbutton-iconic"
-                       command="Browser:RestoreLastSession"/>
+        <toolbarbutton id="appmenu_new"
+                       class="subviewbutton subviewbutton-nav"
+                       label="&newMenu.label;"
+                       closemenu="none"
+                       oncommand="PanelUI.showSubView('appMenu-newView', this)"/>
+        <toolbarbutton id="appmenu_msgAttachmentMenu"
+                       class="subviewbutton subviewbutton-nav"
+                       label="&openAttachmentListCmd.label;"
+                       disabled="true"
+                       closemenu="none"
+                       oncommand="PanelUI.showSubView('appMenu-attachmentsView', this)"/>
         <toolbarseparator/>
-        <toolbaritem id="appMenu-zoom-controls" class="toolbaritem-combined-buttons" closemenu="none">
+        <toolbaritem id="appmenu-edit-controls"
+                     class="toolbaritem-combined-buttons"
+                     closemenu="none">
           <!-- Use a spacer, because panel sizing code gets confused when using CSS methods. -->
           <spacer class="before-label"/>
-          <label value="&fullZoom.label;"/>
+          <label value="&appmenuEditMenu.label;"/>
           <!-- This spacer keeps the scrollbar from overlapping the view. -->
           <spacer class="after-label"/>
-          <toolbarbutton id="appMenu-zoomReduce-button"
-                         class="subviewbutton subviewbutton-iconic"
-                         command="cmd_fullZoomReduce"
-                         tooltip="dynamic-shortcut-tooltip"/>
-          <toolbarbutton id="appMenu-zoomReset-button"
-                         class="subviewbutton"
-                         command="cmd_fullZoomReset"
-                         tooltip="dynamic-shortcut-tooltip"/>
-          <toolbarbutton id="appMenu-zoomEnlarge-button"
-                         class="subviewbutton subviewbutton-iconic"
-                         command="cmd_fullZoomEnlarge"
-                         tooltip="dynamic-shortcut-tooltip"/>
-          <toolbarseparator orient="vertical"/>
-          <toolbarbutton id="appMenu-fullscreen-button"
-                         class="subviewbutton subviewbutton-iconic"
-                         observes="View:FullScreen"
-                         type="checkbox"
-                         closemenu="auto"
-                         onclick="if (event.button == 0) this.closest('panel').hidePopup();"
-                         tooltip="dynamic-shortcut-tooltip"/>
-        </toolbaritem>
-        <toolbarseparator/>
-        <toolbaritem id="appMenu-edit-controls" class="toolbaritem-combined-buttons" closemenu="none">
-          <!-- Use a spacer, because panel sizing code gets confused when using CSS methods. -->
-          <spacer class="before-label"/>
-          <label value="&editMenu.label;"/>
-          <!-- This spacer keeps the scrollbar from overlapping the view. -->
-          <spacer class="after-label"/>
-          <toolbarbutton id="appMenu-cut-button"
+
+          <toolbarbutton id="appmenu-cut"
                          class="subviewbutton subviewbutton-iconic"
                          command="cmd_cut"
                          tooltip="dynamic-shortcut-tooltip"/>
-          <toolbarbutton id="appMenu-copy-button"
+          <toolbarbutton id="appmenu-copy"
                          class="subviewbutton subviewbutton-iconic"
                          command="cmd_copy"
                          tooltip="dynamic-shortcut-tooltip"/>
-          <toolbarbutton id="appMenu-paste-button"
+          <toolbarbutton id="appmenu-paste"
                          class="subviewbutton subviewbutton-iconic"
                          command="cmd_paste"
                          tooltip="dynamic-shortcut-tooltip"/>
+          <toolbarseparator orient="vertical"/>
+          <toolbarbutton id="appmenu-edit-button"
+                         class="subviewbutton subviewbutton-nav"
+                         closemenu="none"
+                         oncommand="PanelUI.showSubView('appMenu-editView', this)"/>
         </toolbaritem>
         <toolbarseparator/>
-        <toolbarbutton id="appMenu-library-button"
+
+        <toolbarbutton id="appmenu_find"
+                       class="subviewbutton subviewbutton-nav subviewbutton-iconic"
+                       label="&findMenu.label;"
+                       closemenu="none"
+                       oncommand="PanelUI.showSubView('appMenu-findView', this)"/>
+        <toolbarbutton id="appmenu_print"
+                       class="subviewbutton subviewbutton-nav subviewbutton-iconic"
+                       label="&printButton.label;"
+                       closemenu="none"
+                       oncommand="PanelUI.showSubView('appMenu-printView', this)"/>
+        <toolbarbutton id="appmenu_saveAs"
+                       class="subviewbutton subviewbutton-nav"
+                       label="&saveAsMenu.label;"
+                       closemenu="none"
+                       oncommand="PanelUI.showSubView('appMenu-saveAsView', this)"/>
+        <toolbarbutton id="appmenu_emptyTrash"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&emptyTrashCmd.label;"
+                       command="cmd_emptyTrash"/>
+        <toolbarseparator/>
+        <toolbarbutton id="appmenu_activityManager"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&activitymanager.label;"
+                       oncommand="openActivityMgr();"/>
+        <toolbarbutton id="appmenu_filters"
+                       class="subviewbutton subviewbutton-nav"
+                       label="&filtersCmd2.label;"
+                       closemenu="none"
+                       oncommand="PanelUI.showSubView('appMenu-filtersView', this)"/>
+        <toolbarbutton id="appmenu_addons"
                        class="subviewbutton subviewbutton-iconic subviewbutton-nav"
-                       label="&places.library.title;"
+                       label="&addons.label;"
+                       closemenu="none"
+                       oncommand="PanelUI.showSubView('appMenu-addonsView', this)"/>
+        <toolbarbutton id="appmenu_customize"
+                       class="subviewbutton subviewbutton-nav"
+#ifdef XP_WIN
+                       label="&preferencesCmd2.label;"
+#else
+                       label="&preferencesCmdUnix.label;"
+#endif
+                       closemenu="none"
+                       oncommand="PanelUI.showSubView('appMenu-preferencesView', this)"/>
+        <toolbarseparator/>
+        <toolbarbutton id="appmenu_File"
+                       class="subviewbutton subviewbutton-nav"
+                       label="&fileMenu.label;"
+                       closemenu="none"
+                       oncommand="PanelUI.showSubView('appMenu-fileView', this)"/>
+        <toolbarbutton id="appmenu_View"
+                       class="subviewbutton subviewbutton-nav"
+                       label="&viewMenu.label;"
+                       closemenu="none"
+                       oncommand="PanelUI.showSubView('appMenu-viewView', this)"/>
+        <toolbarbutton id="appmenu_Go"
+                       class="subviewbutton subviewbutton-nav"
+                       label="&goMenu.label;"
+                       closemenu="none"
+                       oncommand="PanelUI.showSubView('appMenu-goView', this)"/>
+        <toolbarbutton id="appmenu_messageMenu"
+                       class="subviewbutton subviewbutton-nav"
+                       label="&msgMenu.label;"
+                       closemenu="none"
+                       oncommand="PanelUI.showSubView('appMenu-messageView', this)"/>
+        <toolbarbutton id="appmenu_tasksMenu"
+                       class="subviewbutton subviewbutton-nav"
+                       label="&tasksMenu.label;"
+                       closemenu="none"
+                       oncommand="PanelUI.showSubView('appMenu-toolsView', this)"/>
+        <toolbarbutton id="appmenu_help"
+                       class="subviewbutton subviewbutton-nav"
+                       label="&helpMenuWin.label;"
                        closemenu="none"
-                       oncommand="PanelUI.showSubView('appMenu-libraryView', this)"/>
-        <toolbarbutton id="appMenu-logins-button"
+                       oncommand="PanelUI.showSubView('appMenu-helpView', this)"/>
+
+        <toolbarseparator/>
+        <toolbarbutton id="appmenu-quit"
+                       class="subviewbutton subviewbutton-iconic"
+#ifdef XP_WIN
+                       label="&quitApplicationCmd.label;"
+#else
+                       label="&quitApplicationCmdUnix.label;"
+#endif
+                       command="cmd_quit"/>
+      </vbox>
+    </panelview>
+
+    <!-- New -->
+    <panelview id="appMenu-newView"
+               title="&newMenu.label;"
+               class="PanelUI-subView">
+      <vbox class="panel-subview-body">
+        <toolbarbutton id="appmenu_newNewMsgCmd"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&newNewMsgCmd.label;"
+                       key="key_newMessage2"
+                       command="cmd_newMessage"/>
+        <toolbarbutton id="appmenu_newFolder"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&newFolderCmd.label;"
+                       command="cmd_newFolder"/>
+        <toolbarbutton id="appmenu_newVirtualFolder"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&newVirtualFolderCmd.label;"
+                       command="cmd_newVirtualFolder"/>
+        <toolbarseparator id="appmenu_newAccountPopupMenuSeparator"/>
+        <toolbarbutton id="appmenu_newCreateEmailAccountMenuItem"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&newCreateEmailAccountCmd.label;"
+                       oncommand="NewMailAccountProvisioner(msgWindow);"/>
+        <toolbarbutton id="appmenu_newMailAccountMenuItem"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&newExistingEmailAccountCmd.label;"
+                       oncommand="NewMailAccount(msgWindow);"/>
+        <toolbarbutton id="appmenu_newIMAccountMenuItem"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&newIMAccountCmd.label;"
+                       oncommand="openIMAccountWizard();"/>
+        <toolbarbutton id="appmenu_newFeedAccountMenuItem"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&newFeedAccountCmd.label;"
+                       accesskey="&newFeedAccountCmd.accesskey;"
+                       oncommand="AddFeedAccount();"/>
+        <toolbarbutton id="appmenu_newAccountMenuItem"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&newOtherAccountsCmd.label;"
+                       oncommand="MsgAccountWizard();"/>
+        <toolbarseparator id="appmenu_newPopupMenuSeparator"/>
+        <toolbarbutton id="appmenu_newCard"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&appmenuNewContactCmd.label;"
+                       command="cmd_newCard"/>
+        <toolbarbutton id="appmenu_newIMContactMenuItem"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&newIMContactCmd.label;"
+                       command="cmd_addChatBuddy"/>
+      </vbox>
+    </panelview>
+
+    <!-- Attachments -->
+    <panelview id="appMenu-attachmentsView"
+               title="&openAttachmentListCmd.label;"
+               class="PanelUI-subView">
+      <vbox class="panel-subview-body">
+        <!-- A toolbarbutton for each attachment is added here when this view is shown. -->
+        <toolbarseparator/>
+        <toolbarbutton label="&openAllAttachmentsCmd.label;"
+                       class="subviewbutton subviewbutton-iconic"
+                       accesskey="&openAllAttachmentsCmd.accesskey;"
+                       command="cmd_openAllAttachments"/>
+        <toolbarbutton label="&saveAllAttachmentsCmd.label;"
+                       class="subviewbutton subviewbutton-iconic"
+                       accesskey="&saveAllAttachmentsCmd.accesskey;"
+                       command="cmd_saveAllAttachments"/>
+        <toolbarbutton label="&detachAllAttachmentsCmd.label;"
+                       class="subviewbutton subviewbutton-iconic"
+                       accesskey="&detachAllAttachmentsCmd.accesskey;"
+                       command="cmd_detachAllAttachments"/>
+        <toolbarbutton label="&deleteAllAttachmentsCmd.label;"
                        class="subviewbutton subviewbutton-iconic"
-                       label="&logins.label;"
-                       oncommand="LoginHelper.openPasswordManager(window, { entryPoint: 'mainmenu' })"
-                       />
-        <toolbarbutton id="appMenu-addons-button"
+                       accesskey="&deleteAllAttachmentsCmd.accesskey;"
+                       command="cmd_deleteAllAttachments"/>
+      </vbox>
+    </panelview>
+
+    <!-- Attachment (single attachment view) -->
+    <panelview id="appMenu-attachmentView"
+               class="PanelUI-subView">
+      <vbox class="panel-subview-body">
+        <!-- toolbarbutton elements are added here when this view is shown (open, save, etc.). -->
+      </vbox>
+    </panelview>
+
+    <!-- Edit -->
+    <panelview id="appMenu-editView"
+               title="&appmenuEditMenu.label;"
+               class="PanelUI-subView">
+      <vbox class="panel-subview-body">
+        <toolbarbutton id="appmenu-editmenu-cut"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&cutCmd.label;"
+                       key="key_cut"
+                       command="cmd_cut"/>
+        <toolbarbutton id="appmenu-editmenu-copy"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&copyCmd.label;"
+                       key="key_copy"
+                       command="cmd_copy"/>
+        <toolbarbutton id="appmenu-editmenu-paste"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&pasteCmd.label;"
+                       key="key_paste"
+                       command="cmd_paste"/>
+        <toolbarseparator/>
+        <toolbarbutton id="appmenu-editmenu-undo"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&undoCmd.label;"
+                       key="key_undo"
+                       command="cmd_undo"/>
+        <toolbarbutton id="appmenu-editmenu-redo"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&redoCmd.label;"
+                       key="key_redo"
+                       command="cmd_redo"/>
+        <toolbarseparator id="appmenu_messageAfterRedoEditSeparator"/>
+        <toolbarbutton id="appmenu_delete"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&deleteCmd.label;"
+#ifdef XP_MACOSX
+                       acceltext="⌫"
+#else
+                       key="key_delete"
+#endif
+                       command="cmd_delete"/>
+        <toolbarseparator id="appmenu_messageAfterDeleteEditSeparator"/>
+        <toolbarbutton id="appmenu-editmenu-selectAll"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&selectAllCmd.label;"
+                       key="key_selectAll"
+                       command="cmd_selectAll"/>
+        <toolbarbutton id="appmenu_selectThread"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&appmenuSelectThread.label;"
+                       key="key_selectThread"
+                       command="cmd_selectThread"/>
+        <toolbarbutton id="appmenu_selectFlagged"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&appmenuSelectFlagged.label;"
+                       command="cmd_selectFlagged"/>
+      </vbox>
+    </panelview>
+
+    <!-- Find -->
+    <panelview id="appMenu-findView"
+               title="&findMenu.label;"
+               class="PanelUI-subView">
+      <vbox class="panel-subview-body">
+        <toolbarbutton id="appmenu_findCmd"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&findCmd.label;"
+                       key="key_find"
+                       command="cmd_find"/>
+        <toolbarbutton id="appmenu_findAgainCmd"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&findAgainCmd.label;"
+                       key="key_findAgain"
+                       command="cmd_findAgain"/>
+        <toolbarseparator id="appMenuAfterFindSeparator"/>
+        <toolbarbutton id="appmenu_searchMailCmd"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&searchMailCmd.label;"
+                       key="key_searchMail"
+                       command="cmd_search"/>
+        <toolbarbutton id="appmenu_searchAddressesCmd"
                        class="subviewbutton subviewbutton-iconic"
-                       label="&addons.label;"
-                       key="key_openAddons"
-                       command="Tools:Addons"
-                       />
-        <toolbarbutton id="appMenu-preferences-button"
+                       label="&searchAddressesCmd.label;"
+                       oncommand="MsgSearchAddresses()"/>
+      </vbox>
+    </panelview>
+
+    <!-- Print -->
+    <panelview id="appMenu-printView"
+               title="&printButton.label;"
+               class="PanelUI-subView">
+      <vbox class="panel-subview-body">
+        <toolbarbutton id="appmenu_print_popup"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&printCmd.label;"
+                       key="key_print"
+                       command="cmd_print"/>
+#ifndef XP_MACOSX
+        <toolbarbutton id="appmenu_printPreview"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&printPreviewCmd.label;"
+                       command="cmd_printpreview"/>
+#endif
+        <toolbarbutton id="appmenu_printSetup"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&printSetupCmd.label;"
+                       command="cmd_printSetup"/>
+      </vbox>
+    </panelview>
+
+    <!-- Save As -->
+    <panelview id="appMenu-saveAsView"
+               title="&saveAsMenu.label;"
+               class="PanelUI-subView">
+      <vbox class="panel-subview-body">
+        <toolbarbutton id="appmenu_saveAsFile"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&saveAsFileCmd.label;"
+                       key="key_saveAsFile"
+                       command="cmd_saveAsFile"/>
+        <toolbarbutton id="appmenu_saveAsTemplate"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&saveAsTemplateCmd.label;"
+                       command="cmd_saveAsTemplate"/>
+      </vbox>
+    </panelview>
+
+    <!-- Message Filters -->
+    <panelview id="appMenu-filtersView"
+               title="&filtersCmd2.label;"
+               class="PanelUI-subView">
+      <vbox class="panel-subview-body">
+        <toolbarbutton id="appmenu_filtersCmd"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&filtersCmd2.label;"
+                       command="cmd_displayMsgFilters"/>
+        <toolbarbutton id="appmenu_applyFilters"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&filtersApply.label;"
+                       command="cmd_applyFilters"/>
+        <toolbarbutton id="appmenu_applyFiltersToSelection"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&filtersApplyToMessage.label;"
+                       command="cmd_applyFiltersToSelection"/>
+      </vbox>
+    </panelview>
+
+    <!-- Add-ons -->
+    <panelview id="appMenu-addonsView"
+               title="&addons.label;"
+               class="PanelUI-subView"
+               oncommand="openAddonPrefs(event.target.getAttribute('value'), event.target.getAttribute('optionsType'));">
+      <vbox class="panel-subview-body">
+        <toolbarbutton label="&addons.label;"
+                       class="subviewbutton subviewbutton-iconic"
+                       oncommand="openAddonsMgr(); event.stopPropagation();"/>
+        <toolbarseparator class="appmenu-menuseparator"/>
+        <label
+#ifdef XP_UNIX
+               value="&addonPrefsUnix.label;"
+#else
+               value="&addonPrefs.label;"
+#endif
+               class="subview-subheader"/>
+        <!-- This message is shown when there are no addon items to show. -->
+        <toolbarbutton label="&addonNoPrefs.label;"
+                       class="subviewbutton subviewbutton-iconic"
+                       disabled="true"/>
+        <!-- One toolbarbutton per addon that has prefs is added here when the
+             view is shown. -->
+      </vbox>
+    </panelview>
+
+    <!-- Preferences -->
+    <panelview id="appMenu-preferencesView"
+#ifdef XP_WIN
+               title="&preferencesCmd2.label;"
+#else
+               title="&preferencesCmdUnix.label;"
+#endif
+               class="PanelUI-subView">
+      <vbox class="panel-subview-body">
+        <toolbarbutton id="appmenu_preferences"
                        class="subviewbutton subviewbutton-iconic"
 #ifdef XP_WIN
                        label="&preferencesCmd2.label;"
 #else
                        label="&preferencesCmdUnix.label;"
-#ifdef XP_MACOSX
-                       key="key_preferencesCmdMac"
 #endif
-#endif
-                       oncommand="openPreferences()"
-                       />
-        <toolbarbutton id="appMenu-customize-button"
+                       oncommand="openOptionsDialog();"/>
+        <toolbarbutton id="appmenu_accountmgr"
                        class="subviewbutton subviewbutton-iconic"
-                       label="&viewCustomizeToolbar.label;"
-                       command="cmd_CustomizeToolbars"
-                       />
+                       label="&accountManagerCmd2.label;"
+                       oncommand="MsgAccountManager(null);"/>
         <toolbarseparator/>
-        <toolbarbutton id="appMenu-open-file-button"
-                       class="subviewbutton"
-                       label="&openFileCmd.label;"
-                       key="openFileKb"
-                       command="Browser:OpenFile"
-                       />
-        <toolbarbutton id="appMenu-save-file-button"
-                       class="subviewbutton"
-                       label="&savePageCmd.label;"
-                       key="key_savePage"
-                       command="Browser:SavePage"
-                       />
-        <toolbarbutton id="appMenu-print-button"
+        <toolbarbutton id="appmenu_quickFilterBar"
+                       class="subviewbutton subviewbutton-iconic"
+                       type="checkbox"
+                       label="&quickFilterBar.toggleBarVisibility.appmenu.label;"
+                       command="cmd_toggleQuickFilterBar">
+          <observes element="view_toolbars_popup_quickFilterBar"
+                    attribute="checked"/>
+        </toolbarbutton>
+        <toolbarbutton id="appmenu_showStatusbar"
+                       class="subviewbutton subviewbutton-iconic"
+                       type="checkbox"
+                       label="&showTaskbarCmd.label;"
+                       oncommand="goToggleToolbar('status-bar', 'menu_showTaskbar')"
+                       checked="true"
+                       observes="menu_showTaskbar"/>
+        <toolbarseparator id="appmenu_toggleToolbarsSeparator"/>
+        <toolbarbutton id="appmenu_toolbarLayout"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&appmenuToolbarLayout.label;"
+                       command="cmd_CustomizeMailToolbar"/>
+        <toolbarseparator id="appmenu_paneViewSeparator"/>
+        <toolbarbutton id="appmenu_MessagePaneLayout"
+                       class="subviewbutton subviewbutton-nav"
+                       label="&messagePaneLayoutStyle.label;"
+                       closemenu="none"
+                       oncommand="PanelUI.showSubView('appMenu-preferencesLayoutView', this)"/>
+      </vbox>
+    </panelview>
+
+    <!-- Preferences / Layout -->
+    <panelview id="appMenu-preferencesLayoutView"
+               title="&messagePaneLayoutStyle.label;"
+               class="PanelUI-subView">
+      <vbox class="panel-subview-body">
+        <toolbarbutton id="appmenu_messagePaneClassic"
+                       class="subviewbutton subviewbutton-iconic"
+                       type="radio"
+                       label="&messagePaneClassic.label;"
+                       name="viewlayoutgroup"
+                       command="cmd_viewClassicMailLayout"/>
+        <toolbarbutton id="appmenu_messagePaneWide"
+                       class="subviewbutton subviewbutton-iconic"
+                       type="radio"
+                       label="&messagePaneWide.label;"
+                       name="viewlayoutgroup"
+                       command="cmd_viewWideMailLayout"/>
+        <toolbarbutton id="appmenu_messagePaneVertical"
+                       class="subviewbutton subviewbutton-iconic"
+                       type="radio"
+                       label="&messagePaneVertical.label;"
+                       name="viewlayoutgroup"
+                       command="cmd_viewVerticalMailLayout"/>
+        <toolbarseparator id="appmenu_viewMenuAfterPaneVerticalSeparator"/>
+        <toolbarbutton id="appmenu_showFolderPane"
+                       class="subviewbutton subviewbutton-iconic"
+                       type="checkbox"
+                       label="&showFolderPaneCmd.label;"
+                       command="cmd_toggleFolderPane"/>
+        <toolbarbutton id="appmenu_showFolderPaneCols"
+                       class="subviewbutton subviewbutton-iconic"
+                       type="checkbox"
+                       label="&showFolderPaneColsCmd.label;"
+                       command="cmd_toggleFolderPaneCols"/>
+        <toolbarbutton id="appmenu_showMessage"
+                       class="subviewbutton subviewbutton-iconic"
+                       type="checkbox"
+                       label="&showMessageCmd.label;"
+                       key="key_toggleMessagePane"
+                       command="cmd_toggleMessagePane"/>
+      </vbox>
+    </panelview>
+
+    <!-- File -->
+    <panelview id="appMenu-fileView"
+               title="&fileMenu.label;"
+               class="PanelUI-subView">
+      <vbox class="panel-subview-body">
+        <toolbarbutton id="appmenu_openMessageFileMenuitem"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&openMessageFileCmd.label;"
+                       oncommand="MsgOpenFromFile();"/>
+        <toolbarbutton id="appmenu_close"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&closeCmd.label;"
+                       key="key_close"
+                       command="cmd_close"/>
+        <toolbarseparator id="appmenu_fileMenuAfterCloseSeparator"/>
+        <toolbarbutton id="appmenu_getNewMsgFor"
+                       class="subviewbutton subviewbutton-nav"
+                       label="&getNewMsgForCmd.label;"
+                       closemenu="none"
+                       oncommand="PanelUI.showSubView('appMenu-fileGetNewMsgForView', this)"/>
+        <toolbarbutton id="appmenu_getNextNMsgs"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&getNextNMsgCmd2.label;"
+                       command="cmd_getNextNMessages"/>
+        <toolbarbutton id="appmenu_sendUnsentMsgs"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&sendUnsentCmd.label;"
+                       command="cmd_sendUnsentMsgs"/>
+        <toolbarbutton id="appmenu_subscribe"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&subscribeCmd.label;"
+                       command="cmd_subscribe"/>
+        <toolbarseparator id="appmenu_fileMenuAfterSubscribeSeparator"/>
+        <toolbarbutton id="appmenu_deleteFolder"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&deleteFolder.label;"
+                       command="cmd_deleteFolder"/>
+        <toolbarbutton id="appmenu_renameFolder"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&renameFolder.label;"
+                       key="key_renameFolder"
+                       command="cmd_renameFolder"/>
+        <toolbarseparator id="appmenu_fileMenuAfterRenameSeparator"/>
+        <toolbarbutton id="appmenu_compactFolder"
                        class="subviewbutton subviewbutton-iconic"
-                       label="&printCmd.label;"
-#ifdef XP_MACOSX
-                       key="printKb"
-                       command="cmd_print"
-#else
-                       command="cmd_printPreview"
-#endif
-                       />
-        <toolbarseparator/>
-        <toolbarbutton id="appMenu-find-button"
-                       class="subviewbutton subviewbutton-iconic"
-                       label="&findOnCmd.label;"
-                       key="key_find"
-                       command="cmd_find"/>
-        <toolbarbutton id="appMenu-more-button"
-                       class="subviewbutton subviewbutton-nav"
-                       label="&moreMenu.label;"
-                       closemenu="none"
-                       oncommand="PanelUI.showSubView('appMenu-moreView', this)"/>
-        <toolbarbutton id="appMenu-developer-button"
+                       label="&compactFolders.label;"
+                       command="cmd_compactFolder"/>
+        <toolbarseparator id="appmenu_fileMenuAfterCompactSeparator"/>
+        <toolbarbutton id="appmenu_offline"
                        class="subviewbutton subviewbutton-nav"
-                       label="&webDeveloperMenu.label;"
-                       closemenu="none"
-                       oncommand="PanelUI.showSubView('PanelUI-developer', this)"/>
-        <toolbarbutton id="appMenu-help-button"
-                       class="subviewbutton subviewbutton-iconic subviewbutton-nav"
-                       label="&appMenuHelp.label;"
+                       label="&offlineMenu.label;"
                        closemenu="none"
-                       oncommand="PanelUI.showSubView('PanelUI-helpView', this)"/>
-#ifndef XP_MACOSX
-        <toolbarseparator/>
-        <toolbarbutton id="appMenu-quit-button"
+                       oncommand="PanelUI.showSubView('appMenu-fileOfflineView', this)"/>
+      </vbox>
+    </panelview>
+
+    <!-- File / Get New Message For -->
+    <panelview id="appMenu-fileGetNewMsgForView"
+               title="&getNewMsgForCmd.label;"
+               class="PanelUI-subView">
+      <vbox class="panel-subview-body">
+        <!-- TODO appmenu dynamically populate account items here
+             Once dynamic folders subviews work, use these commented
+             toolbarbuttons in place of the <menu> below. -->
+        <!-- <toolbarbutton id="appmenu_getnewmsgs_all_accounts"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&getAllNewMsgCmdPopupMenu.label;"
+                       key="key_getAllNewMessages"
+                       command="cmd_getMsgsForAuthAccounts"/>
+        <toolbarbutton id="appmenu_getnewmsgs_current_account"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&getNewMsgCurrentAccountCmdPopupMenu.label;"
+                       key="key_getNewMessages"
+                       command="cmd_getNewMessages"/>
+        <toolbarseparator/> -->
+        <menu id="appmenu_getNewMsgFor"
+              label="&getNewMsgForCmd.label;"
+              oncommand="MsgGetMessagesForAccount();">
+          <menupopup is="folder-menupopup"
+                      mode="getMail"
+                      id="appmenu_getAllNewMsgPopup"
+                      expandFolders="false"
+                      oncommand="MsgGetMessagesForAccount(event.target._folder); event.stopPropagation();">
+            <menuitem id="appmenu_getnewmsgs_all_accounts"
+                      label="&getAllNewMsgCmdPopupMenu.label;"
+                      key="key_getAllNewMessages"
+                      command="cmd_getMsgsForAuthAccounts"/>
+            <menuitem id="appmenu_getnewmsgs_current_account"
+                      label="&getNewMsgCurrentAccountCmdPopupMenu.label;"
+                      key="key_getNewMessages"
+                      command="cmd_getNewMessages"/>
+            <menuseparator/>
+          </menupopup>
+        </menu>
+      </vbox>
+    </panelview>
+
+    <!-- File / Offline -->
+    <panelview id="appMenu-fileOfflineView"
+               title="&offlineMenu.label;"
+               class="PanelUI-subView">
+      <vbox class="panel-subview-body">
+        <toolbarbutton id="appmenu_goOffline"
+                       class="subviewbutton subviewbutton-iconic"
+                       type="checkbox"
+                       label="&offlineGoOfflineCmd.label;"
+                       oncommand="MailOfflineMgr.toggleOfflineStatus();"/>
+        <toolbarseparator id="appmenu_offlineMenuAfterGoSeparator"/>
+        <toolbarbutton id="appmenu_synchronizeOffline"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&synchronizeOfflineCmd.label;"
+                       command="cmd_synchronizeOffline"/>
+        <toolbarbutton id="appmenu_settingsOffline"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&settingsOfflineCmd2.label;"
+                       command="cmd_settingsOffline"/>
+        <toolbarseparator id="app_offlineMenuAfterSettingsSeparator"/>
+        <toolbarbutton id="appmenu_downloadFlagged"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&downloadStarredCmd.label;"
+                       command="cmd_downloadFlagged"/>
+        <toolbarbutton id="appmenu_downloadSelected"
                        class="subviewbutton subviewbutton-iconic"
-#ifdef XP_WIN
-                       label="&quitApplicationCmdWin2.label;"
-                       tooltiptext="&quitApplicationCmdWin2.tooltip;"
-#else
-                       label="&quitApplicationCmd.label;"
-#endif
-                       key="key_quitApplication"
-                       command="cmd_quitApplication"/>
-#endif
+                       label="&downloadSelectedCmd.label;"
+                       command="cmd_downloadSelected"/>
+      </vbox>
+    </panelview>
+
+    <!-- View -->
+    <panelview id="appMenu-viewView"
+               title="&viewMenu.label;"
+               class="PanelUI-subView">
+      <vbox class="panel-subview-body">
+        <toolbarbutton id="appmenu_FolderViews"
+                       class="subviewbutton subviewbutton-nav"
+                       label="&folderView.label;"
+                       closemenu="none"
+                       oncommand="PanelUI.showSubView('appMenu-foldersView', this)"/>
+        <toolbarbutton id="appmenu_viewSortMenu"
+                       class="subviewbutton subviewbutton-nav"
+                       label="&sortMenu.label;"
+                       closemenu="none"
+                       oncommand="PanelUI.showSubView('appMenu-viewSortByView', this)"/>
+        <toolbarbutton id="appmenu_viewMessageViewMenu"
+                       class="subviewbutton subviewbutton-nav"
+                       label="&msgsMenu.label;"
+                       closemenu="none"
+                       oncommand="PanelUI.showSubView('appMenu-viewMessagesView', this)"/>
+        <toolbarbutton id="appmenu_viewMessagesMenu"
+                       class="subviewbutton subviewbutton-nav"
+                       label="&threads.label;"
+                       closemenu="none"
+                       oncommand="PanelUI.showSubView('appMenu-viewThreadsView', this)"/>
+        <toolbarbutton id="appmenu_viewHeadersMenu"
+                       class="subviewbutton subviewbutton-nav"
+                       label="&headersMenu.label;"
+                       closemenu="none"
+                       oncommand="PanelUI.showSubView('appMenu-viewHeadersView', this)"/>
+        <toolbarbutton id="appmenu_viewBodyMenu"
+                       class="subviewbutton subviewbutton-nav"
+                       label="&bodyMenu.label;"
+                       closemenu="none"
+                       oncommand="PanelUI.showSubView('appMenu-viewMessageBodyAsView', this)"/>
+        <toolbarbutton id="appmenu_viewFeedSummary"
+                       class="subviewbutton subviewbutton-nav"
+                       label="&bodyMenuFeed.label;"
+                       closemenu="none"
+                       oncommand="PanelUI.showSubView('appMenu-viewFeedsView', this)"/>
+        <toolbarbutton id="appmenu_viewAttachmentsInlineMenuitem"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&viewAttachmentsInlineCmd.label;"
+                       oncommand="ToggleInlineAttachment(event.target)"
+                       type="checkbox"
+                       checked="true"/>
+        <toolbarseparator id="appmenu_viewAfterAttachmentsSeparator"/>
+        <toolbarbutton id="appmenu_viewFullZoomMenu"
+                       class="subviewbutton subviewbutton-nav"
+                       label="&fullZoom.label;"
+                       closemenu="none"
+                       oncommand="PanelUI.showSubView('appMenu-viewZoomView', this)"/>
+        <toolbarbutton id="appmenu_charsetMenu"
+                       class="subviewbutton subviewbutton-nav"
+                       label="&charsetMenu2.label;"
+                       accesskey="&charsetMenu2.accesskey;"
+                       closemenu="none"
+                       oncommand="PanelUI.showSubView('appMenu-viewTextEncodingView', this)"/>
+        <toolbarseparator id="appmenu_viewAfterCharsetSeparator"/>
+        <toolbarbutton id="appmenu_pageSourceMenuItem"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&pageSourceCmd.label;"
+                       key="key_viewPageSource"
+                       command="cmd_viewPageSource"/>
+        <toolbarbutton id="appmenu_securityStatus"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&menu_securityStatus.label;"
+                       accesskey="&menu_securityStatus.accesskey;"
+                       command="cmd_viewSecurityStatus"/>
       </vbox>
     </panelview>
-    <panelview id="PanelUI-history" flex="1">
+
+    <!-- View / Folders -->
+    <panelview id="appMenu-foldersView"
+               title="&folderView.label;"
+               class="PanelUI-subView">
       <vbox class="panel-subview-body">
-        <toolbarbutton id="appMenuViewHistorySidebar"
-                       label="&appMenuHistory.viewSidebar.label;"
-                       label-checked="&appMenuHistory.hideSidebar.label;"
-                       label-unchecked="&appMenuHistory.viewSidebar.label;"
-                       type="checkbox"
+        <toolbarbutton id="appmenu_allFolders"
+                       class="subviewbutton subviewbutton-iconic"
+                       value="all"
+                       label="&allFolders.label;"
+                       type="radio"
+                       name="viewmessages"
+                       oncommand="gFolderTreeView.toggleMode(this.getAttribute('value'));"/>
+        <toolbarbutton id="appmenu_smartFolders"
                        class="subviewbutton subviewbutton-iconic"
-                       key="key_gotoHistory"
-                       oncommand="SidebarUI.toggle('viewHistorySidebar');">
-                       <observes element="sidebar-box" attribute="positionend"/>
-        </toolbarbutton>
-        <toolbarbutton id="appMenuClearRecentHistory"
-                       label="&appMenuHistory.clearRecent.label;"
+                       value="smart"
+                       label="&unifiedFolders.label;"
+                       type="radio"
+                       name="viewmessages"
+                       oncommand="gFolderTreeView.toggleMode(this.getAttribute('value'));"/>
+        <toolbarbutton id="appmenu_unreadFolders"
+                       class="subviewbutton subviewbutton-iconic"
+                       value="unread"
+                       label="&unreadFolders.label;"
+                       type="radio"
+                       name="viewmessages"
+                       oncommand="gFolderTreeView.toggleMode(this.getAttribute('value'));"/>
+        <toolbarbutton id="appmenu_favoriteFolders"
                        class="subviewbutton subviewbutton-iconic"
-                       command="Tools:Sanitize"/>
-        <toolbarseparator/>
-        <toolbarbutton id="appMenuRecentlyClosedTabs"
-                       label="&historyUndoMenu.label;"
-                       class="subviewbutton subviewbutton-iconic subviewbutton-nav"
-                       closemenu="none"
-                       oncommand="PanelUI.showSubView('appMenu-library-recentlyClosedTabs', this)"/>
-        <toolbarbutton id="appMenuRecentlyClosedWindows"
-                       label="&historyUndoWindowMenu.label;"
-                       class="subviewbutton subviewbutton-iconic subviewbutton-nav"
-                       closemenu="none"
-                       oncommand="PanelUI.showSubView('appMenu-library-recentlyClosedWindows', this)"/>
-        <toolbarseparator/>
-        <label value="&appMenuHistory.recentHistory.label;"
-               class="subview-subheader"/>
-        <toolbaritem id="appMenu_historyMenu"
-                     orient="vertical"
-                     smoothscroll="false"
-                     flatList="true"
-                     tooltip="bhTooltip">
-          <!-- history menu items will go here -->
-        </toolbaritem>
+                       value="favorite"
+                       label="&favoriteFolders.label;"
+                       type="radio"
+                       name="viewmessages"
+                       oncommand="gFolderTreeView.toggleMode(this.getAttribute('value'));"/>
+        <toolbarbutton id="appmenu_recentFolders"
+                       class="subviewbutton subviewbutton-iconic"
+                       value="recent"
+                       label="&recentFolders.label;"
+                       type="radio"
+                       name="viewmessages"
+                       oncommand="gFolderTreeView.toggleMode(this.getAttribute('value'));"/>
+        <toolbarseparator id="appmenu_compactViewSeparator"/>
+        <toolbarbutton id="appmenu_compactFolderView"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&compactVersion.label;"
+                       type="checkbox"
+                       oncommand="gFolderTreeView.toggleCompact(this.getAttribute('checked') == 'true');"/>
+        <toolbarseparator id="appmenu_favoritePropertiesSeparator"/>
+        <toolbarbutton id="appmenu_favoriteFolder"
+                       class="subviewbutton subviewbutton-iconic"
+                       type="checkbox"
+                       label="&menuFavoriteFolder.label;"
+                       checked="false"
+                       oncommand="ToggleFavoriteFolderFlag();"/>
+        <toolbarbutton id="appmenu_properties"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&folderPropsCmd2.label;"
+                       command="cmd_properties"/>
       </vbox>
-      <toolbarbutton id="PanelUI-historyMore"
-                     class="panel-subview-footer subviewbutton"
-                     label="&appMenuHistory.showAll.label;"
-                     oncommand="PlacesCommandHook.showPlacesOrganizer('History'); CustomizableUI.hidePanelForNode(this);"/>
     </panelview>
 
-    <panelview id="appMenu-library-recentlyClosedTabs"/>
-    <panelview id="appMenu-library-recentlyClosedWindows"/>
+    <!-- View / Sort by -->
+    <panelview id="appMenu-viewSortByView"
+               title="&sortMenu.label;"
+               class="PanelUI-subView">
+      <vbox class="panel-subview-body">
+        <toolbarbutton id="appmenu_sortByDateMenuitem"
+                       class="subviewbutton subviewbutton-iconic"
+                       type="radio"
+                       name="sortby"
+                       label="&sortByDateCmd.label;"
+                       oncommand="MsgSortThreadPane('byDate')"/>
+        <toolbarbutton id="appmenu_sortByReceivedMenuitem"
+                       class="subviewbutton subviewbutton-iconic"
+                       type="radio"
+                       name="sortby"
+                       label="&sortByReceivedCmd.label;"
+                       oncommand="MsgSortThreadPane('byReceived')"/>
+        <toolbarbutton id="appmenu_sortByFlagMenuitem"
+                       class="subviewbutton subviewbutton-iconic"
+                       type="radio"
+                       name="sortby"
+                       label="&sortByStarCmd.label;"
+                       oncommand="MsgSortThreadPane('byFlagged')"/>
+        <toolbarbutton id="appmenu_sortByOrderReceivedMenuitem"
+                       class="subviewbutton subviewbutton-iconic"
+                       type="radio"
+                       name="sortby"
+                       label="&sortByOrderReceivedCmd.label;"
+                       oncommand="MsgSortThreadPane('byId')"/>
+        <toolbarbutton id="appmenu_sortByPriorityMenuitem"
+                       class="subviewbutton subviewbutton-iconic"
+                       type="radio"
+                       name="sortby"
+                       label="&sortByPriorityCmd.label;"
+                       oncommand="MsgSortThreadPane('byPriority')"/>
+        <toolbarbutton id="appmenu_sortByFromMenuitem"
+                       class="subviewbutton subviewbutton-iconic"
+                       type="radio"
+                       name="sortby"
+                       label="&sortByFromCmd.label;"
+                       oncommand="MsgSortThreadPane('byAuthor')"/>
+        <toolbarbutton id="appmenu_sortByRecipientMenuitem"
+                       class="subviewbutton subviewbutton-iconic"
+                       type="radio"
+                       name="sortby"
+                       label="&sortByRecipientCmd.label;"
+                       oncommand="MsgSortThreadPane('byRecipient')"/>
+        <toolbarbutton id="appmenu_sortByCorrespondentMenuitem"
+                       class="subviewbutton subviewbutton-iconic"
+                       type="radio"
+                       name="sortby"
+                       label="&sortByCorrespondentCmd.label;"
+                       oncommand="MsgSortThreadPane('byCorrespondent')"/>
+        <toolbarbutton id="appmenu_sortBySizeMenuitem"
+                       class="subviewbutton subviewbutton-iconic"
+                       type="radio"
+                       name="sortby"
+                       label="&sortBySizeCmd.label;"
+                       oncommand="MsgSortThreadPane('bySize')"/>
+        <toolbarbutton id="appmenu_sortByStatusMenuitem"
+                       class="subviewbutton subviewbutton-iconic"
+                       type="radio"
+                       name="sortby"
+                       label="&sortByStatusCmd.label;"
+                       oncommand="MsgSortThreadPane('byStatus')"/>
+        <toolbarbutton id="appmenu_sortBySubjectMenuitem"
+                       class="subviewbutton subviewbutton-iconic"
+                       type="radio"
+                       name="sortby"
+                       label="&sortBySubjectCmd.label;"
+                       oncommand="MsgSortThreadPane('bySubject')"/>
+        <toolbarbutton id="appmenu_sortByUnreadMenuitem"
+                       class="subviewbutton subviewbutton-iconic"
+                       type="radio"
+                       name="sortby"
+                       label="&sortByUnreadCmd.label;"
+                       oncommand="MsgSortThreadPane('byUnread')"/>
+        <toolbarbutton id="appmenu_sortByTagsMenuitem"
+                       class="subviewbutton subviewbutton-iconic"
+                       type="radio"
+                       name="sortby"
+                       label="&sortByTagsCmd.label;"
+                       oncommand="MsgSortThreadPane('byTags')"/>
+        <toolbarbutton id="appmenu_sortByJunkStatusMenuitem"
+                       class="subviewbutton subviewbutton-iconic"
+                       type="radio"
+                       name="sortby"
+                       label="&sortByJunkStatusCmd.label;"
+                       oncommand="MsgSortThreadPane('byJunkStatus')"/>
+        <toolbarbutton id="appmenu_sortByAttachmentsMenuitem"
+                       class="subviewbutton subviewbutton-iconic"
+                       type="radio"
+                       name="sortby"
+                       label="&sortByAttachmentsCmd.label;"
+                       oncommand="MsgSortThreadPane('byAttachments')"/>
+        <toolbarseparator id="appmenu_sortAfterAttachmentSeparator"/>
+        <toolbarbutton id="appmenu_sortAscending"
+                       class="subviewbutton subviewbutton-iconic"
+                       type="radio"
+                       name="sortdirection"
+                       label="&sortAscending.label;"
+                       oncommand="MsgSortAscending()"/>
+        <toolbarbutton id="appmenu_sortDescending"
+                       class="subviewbutton subviewbutton-iconic"
+                       type="radio"
+                       name="sortdirection"
+                       label="&sortDescending.label;"
+                       oncommand="MsgSortDescending()"/>
+        <toolbarseparator id="appmenu_sortAfterDescendingSeparator"/>
+        <toolbarbutton id="appmenu_sortThreaded"
+                       class="subviewbutton subviewbutton-iconic"
+                       type="radio"
+                       name="threaded"
+                       label="&sortThreaded.label;"
+                       oncommand="MsgSortThreaded();"/>
+        <toolbarbutton id="appmenu_sortUnthreaded"
+                       class="subviewbutton subviewbutton-iconic"
+                       type="radio"
+                       name="threaded"
+                       label="&sortUnthreaded.label;"
+                       oncommand="MsgSortUnthreaded();"/>
+        <toolbarbutton id="appmenu_groupBySort"
+                       class="subviewbutton subviewbutton-iconic"
+                       type="radio"
+                       name="group"
+                       label="&groupBySort.label;"
+                       oncommand="MsgGroupBySort();"/>
+      </vbox>
+    </panelview>
 
-    <panelview id="PanelUI-remotetabs" flex="1" class="PanelUI-subView"
-               descriptionheightworkaround="true">
+    <!-- View / Messages -->
+    <panelview id="appMenu-viewMessagesView"
+               title="&msgsMenu.label;"
+               class="PanelUI-subView">
       <vbox class="panel-subview-body">
-        <!-- this widget has 3 boxes in the body, but only 1 is ever visible -->
-        <!-- When Sync is ready to sync -->
-        <vbox id="PanelUI-remotetabs-main" hidden="true">
-          <vbox id="PanelUI-remotetabs-buttons">
-            <toolbarbutton id="PanelUI-remotetabs-view-sidebar"
-                           class="subviewbutton subviewbutton-iconic"
-                           label="&appMenuRemoteTabs.sidebar.label;"
-                           label-checked="&appMenuRemoteTabs.hidesidebar.label;"
-                           label-unchecked="&appMenuRemoteTabs.sidebar.label;"
-                           oncommand="SidebarUI.toggle('viewTabsSidebar', this);"/>
-            <toolbarbutton id="PanelUI-remotetabs-view-managedevices"
-                           class="subviewbutton subviewbutton-iconic"
-                           label="&appMenuRemoteTabs.managedevices.label;"
-                           oncommand="gSync.openDevicesManagementPage('syncedtabs-menupanel');">
-                           <observes element="sidebar-box" attribute="positionend"/>
-            </toolbarbutton>
-            <toolbarbutton id="PanelUI-remotetabs-syncnow"
-                           onmouseover="gSync.refreshSyncButtonsTooltip();"
-                           class="subviewbutton subviewbutton-iconic"
-                           oncommand="gSync.doSync();"
-                           closemenu="none"/>
-            <menuseparator id="PanelUI-remotetabs-separator"/>
-          </vbox>
-          <deck id="PanelUI-remotetabs-deck">
-            <!-- Sync is ready to Sync and the "tabs" engine is enabled -->
-            <vbox id="PanelUI-remotetabs-tabspane">
-              <vbox id="PanelUI-remotetabs-tabslist"
-                    showAllLabel="&appMenuRemoteTabs.showAll.label;"
-                    showAllTooltipText="&appMenuRemoteTabs.showAll.tooltip;"
-                    showMoreLabel="&appMenuRemoteTabs.showMore.label;"
-                    showMoreTooltipText="&appMenuRemoteTabs.showMore.tooltip;"
-                    notabsforclientlabel="&appMenuRemoteTabs.notabs.label;"
-                    />
-            </vbox>
-            <!-- Sync is ready to Sync but the "tabs" engine isn't enabled-->
-            <hbox id="PanelUI-remotetabs-tabsdisabledpane" pack="center" flex="1">
-              <vbox class="PanelUI-remotetabs-instruction-box" align="center">
-                <hbox pack="center">
-                  <image class="fxaSyncIllustrationIssue"/>
-                </hbox>
-                <label class="PanelUI-remotetabs-instruction-label">&appMenuRemoteTabs.tabsnotsyncing.label;</label>
-                <hbox pack="center">
-                  <toolbarbutton class="PanelUI-remotetabs-button"
-                                 label="&appMenuRemoteTabs.opensyncprefs.label;"
-                                 oncommand="gSync.openPrefs('synced-tabs');"/>
-                </hbox>
-              </vbox>
-            </hbox>
-            <!-- Sync is ready to Sync but we are still fetching the tabs to show -->
-            <vbox id="PanelUI-remotetabs-fetching">
-              <!-- Show intentionally blank panel, see bug 1239845 -->
-            </vbox>
-            <!-- Sync has only 1 (ie, this) device connected -->
-            <hbox id="PanelUI-remotetabs-nodevicespane" pack="center" flex="1">
-              <vbox class="PanelUI-remotetabs-instruction-box" align="center">
-                <hbox pack="center">
-                  <image class="fxaSyncIllustrationIssue"/>
-                </hbox>
-                <label class="PanelUI-remotetabs-instruction-label">&appMenuRemoteTabs.noclients.subtitle;</label>
-                <toolbarbutton id="PanelUI-remotetabs-connect-device-button"
-                               class="PanelUI-remotetabs-button"
-                               label="&appMenuRemoteTabs.connectdevice.label;"
-                               oncommand="gSync.openConnectAnotherDevice('synced-tabs');"/>
-              </vbox>
-            </hbox>
-          </deck>
-        </vbox>
-        <!-- a box to ensure contained boxes are centered horizonally -->
-        <hbox pack="center" flex="1">
-          <!-- When Sync is not configured -->
-          <vbox id="PanelUI-remotetabs-setupsync"
-                flex="1"
-                align="center"
-                class="PanelUI-remotetabs-instruction-box"
-                hidden="true">
-            <image class="fxaSyncIllustration"/>
-            <label class="PanelUI-remotetabs-instruction-label">&appMenuRemoteTabs.notsignedin.label;</label>
-            <toolbarbutton class="PanelUI-remotetabs-button"
-                           label="&appMenuRemoteTabs.signin.label;"
-                           oncommand="gSync.openPrefs('synced-tabs');"/>
-          </vbox>
-          <!-- When Sync needs re-authentication -->
-          <vbox id="PanelUI-remotetabs-reauthsync"
-                flex="1"
-                align="center"
-                class="PanelUI-remotetabs-instruction-box"
-                hidden="true">
-            <image class="fxaSyncIllustrationIssue"/>
-            <label class="PanelUI-remotetabs-instruction-label">&appMenuRemoteTabs.notsignedin.label;</label>
-            <toolbarbutton class="PanelUI-remotetabs-button"
-                           label="&appMenuRemoteTabs.signin.label;"
-                           oncommand="gSync.openPrefs('synced-tabs');"/>
-          </vbox>
-          <!-- When Sync needs verification -->
-          <vbox id="PanelUI-remotetabs-unverified"
-                flex="1"
-                align="center"
-                class="PanelUI-remotetabs-instruction-box"
-                hidden="true">
-            <image class="fxaSyncIllustrationIssue"/>
-            <label class="PanelUI-remotetabs-instruction-label">&appMenuRemoteTabs.unverified.label;</label>
-            <toolbarbutton class="PanelUI-remotetabs-button"
-                           label="&appMenuRemoteTabs.opensyncprefs.label;"
-                           oncommand="gSync.openPrefs('synced-tabs');"/>
-          </vbox>
-        </hbox>
+        <toolbarbutton id="appmenu_viewMessageAll"
+                       class="subviewbutton subviewbutton-iconic"
+                       value="0"
+                       type="radio"
+                       label="&viewAll.label;"
+                       oncommand="ViewChangeByMenuitem(event.target);"/>
+        <toolbarbutton id="appmenu_viewMessageUnread"
+                       class="subviewbutton subviewbutton-iconic"
+                       value="1"
+                       type="radio"
+                       label="&viewUnread.label;"
+                       oncommand="ViewChangeByMenuitem(event.target);"/>
+        <toolbarbutton id="appmenu_viewMessageNotDeleted"
+                       class="subviewbutton subviewbutton-iconic"
+                       value="3"
+                       type="radio"
+                       label="&viewNotDeleted.label;"
+                       oncommand="ViewChangeByMenuitem(event.target);"/>
+        <toolbarseparator id="appmenu_messageViewAfterUnreadSeparator"/>
+        <toolbarbutton id="appmenu_viewMessageTags"
+                       class="subviewbutton subviewbutton-nav"
+                       label="&viewTags.label;"
+                       closemenu="none"
+                       oncommand="PanelUI.showSubView('appMenu-viewMessagesTagsView', this)"/>
+        <toolbarbutton id="appmenu_viewMessageCustomViews"
+                       class="subviewbutton subviewbutton-nav"
+                       label="&viewCustomViews.label;"
+                       closemenu="none"
+                       oncommand="PanelUI.showSubView('appMenu-viewMessagesCustomViewsView', this)"/>
+        <toolbarseparator id="appmenu_messageViewAfterCustomSeparator"/>
+        <!-- TODO appmenu - broken? broken already? -->
+        <toolbarbutton id="appmenu_viewMessageVirtualFolder"
+                       class="subviewbutton subviewbutton-iconic"
+                       value="7"
+                       label="&viewVirtualFolder.label;"
+                       oncommand="ViewChangeByMenuitem(event.target);"/>
+        <toolbarbutton id="appmenu_viewMessageCustomize"
+                       class="subviewbutton subviewbutton-iconic"
+                       value="8"
+                       label="&viewCustomizeView.label;"
+                       oncommand="ViewChangeByMenuitem(event.target);"/>
+      </vbox>
+    </panelview>
+
+    <!-- View / Messages / Tags -->
+    <!-- Dynamically populated when shown. -->
+    <panelview id="appMenu-viewMessagesTagsView"
+               title="&viewTags.label;"
+               class="PanelUI-subView"
+               oncommand="ViewChangeByMenuitem(event.target);">
+      <vbox class="panel-subview-body"/>
+    </panelview>
+
+    <!-- View / Messages / Custom Views -->
+    <!-- Dynamically populated when shown. -->
+    <panelview id="appMenu-viewMessagesCustomViewsView"
+               title="&viewCustomViews.label;"
+               class="PanelUI-subView"
+               oncommand="ViewChangeByMenuitem(event.target);">
+      <vbox class="panel-subview-body"/>
+    </panelview>
+
+    <!-- View / Threads -->
+    <panelview id="appMenu-viewThreadsView"
+               title="&threads.label;"
+               class="PanelUI-subView">
+      <vbox class="panel-subview-body">
+        <toolbarbutton id="appmenu_viewAllMessagesMenuItem"
+                       class="subviewbutton subviewbutton-iconic"
+                       type="radio"
+                       name="viewmessages"
+                       label="&allMsgsCmd.label;"
+                       disabled="true"
+                       command="cmd_viewAllMsgs"/>
+        <toolbarbutton id="appmenu_viewUnreadMessagesMenuItem"
+                       class="subviewbutton subviewbutton-iconic"
+                       type="radio"
+                       name="viewmessages"
+                       label="&unreadMsgsCmd.label;"
+                       disabled="true"
+                       command="cmd_viewUnreadMsgs"/>
+        <toolbarbutton id="appmenu_viewThreadsWithUnreadMenuItem"
+                       class="subviewbutton subviewbutton-iconic"
+                       type="radio"
+                       name="viewmessages"
+                       label="&threadsWithUnreadCmd.label;"
+                       disabled="true"
+                       command="cmd_viewThreadsWithUnread"/>
+        <toolbarbutton id="appmenu_viewWatchedThreadsWithUnreadMenuItem"
+                       class="subviewbutton subviewbutton-iconic"
+                       type="radio"
+                       name="viewmessages"
+                       label="&watchedThreadsWithUnreadCmd.label;"
+                       disabled="true"
+                       command="cmd_viewWatchedThreadsWithUnread"/>
+        <toolbarseparator id="appmenu_threadsAfterWatchedSeparator"/>
+        <toolbarbutton id="appmenu_viewIgnoredThreadsMenuItem"
+                       class="subviewbutton subviewbutton-iconic"
+                       type="checkbox"
+                       label="&ignoredThreadsCmd.label;"
+                       disabled="true"
+                       command="cmd_viewIgnoredThreads"/>
+        <toolbarseparator id="appmenu_threadsAfterIgnoredSeparator"/>
+        <toolbarbutton id="appmenu_expandAllThreads"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&expandAllThreadsCmd.label;"
+                       key="key_expandAllThreads"
+                       disabled="true"
+                       command="cmd_expandAllThreads"/>
+        <toolbarbutton id="appmenu_collapseAllThreads"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&collapseAllThreadsCmd.label;"
+                       key="key_collapseAllThreads"
+                       disabled="true"
+                       command="cmd_collapseAllThreads"/>
+      </vbox>
+    </panelview>
+
+    <!-- View / Headers -->
+    <panelview id="appMenu-viewHeadersView"
+               title="&headersMenu.label;"
+               class="PanelUI-subView">
+      <vbox class="panel-subview-body">
+        <toolbarbutton id="appmenu_viewallheaders"
+                       class="subviewbutton subviewbutton-iconic"
+                       type="radio"
+                       name="viewheadergroup"
+                       label="&headersAllCmd.label;"
+                       command="cmd_viewAllHeader"/>
+        <toolbarbutton id="appmenu_viewnormalheaders"
+                       class="subviewbutton subviewbutton-iconic"
+                       type="radio"
+                       name="viewheadergroup"
+                       label="&headersNormalCmd.label;"
+                       command="cmd_viewNormalHeader"/>
+      </vbox>
+    </panelview>
+
+    <!-- View / Message Body As -->
+    <panelview id="appMenu-viewMessageBodyAsView"
+               title="&bodyMenu.label;"
+               class="PanelUI-subView">
+      <vbox class="panel-subview-body">
+        <toolbarbutton id="appmenu_bodyAllowHTML"
+                       class="subviewbutton subviewbutton-iconic"
+                       type="radio"
+                       name="bodyPlaintextVsHTMLPref"
+                       label="&bodyAllowHTML.label;"
+                       oncommand="MsgBodyAllowHTML()"/>
+        <toolbarbutton id="appmenu_bodySanitized"
+                       class="subviewbutton subviewbutton-iconic"
+                       type="radio"
+                       name="bodyPlaintextVsHTMLPref"
+                       label="&bodySanitized.label;"
+                       oncommand="MsgBodySanitized()"/>
+        <toolbarbutton id="appmenu_bodyAsPlaintext"
+                       class="subviewbutton subviewbutton-iconic"
+                       type="radio"
+                       name="bodyPlaintextVsHTMLPref"
+                       label="&bodyAsPlaintext.label;"
+                       oncommand="MsgBodyAsPlaintext()"/>
+        <toolbarbutton id="appmenu_bodyAllParts"
+                       class="subviewbutton subviewbutton-iconic"
+                       type="radio"
+                       name="bodyPlaintextVsHTMLPref"
+                       label="&bodyAllParts.label;"
+                       oncommand="MsgBodyAllParts()"/>
       </vbox>
     </panelview>
 
-    <panelview id="PanelUI-bookmarks" flex="1" class="PanelUI-subView">
+    <!-- View / Feed Message Body As -->
+    <panelview id="appMenu-viewFeedsView"
+               title="&bodyMenuFeed.label;"
+               class="PanelUI-subView">
       <vbox class="panel-subview-body">
-        <toolbarbutton id="panelMenuBookmarkThisPage"
+        <toolbarbutton id="appmenu_bodyFeedGlobalWebPage"
+                       class="subviewbutton subviewbutton-iconic"
+                       type="radio"
+                       name="viewFeedSummaryGroup"
+                       label="&viewFeedWebPage.label;"
+                       observes="bodyFeedGlobalWebPage"
+                       oncommand="FeedMessageHandler.onSelectPref = 0"/>
+        <toolbarbutton id="appmenu_bodyFeedGlobalSummary"
                        class="subviewbutton subviewbutton-iconic"
-                       command="Browser:AddBookmarkAs"
-                       onclick="PanelUI.hide();"/>
-        <toolbarbutton id="panelMenu_bookmarkingTools"
-                       label="&bookmarkingTools.label;"
-                       class="subviewbutton subviewbutton-iconic subviewbutton-nav"
-                       closemenu="none"
-                       oncommand="BookmarkingUI.showBookmarkingTools(this);"/>
-        <toolbarbutton id="panelMenu_searchBookmarks"
-                       label="&searchBookmarks.label;"
+                       type="radio"
+                       name="viewFeedSummaryGroup"
+                       label="&viewFeedSummary.label;"
+                       observes="bodyFeedGlobalSummary"
+                       oncommand="FeedMessageHandler.onSelectPref = 1"/>
+        <toolbarbutton id="appmenu_bodyFeedPerFolderPref"
+                       class="subviewbutton subviewbutton-iconic"
+                       type="radio"
+                       name="viewFeedSummaryGroup"
+                       label="&viewFeedSummaryFeedPropsPref.label;"
+                       observes="bodyFeedPerFolderPref"
+                       oncommand="FeedMessageHandler.onSelectPref = 2"/>
+        <toolbarseparator id="appmenu_viewFeedSummarySeparator"/>
+        <toolbarbutton id="appmenu_bodyFeedSummaryAllowHTML"
+                       class="subviewbutton subviewbutton-iconic"
+                       type="radio"
+                       name="viewFeedBodyHTMLGroup"
+                       label="&bodyAllowHTML.label;"
+                       oncommand="MsgFeedBodyRenderPrefs(false, 0, 0)"/>
+        <toolbarbutton id="appmenu_bodyFeedSummarySanitized"
+                       class="subviewbutton subviewbutton-iconic"
+                       type="radio"
+                       name="viewFeedBodyHTMLGroup"
+                       label="&bodySanitized.label;"
+                       oncommand="MsgFeedBodyRenderPrefs(false, 3, gDisallow_classes_no_html)"/>
+        <toolbarbutton id="appmenu_bodyFeedSummaryAsPlaintext"
                        class="subviewbutton subviewbutton-iconic"
-                       oncommand="PlacesCommandHook.searchBookmarks(); PanelUI.hide();"/>
-        <toolbarseparator/>
-        <label id="panelMenu_recentBookmarks"
-               value="&recentBookmarks.label;"
-               class="subview-subheader"/>
-        <toolbaritem id="panelMenu_bookmarksMenu"
-                     orient="vertical"
-                     smoothscroll="false"
-                     flatList="true"
-                     tooltip="bhTooltip">
-          <!-- bookmarks menu items will go here -->
-        </toolbaritem>
+                       type="radio"
+                       name="viewFeedBodyHTMLGroup"
+                       label="&bodyAsPlaintext.label;"
+                       oncommand="MsgFeedBodyRenderPrefs(true, 1, gDisallow_classes_no_html)"/>
       </vbox>
-      <toolbarbutton id="panelMenu_showAllBookmarks"
-                     label="&showAllBookmarks2.label;"
-                     class="subviewbutton panel-subview-footer"
-                     command="Browser:ShowAllBookmarks"
-                     onclick="PanelUI.hide();"/>
+    </panelview>
+
+    <!-- View / Zoom -->
+    <panelview id="appMenu-viewZoomView"
+               title="&fullZoom.label;"
+               class="PanelUI-subView">
+      <vbox class="panel-subview-body">
+        <toolbarbutton id="appmenu_fullZoomEnlarge"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&fullZoomEnlargeCmd.label;"
+                       key="key_fullZoomEnlarge"
+                       command="cmd_fullZoomEnlarge"/>
+        <toolbarbutton id="appmenu_fullZoomReduce"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&fullZoomReduceCmd.label;"
+                       key="key_fullZoomReduce"
+                       command="cmd_fullZoomReduce"/>
+        <toolbarseparator id="appmenu_fullZoomAfterReduceSeparator"/>
+        <toolbarbutton id="appmenu_fullZoomReset"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&fullZoomResetCmd.label;"
+                       key="key_fullZoomReset"
+                       command="cmd_fullZoomReset"/>
+        <toolbarseparator id="appmenu_fullZoomAfterResetSeparator"/>
+        <toolbarbutton id="appmenu_fullZoomToggle"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&fullZoomToggleCmd.label;"
+                       type="checkbox"
+                       command="cmd_fullZoomToggle"
+                       checked="false"/>
+      </vbox>
+    </panelview>
+
+    <!-- View / Text Encoding -->
+    <!-- Populated when shown via event listener. -->
+    <panelview id="appMenu-viewTextEncodingView"
+               title="&charsetMenu2.label;"
+               class="PanelUI-subView"
+               oncommand="MailSetCharacterSet(event)">
+      <vbox class="panel-subview-body"/>
+    </panelview>
+
+    <!-- View / Text Encoding / Auto-Detect -->
+    <!-- Populated when shown via event listener. -->
+    <panelview id="appMenu-viewTextEncodingDetectorsView"
+               class="PanelUI-subView"
+               oncommand="PanelUI.setTextEncodingDetector(event)">
+      <vbox class="panel-subview-body"/>
     </panelview>
 
-    <panelview id="PanelUI-containers" flex="1">
-      <vbox id="PanelUI-containersItems"/>
-    </panelview>
-
-    <panelview id="PanelUI-helpView" flex="1" class="PanelUI-subView">
-      <vbox id="PanelUI-helpItems" class="panel-subview-body"/>
-    </panelview>
-
-    <panelview id="PanelUI-developer" flex="1">
-      <vbox id="PanelUI-developerItems" class="panel-subview-body"/>
+    <!-- Go -->
+    <panelview id="appMenu-goView"
+               title="&goMenu.label;"
+               class="PanelUI-subView">
+      <vbox class="panel-subview-body">
+        <toolbarbutton id="appmenu_goNextMenu"
+                       class="subviewbutton subviewbutton-nav"
+                       label="&nextMenu.label;"
+                       closemenu="none"
+                       oncommand="PanelUI.showSubView('appMenu-goNextView', this)"/>
+        <toolbarbutton id="appmenu_goPreviousMenu"
+                       class="subviewbutton subviewbutton-nav"
+                       label="&prevMenu.label;"
+                       closemenu="none"
+                       oncommand="PanelUI.showSubView('appMenu-goPreviousView', this)"/>
+        <toolbarbutton id="appmenu_goForward"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&goForwardCmd.label;"
+                       key="key_goForward"
+                       command="cmd_goForward"/>
+        <toolbarbutton id="appmenu_goBack"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&goBackCmd.label;"
+                       key="key_goBack"
+                       command="cmd_goBack"/>
+        <toolbarseparator id="appmenu_goNextSeparator"/>
+        <toolbarbutton id="appmenu_goChat"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&goChatCmd.label;"
+                       key="key_goChat"
+                       command="cmd_chat"/>
+        <toolbarseparator id="appmenu_goChatSeparator"/>
+        <toolbarbutton id="appmenu_goFolderMenu"
+                       class="subviewbutton subviewbutton-nav"
+                       label="&folderMenu.label;"
+                       closemenu="none"
+                       oncommand="PanelUI.showSubView('appMenu-goFolderView', this)"/>
+        <toolbarseparator id="appmenu_goFolderSeparator"/>
+        <toolbarbutton id="appmenu_goRecentlyClosedTabs"
+                       class="subviewbutton subviewbutton-nav"
+                       label="&goRecentlyClosedTabs.label;"
+                       closemenu="none"
+                       oncommand="PanelUI.showSubView('appMenu-goRecentlyClosedTabsView', this)"/>
+        <toolbarseparator id="appmenu_goRecentlyClosedTabsSeparator"/>
+        <toolbarbutton id="appmenu_goStartPage"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&startPageCmd.label;"
+                       key="key_goStartPage"
+                       command="cmd_goStartPage"/>
+      </vbox>
     </panelview>
 
-    <panelview id="PanelUI-characterEncodingView" flex="1">
+    <!-- Go / Next -->
+    <panelview id="appMenu-goNextView"
+               title="&nextMenu.label;"
+               class="PanelUI-subView">
       <vbox class="panel-subview-body">
-        <vbox id="PanelUI-characterEncodingView-pinned"
-              class="PanelUI-characterEncodingView-list"/>
-        <toolbarseparator/>
-        <vbox id="PanelUI-characterEncodingView-charsets"
-              class="PanelUI-characterEncodingView-list"/>
-        <toolbarseparator/>
-        <vbox>
-          <label id="PanelUI-characterEncodingView-autodetect-label"/>
-          <vbox id="PanelUI-characterEncodingView-autodetect"
-                class="PanelUI-characterEncodingView-list"/>
-        </vbox>
+        <toolbarbutton id="appmenu_nextMsg"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&nextMsgCmd.label;"
+                       key="key_nextMsg"
+                       command="cmd_nextMsg"/>
+        <toolbarbutton id="appmenu_nextUnreadMsg"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&nextUnreadMsgCmd.label;"
+                       key="key_nextUnreadMsg"
+                       command="cmd_nextUnreadMsg"/>
+        <toolbarbutton id="appmenu_nextFlaggedMsg"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&nextStarredMsgCmd.label;"
+                       command="cmd_nextFlaggedMsg"/>
+        <toolbarseparator id="appmenu_goNextAfterFlaggedSeparator"/>
+        <toolbarbutton id="appmenu_nextUnreadThread"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&nextUnreadThread.label;"
+                       key="key_nextUnreadThread"
+                       command="cmd_nextUnreadThread"/>
+      </vbox>
+    </panelview>
+
+    <!-- Go / Previous -->
+    <panelview id="appMenu-goPreviousView"
+               title="&prevMenu.label;"
+               class="PanelUI-subView">
+      <vbox class="panel-subview-body">
+        <toolbarbutton id="appmenu_prevMsg"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&prevMsgCmd.label;"
+                       key="key_previousMsg"
+                       command="cmd_previousMsg"/>
+        <toolbarbutton id="appmenu_prevUnreadMsg"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&prevUnreadMsgCmd.label;"
+                       key="key_previousUnreadMsg"
+                       command="cmd_previousUnreadMsg"/>
+        <toolbarbutton id="appmenu_prevFlaggedMsg"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&prevStarredMsgCmd.label;"
+                       command="cmd_previousFlaggedMsg"/>
+      </vbox>
+    </panelview>
+
+    <!-- Go / Folder -->
+    <panelview id="appMenu-goFolderView"
+               title="&folderMenu.label;"
+               class="PanelUI-subView">
+      <vbox class="panel-subview-body">
+        <!-- TODO appmenu dynamically populate -->
+        <menu id="appmenu_goFolderMenu"
+              label="&folderMenu.label;"
+              command="cmd_goFolder">
+          <menupopup is="folder-menupopup" id="appmenu_GoFolderPopup"
+                     showFileHereLabel="true"
+                     showRecent="true"
+                     recentLabel="&contextMoveCopyMsgRecentMenu.label;"/>
+        </menu>
       </vbox>
     </panelview>
 
-    <panelview id="PanelUI-panicView" flex="1"
-               descriptionheightworkaround="true">
-      <!-- This is constructed in CustomizableWidgets.jsm -->
+    <!-- Go / Recently Closed Tabs -->
+    <!-- Dynamically populated when shown. -->
+    <!-- TODO appmenu - what about this 'observes' bit?
+        <menu id="appmenu_goRecentlyClosedTabs"
+                  label="&goRecentlyClosedTabs.label;"
+                  observes="cmd_undoCloseTab">
+    -->
+    <panelview id="appMenu-goRecentlyClosedTabsView"
+               title="&goRecentlyClosedTabs.label;"
+               class="PanelUI-subView">
+      <vbox class="panel-subview-body"/>
     </panelview>
 
-    <panelview id="appMenu-moreView" title="&moreMenu.label;" class="PanelUI-subView">
+
+    <!-- Message -->
+    <panelview id="appMenu-messageView"
+               title="&msgMenu.label;"
+               class="PanelUI-subView">
       <vbox class="panel-subview-body">
-        <toolbarbutton id="appMenu-taskmanager-button"
+        <toolbarbutton id="appmenu_newMsgCmd"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&newMsgCmd.label;"
+                       key="key_newMessage2"
+                       command="cmd_newMessage"/>
+        <toolbarbutton id="appmenu_replyMainMenu"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&replyMsgCmd.label;"
+                       key="key_reply"
+                       command="cmd_reply"/>
+        <toolbarbutton id="appmenu_replyNewsgroupMainMenu"
                        class="subviewbutton subviewbutton-iconic"
-                       label="&taskManagerCmd.label;"
-                       oncommand="switchToTabHavingURI('about:performance', true)"/>
-        <toolbarbutton id="appMenu-characterencoding-button"
+                       label="&replyNewsgroupCmd2.label;"
+                       key="key_reply"
+                       command="cmd_replyGroup"/>
+        <toolbarbutton id="appmenu_replySenderMainMenu"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&replySenderCmd.label;"
+                       command="cmd_replySender"/>
+        <toolbarbutton id="appmenu_replyToAll"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&replyToAllMsgCmd.label;"
+                       key="key_replyall"
+                       command="cmd_replyall"/>
+        <toolbarbutton id="appmenu_replyToList"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&replyToListMsgCmd.label;"
+                       key="key_replylist"
+                       command="cmd_replylist"/>
+        <toolbarbutton id="appmenu_forwardMsg"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&forwardMsgCmd.label;"
+                       key="key_forward"
+                       command="cmd_forward"/>
+        <toolbarbutton id="appmenu_forwardAsMenu"
                        class="subviewbutton subviewbutton-nav"
-                       label="&charsetMenu2.label;"
+                       label="&forwardAsMenu.label;"
+                       closemenu="none"
+                       oncommand="PanelUI.showSubView('appMenu-messageForwardAsView', this)"/>
+        <toolbarbutton id="appmenu_editMsgAsNew"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&editAsNewMsgCmd.label;"
+                       key="key_editAsNew"
+                       command="cmd_editAsNew"/>
+        <toolbarbutton id="appmenu_editDraftMsg"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&editDraftMsgCmd.label;"
+                       command="cmd_editDraftMsg"/>
+        <toolbarbutton id="appmenu_newMsgFromTemplateCmd"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&newMsgFromTemplateCmd.label;"
+                       key="key_newMsgFromTemplate"
+                       command="cmd_newMsgFromTemplate"/>
+        <toolbarbutton id="appmenu_editTemplateMsgCmd"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&editTemplateMsgCmd.label;"
+                       command="cmd_editTemplateMsg"/>
+        <toolbarseparator id="appmenu_messageMenuAfterCompositionCommandsSeparator"/>
+        <toolbarbutton id="appmenu_openMessageWindowMenuitem"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&openMessageWindowCmd.label;"
+                       key="key_openMessage"
+                       command="cmd_openMessage"/>
+#ifdef MAIN_WINDOW
+        <toolbarbutton id="appmenu_openConversationMenuitem"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&openInConversationCmd.label;"
+                       key="key_openConversation"
+                       command="cmd_openConversation"/>
+#endif
+        <toolbarbutton id="appmenu_openFeedMessage"
+                       class="subviewbutton subviewbutton-nav"
+                       label="&openFeedMessage1.label;"
+                       closemenu="none"
+                       oncommand="PanelUI.showSubView('appMenu-messageOpenFeedView', this)"/>
+#ifdef MAIN_WINDOW
+        <toolbarseparator id="appmenu_messageAfterOpenMsgSeparator"/>
+#endif
+        <toolbarbutton id="appmenu_tagMenu"
+                       class="subviewbutton subviewbutton-nav"
+                       label="&tagMenu.label;"
+                       closemenu="none"
+                       oncommand="PanelUI.showSubView('appMenu-messageTagView', this)"/>
+        <toolbarbutton id="appmenu_markMenu"
+                       class="subviewbutton subviewbutton-nav"
+                       label="&markMenu.label;"
                        closemenu="none"
-                       oncommand="PanelUI.showSubView('PanelUI-characterEncodingView', this)"/>
-        <toolbarbutton id="appMenu-workoffline-button"
-                       class="subviewbutton"
-                       label="&goOfflineCmd.label;"
+                       oncommand="PanelUI.showSubView('appMenu-messageMarkView', this)"/>
+        <toolbarseparator id="appmenu_messageMenuAfterMarkSeparator"/>
+        <toolbarbutton id="appmenu_archiveMainMenu"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&archiveMsgCmd.label;"
+                       key="key_archive"
+                       command="cmd_archive"/>
+        <toolbarbutton id="appmenu_cancel"
+                       class="subviewbutton subviewbutton-iconic"
+                       command="cmd_cancel"
+                       label="&cancelNewsMsgCmd.label;"/>
+        <toolbarbutton id="appmenu_moveMenu"
+                       class="subviewbutton subviewbutton-nav"
+                       label="&moveMsgToMenu.label;"
+                       closemenu="none"
+                       oncommand="PanelUI.showSubView('appMenu-messageMoveToView', this)"/>
+        <toolbarbutton id="appmenu_copyMenu"
+                       class="subviewbutton subviewbutton-nav"
+                       label="&copyMsgToMenu.label;"
+                       closemenu="none"
+                       oncommand="PanelUI.showSubView('appMenu-messageCopyToView', this)"/>
+        <toolbarbutton id="appmenu_moveToFolderAgain"
+                       class="subviewbutton subviewbutton-iconic"
+                       command="cmd_moveToFolderAgain"
+                       key="key_moveToFolderAgain"
+                       label="&moveToFolderAgain.label;"/>
+        <toolbarseparator id="appmenu_messageMenuAfterMoveCommandsSeparator"/>
+        <toolbarbutton id="appmenu_createFilter"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&createFilter.label;"
+                       command="cmd_createFilterFromMenu"/>
+        <toolbarseparator id="appmenu_threadItemsSeparator"/>
+        <toolbarbutton label="&killThreadMenu.label;"
+                       id="appmenu_killThread"
+                       class="subviewbutton subviewbutton-iconic"
+                       key="key_killThread"
                        type="checkbox"
-                       command="cmd_toggleOfflineStatus"/>
+                       command="cmd_killThread"/>
+        <toolbarbutton label="&killSubthreadMenu.label;"
+                       id="appmenu_killSubthread"
+                       class="subviewbutton subviewbutton-iconic"
+                       key="key_killSubthread"
+                       type="checkbox"
+                       command="cmd_killSubthread"/>
+        <toolbarbutton label="&watchThreadMenu.label;"
+                       id="appmenu_watchThread"
+                       class="subviewbutton subviewbutton-iconic"
+                       key="key_watchThread"
+                       type="checkbox"
+                       command="cmd_watchThread"/>
       </vbox>
     </panelview>
-    <panelview id="appMenu-libraryView" class="PanelUI-subView">
+
+    <!-- Message / Forward As -->
+    <panelview id="appMenu-messageForwardAsView"
+               title="&forwardAsMenu.label;"
+               class="PanelUI-subView">
       <vbox class="panel-subview-body">
-        <toolbarbutton id="appMenu-library-bookmarks-button"
-                       class="subviewbutton subviewbutton-iconic subviewbutton-nav"
-                       label="&bookmarksSubview.label;"
-                       closemenu="none"
-                       oncommand="BookmarkingUI.showSubView(this);"/>
-        <toolbarbutton id="appMenu-library-pocket-button"
+        <toolbarbutton id="appmenu_forwardAsInline"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&forwardAsInline.label;"
+                       command="cmd_forwardInline"/>
+        <toolbarbutton id="appmenu_forwardAsAttachment"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&forwardAsAttachmentCmd.label;"
+                       command="cmd_forwardAttachment"/>
+      </vbox>
+    </panelview>
+
+    <!-- Message / When Opening Feed Messages -->
+    <panelview id="appMenu-messageOpenFeedView"
+               title="&openFeedMessage1.label;"
+               class="PanelUI-subView">
+      <vbox class="panel-subview-body">
+        <toolbarbutton id="appmenu_openFeedWebPage"
+                       class="subviewbutton subviewbutton-iconic"
+                       type="radio"
+                       name="openFeedGroup"
+                       label="&openFeedWebPage.label;"
+                       oncommand="FeedMessageHandler.onOpenPref = 0"/>
+        <toolbarbutton id="appmenu_openFeedSummary"
                        class="subviewbutton subviewbutton-iconic"
-                       label="&pocketMenuitem.label;"
-                       oncommand="Pocket.openList(event)"/>
-        <toolbarbutton id="appMenu-library-history-button"
-                       class="subviewbutton subviewbutton-iconic subviewbutton-nav"
-                       label="&historyMenu.label;"
-                       closemenu="none"
-                       oncommand="PanelUI.showSubView('PanelUI-history', this)"/>
-        <toolbarbutton id="appMenu-library-downloads-button"
-                       class="subviewbutton subviewbutton-iconic subviewbutton-nav"
-                       label="&libraryDownloads.label;"
-                       closemenu="none"
-                       oncommand="DownloadsSubview.show(this);"/>
-        <toolbarbutton id="appMenu-library-remotetabs-button"
-                       class="subviewbutton subviewbutton-iconic subviewbutton-nav sync-ui-item"
-                       label="&appMenuRemoteTabs.label;"
-                       closemenu="none"
-                       oncommand="PanelUI.showSubView('PanelUI-remotetabs', this)"/>
-        <toolbarseparator hidden="true"/>
-        <label value="&appMenuRecentHighlights.label;"
-               hidden="true"
-               class="subview-subheader"/>
-        <toolbaritem id="appMenu-library-recentHighlights"
-                     hidden="true"
-                     orient="vertical"
-                     smoothscroll="false"
-                     flatList="true"
-                     tooltip="bhTooltip">
-          <!-- Recent Highlights will go here -->
-        </toolbaritem>
+                       type="radio"
+                       name="openFeedGroup"
+                       label="&openFeedSummary.label;"
+                       oncommand="FeedMessageHandler.onOpenPref = 1"/>
+        <toolbarbutton id="appmenu_openFeedWebPageInMessagePane"
+                       class="subviewbutton subviewbutton-iconic"
+                       type="radio"
+                       name="openFeedGroup"
+                       label="&openFeedWebPageInMP.label;"
+                       oncommand="FeedMessageHandler.onOpenPref = 2"/>
+      </vbox>
+    </panelview>
+
+    <!-- Message / Tag -->
+    <panelview id="appMenu-messageTagView"
+               title="&tagMenu.label;"
+               class="PanelUI-subView">
+      <vbox class="panel-subview-body">
+        <toolbarbutton id="appmenu_addNewTag"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&addNewTag.label;"
+                       command="cmd_addTag"/>
+        <toolbarbutton id="appmenu_manageTags"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&manageTags.label;"
+                       command="cmd_manageTags"/>
+        <toolbarseparator id="appmenu_tagMenu-sep-afterTagAddNew"/>
+        <!-- Label for remove all tags is dynamically set. -->
+        <toolbarbutton id="appmenu_tagMenu-tagRemoveAll"
+                       class="subviewbutton subviewbutton-iconic"
+                       command="cmd_removeTags"/>
+        <toolbarseparator id="appmenu_tagMenuAfterRemoveSeparator"/>
+        <!-- Tag items are dynamically added here. -->
       </vbox>
     </panelview>
 
-    <panelview id="PanelUI-fxa" class="PanelUI-subView" descriptionheightworkaround="true">
+    <!-- Message / Mark -->
+    <panelview id="appMenu-messageMarkView"
+               title="&markMenu.label;"
+               class="PanelUI-subView">
       <vbox class="panel-subview-body">
-        <vbox id="PanelUI-fxa-signin">
-          <image class="fxaChooseWhatToSyncDevices"/>
-          <label class="PanelUI-fxa-signin-instruction-callout">&fxa.signin.callout.label;</label>
-          <label class="PanelUI-fxa-signin-instruction-label">&fxa.signin.description.label;</label>
-          <toolbarbutton class="PanelUI-fxa-signin-button"
-                         label="&fxa.signin.button.label;"
-                         oncommand="gSync.openFxAEmailFirstPageFromFxaMenu(this);"/>
-        </vbox>
-        <vbox id="PanelUI-fxa-unverified" class="PanelUI-fxa-unverified-instruction-box">
-          <image class="fxaGraphicMail"/>
-          <label class="PanelUI-fxa-signin-instruction-callout">&fxa.unverified.callout.label;</label>
-          <label class="PanelUI-fxa-signin-instruction-label">&fxa.unverified.description.label;</label>
-          <toolbarbutton class="PanelUI-fxa-signin-button"
-                         label="&fxa.unverified.button.label;"
-                         oncommand="gSync.openPrefsFromFxaMenu('unver_sync_settings', this);"/>
-        </vbox>
-        <vbox id="PanelUI-fxa-menu">
-          <hbox flex="1" align="center" class="fxa-avatar-subpanel">
-            <image role="presentation" id="fxa-menu-avatar"/>
-            <vbox flex="1">
-              <label class="fxa-avatar-subpanel-description" >&fxa.menu.signedInAs.label;</label>
-              <label id="fxa-menu-email"></label>
-            </vbox>
-          </hbox>
-          <toolbarseparator/>
-          <toolbarbutton id="PanelUI-fxa-menu-sendtab-button"
-                         class="subviewbutton subviewbutton-iconic subviewbutton-nav"
-                         closemenu="none"
-                         oncommand="gSync.showSendToDeviceViewFromFxaMenu(this);"/>
-          <toolbarbutton id="PanelUI-fxa-menu-remotetabs-button"
-                         class="subviewbutton subviewbutton-iconic subviewbutton-nav"
-                         label="&appMenuRemoteTabs.label;"
-                         closemenu="none"
-                         oncommand="gSync.showRemoteTabsFromFxaMenu(this);"/>
-          <toolbarbutton id="PanelUI-fxa-menu-view-sidebar"
-                         class="subviewbutton subviewbutton-iconic"
-                         label="&appMenuRemoteTabs.sidebar.label;"
-                         oncommand="gSync.showSidebarFromFxaMenu(this);">
-            <observes element="sidebar-box" attribute="positionend"/>
-          </toolbarbutton>
-          <toolbarseparator/>
-          <toolbarbutton class="subviewbutton"
-                         label="&fxa.menu.connectAnotherDevice2.label;"
-                         oncommand="gSync.openConnectAnotherDeviceFromFxaMenu(this);"/>
-          <toolbarbutton class="subviewbutton"
-                         label="&fxa.menu.manageAccount.label;"
-                         oncommand="gSync.openFxAManagePageFromFxaMenu(this);"/>
-          <toolbarbutton class="subviewbutton"
-                         label="&fxa.menu.syncSettings.label;"
-                         oncommand="gSync.openPrefsFromFxaMenu('sync_settings', this);"/>
-          <toolbarseparator/>
-          <toolbarbutton id="PanelUI-fxa-menu-syncnow-button"
-                         label="&syncSyncNowItem.label;"
-                         syncinglabel="&syncSyncNowItemSyncing.label;"
-                         class="subviewbutton subviewbutton-iconic"
-                         oncommand="gSync.doSyncFromFxaMenu(this);"
-                         closemenu="none"/>
-        </vbox>
+        <toolbarbutton id="appmenu_markReadMenuItem"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&markAsReadCmd.label;"
+                       command="cmd_markAsRead"/>
+        <toolbarbutton id="appmenu_markUnreadMenuItem"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&markAsUnreadCmd.label;"
+                       command="cmd_markAsUnread"/>
+        <toolbarbutton id="appmenu_markThreadAsRead"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&markThreadAsReadCmd.label;"
+                       key="key_markThreadAsRead"
+                       command="cmd_markThreadAsRead"/>
+        <toolbarbutton id="appmenu_markReadByDate"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&markReadByDateCmd.label;"
+                       key="key_markReadByDate"
+                       command="cmd_markReadByDate"/>
+        <toolbarbutton id="appmenu_markAllRead"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&markAllReadCmd.label;"
+                       key="key_markAllRead"
+                       command="cmd_markAllRead"/>
+        <toolbarseparator id="markMenuAfterAllReadSeparator"/>
+        <toolbarbutton id="appmenu_markFlaggedMenuItem"
+                       class="subviewbutton subviewbutton-iconic"
+                       type="checkbox"
+                       label="&markStarredCmd.label;"
+                       key="key_toggleFlagged"
+                       command="cmd_markAsFlagged"/>
+        <toolbarseparator id="markMenuAfterFlaggedSeparator"/>
+        <toolbarbutton id="appmenu_markAsJunk"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&markAsJunkCmd.label;"
+                       key="key_markJunk"
+                       command="cmd_markAsJunk"/>
+        <toolbarbutton id="appmenu_markAsNotJunk"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&markAsNotJunkCmd.label;"
+                       key="key_markNotJunk"
+                       command="cmd_markAsNotJunk"/>
+        <toolbarbutton id="appmenu_recalculateJunkScore"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&recalculateJunkScoreCmd.label;"
+                       command="cmd_recalculateJunkScore"/>
       </vbox>
     </panelview>
-    <!-- This panelview is used to contain the dynamically created buttons for send tab to devices -->
-    <panelview id="PanelUI-sendTabToDevice" flex="1" class="PanelUI-subView">
+
+    <!-- Message / Move To -->
+    <panelview id="appMenu-messageMoveToView"
+               title="&moveMsgToMenu.label;"
+               class="PanelUI-subView">
       <vbox class="panel-subview-body">
-        <toolbarbutton id="PanelUI-sendTabToDevice-syncingDevices" class="subviewbutton subviewbutton-iconic pageAction-sendToDevice-notReady"
-                       label="&sendToDevice.syncNotReady.label;"
-                       disabled="true"/>
+        <!-- TODO appmenu dynamic population -->
+        <menu id="appmenu_moveMenu"
+              label="&moveMsgToMenu.label;"
+              oncommand="MsgMoveMessage(event.target._folder)">
+          <menupopup is="folder-menupopup"
+                     mode="filing"
+                     showFileHereLabel="true"
+                     showRecent="true"
+                     recentLabel="&moveCopyMsgRecentMenu.label;"
+                     showFavorites="true"
+                     favoritesLabel="&contextMoveCopyMsgFavoritesMenu.label;"
+                     favoritesAccessKey="&contextMoveCopyMsgFavoritesMenu.accesskey;"/>
+        </menu>
+      </vbox>
+    </panelview>
+
+    <!-- Message / Copy To -->
+    <panelview id="appMenu-messageCopyToView"
+               title="&copyMsgToMenu.label;"
+               class="PanelUI-subView">
+      <vbox class="panel-subview-body">
+        <!-- TODO appmenu dynamic population -->
+        <menu id="appmenu_copyMenu"
+              label="&copyMsgToMenu.label;"
+              oncommand="MsgCopyMessage(event.target._folder)">
+          <menupopup is="folder-menupopup"
+                      mode="filing"
+                      showFileHereLabel="true"
+                      showRecent="true"
+                      recentLabel="&moveCopyMsgRecentMenu.label;"
+                      showFavorites="true"
+                      favoritesLabel="&contextMoveCopyMsgFavoritesMenu.label;"
+                      favoritesAccessKey="&contextMoveCopyMsgFavoritesMenu.accesskey;"/>
+        </menu>
       </vbox>
     </panelview>
 
-    <panelview id="PanelUI-bookmarkingTools" class="PanelUI-subView">
+    <!-- Tools -->
+    <panelview id="appMenu-toolsView"
+               title="&tasksMenu.label;"
+               class="PanelUI-subView">
       <vbox class="panel-subview-body">
-        <toolbarbutton id="panelMenu_toggleBookmarksMenu"
+        <toolbarbutton hidden="true"
+                       id="appmenu_tasksMenuMail"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&messengerCmd.label;"
+                       key="key_mail"
+                       oncommand="toMessengerWindow();"/>
+        <toolbarbutton id="appmenu_addressBook"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&addressBookCmd.label;"
+                       key="key_addressbook"
+                       oncommand="toOpenWindowByType('mail:addressbook', 'chrome://messenger/content/addressbook/addressbook.xul');"/>
+        <toolbarseparator id="devToolsSeparator"/>
+        <toolbarbutton id="appmenu_openSavedFilesWnd"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&savedFiles.label;"
+                       key="key_savedFiles"
+                       oncommand="openSavedFilesWnd();"/>
+        <toolbarbutton id="appmenu_imAccountsStatus"
+                       class="subviewbutton subviewbutton-nav"
+                       label="&imAccountsStatus.label;"
+                       closemenu="none"
+                       oncommand="PanelUI.showSubView('appMenu-toolsChatStatusView', this)"/>
+
+        <toolbarbutton id="appmenu_joinChatMenuItem"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&joinChatCmd.label;"
+                       command="cmd_joinChat"/>
+        <toolbarseparator id="appmenu_afterChatSeparator"/>
+        <toolbarbutton id="appmenu_runJunkControls"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&runJunkControls.label;"
+                       command="cmd_runJunkControls"/>
+        <toolbarbutton id="appmenu_deleteJunk"
                        class="subviewbutton subviewbutton-iconic"
-                       label-show="&addBookmarksMenu.label;"
-                       label-hide="&removeBookmarksMenu.label;"
-                       oncommand="BookmarkingUI.toggleMenuButtonInToolbar(this);"/>
-        <toolbarbutton id="panelMenu_viewBookmarksSidebar"
+                       label="&deleteJunk.label;"
+                       command="cmd_deleteJunk"/>
+        <toolbarseparator id="tasksMenuAfterDeleteSeparator"/>
+        <toolbarbutton id="appmenu_import"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&importCmd.label;"
+                       oncommand="toImport();"/>
+        <toolbarbutton id="appmenu_devtoolsMenu"
+                       class="subviewbutton subviewbutton-nav"
+                       label="&devtoolsMenu.label;"
+                       accesskey="&devtoolsMenu.accesskey;"
+                       closemenu="none"
+                       oncommand="PanelUI.showSubView('appMenu-toolsDevtoolsView', this)"/>
+        <toolbarbutton id="appmenu_sanitizeHistory"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&clearRecentHistory.label;"
+                       key="key_sanitizeHistory"
+                       oncommand="toSanitize();"/>
+      </vbox>
+    </panelview>
+
+    <!-- Tools / Chat Status -->
+    <panelview id="appMenu-toolsChatStatusView"
+               title="&imAccountsStatus.label;"
+               class="PanelUI-subView"
+               command="cmd_chatStatus">
+      <vbox class="panel-subview-body">
+        <toolbarbutton id="appmenu_imStatusAvailable"
+                       class="subviewbutton subviewbutton-iconic"
+                       status="available"
+                       label="&imStatus.available;"/>
+        <toolbarbutton id="appmenu_imStatusUnavailable"
+                       class="subviewbutton subviewbutton-iconic"
+                       status="unavailable"
+                       label="&imStatus.unavailable;"/>
+        <toolbarseparator id="appmenu_imStatusOfflineSeparator"/>
+        <toolbarbutton id="appmenu_imStatusOffline"
+                       class="subviewbutton subviewbutton-iconic"
+                       status="offline"
+                       label="&imStatus.offline;"/>
+        <toolbarseparator id="appmenu_imStatusShowAccountsSeparator"/>
+        <toolbarbutton id="appmenu_imStatusShowAccounts"
                        class="subviewbutton subviewbutton-iconic"
-                       label-show="&viewBookmarksSidebar2.label;"
-                       label-hide="&hideBookmarksSidebar.label;"
-                       key="viewBookmarksSidebarKb"
-                       oncommand="SidebarUI.toggle('viewBookmarksSidebar', this);">
-                       <observes element="sidebar-box" attribute="positionend"/>
-        </toolbarbutton>
-        <toolbarbutton id="panelMenu_viewBookmarksToolbar"
+                       label="&imStatus.showAccounts;"/>
+      </vbox>
+    </panelview>
+
+    <!-- Tools / Developer Tools -->
+    <panelview id="appMenu-toolsDevtoolsView"
+               title="&devtoolsMenu.label;"
+               class="PanelUI-subView">
+      <vbox class="panel-subview-body">
+        <toolbarbutton id="appmenu_devtoolsToolbox"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&devToolboxCmd.label;"
+                       accesskey="&devToolboxCmd.accesskey;"
+                       key="key_devtoolsToolbox"
+                       oncommand="BrowserToolboxProcess.init();"/>
+        <toolbarbutton id="appmenu_addonDebugging"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&debugAddonsCmd.label;"
+                       accesskey="&debugAddonsCmd.accesskey;"
+                       oncommand="openAboutDebugging('addons')"/>
+        <toolbarbutton id="appmenu_tabsDebugging"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&tabsDebugCmd.label;"
+                       accesskey="&tabsDebugCmd.accesskey;"
+                       oncommand="openAboutDebugging('tabs')"/>
+        <toolbarseparator id="appmenu_debuggingSeparator"/>
+        <toolbarbutton id="appmenu_javascriptConsole"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&errorConsoleCmd.label;"
+                       accesskey="&errorConsoleCmd.accesskey;"
+                       key="key_errorConsole"
+                       oncommand="toJavaScriptConsole();"/>
+        <toolbarbutton id="appmenu_openScratchpad"
                        class="subviewbutton subviewbutton-iconic"
-                       label-show="&viewBookmarksToolbar.label;"
-                       label-hide="&hideBookmarksToolbar.label;"
-                       oncommand="BookmarkingUI.toggleBookmarksToolbar();"/>
+                       label="&scratchpadCmd.label;"
+                       accesskey="&scratchpadCmd.accesskey;"
+                       key="key_scratchpad"
+                       oncommand="ScratchpadManager.openScratchpad({ executionContext: 2 });"/>
+      </vbox>
+    </panelview>
+
+    <!-- Help -->
+    <panelview id="appMenu-helpView"
+               title="&helpMenuWin.label;"
+               class="PanelUI-subView">
+      <vbox class="panel-subview-body">
+        <toolbarbutton id="appmenu_openHelp"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&productHelp.label;"
+                       key="key_openHelp"
+                       oncommand="openSupportURL();"/>
+        <toolbarbutton id="menu_keyboardShortcuts"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&helpKeyboardShortcuts.label;"
+                       oncommand="openLinkText(event, 'keyboardShortcutsURL');"/>
+        <toolbarbutton id="getInvolved"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&helpGetInvolvedPage.label;"
+                       oncommand="openLinkText(event, 'getInvolvedURL');"/>
+        <toolbarbutton id="donationsPage"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&helpDonationsPage.label;"
+                       oncommand="openLinkText(event, 'donateURL');"/>
+        <toolbarbutton id="feedbackPage" hidden="true"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&helpFeedbackPage.label;"
+                       oncommand="openFormattedURL('app.feedback.baseURL');"/>
+        <toolbarseparator/>
+        <toolbarbutton id="appmenu_troubleshootingInfo"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&helpTroubleshootingInfo.label;"
+                       oncommand="openAboutSupport();"/>
+        <toolbarbutton id="appmenu_safeMode"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&helpSafeMode.label;"
+                       oncommand="safeModeRestart();"/>
+        <toolbarseparator/>
+        <toolbarbutton id="appmenu_about"
+                       class="subviewbutton subviewbutton-iconic"
+                       label="&aboutProduct2.label;"
+                       oncommand="openAboutDialog();"/>
       </vbox>
     </panelview>
   </panelmultiview>
 </panel>
-
-<panel id="downloads-button-autohide-panel"
-       role="group"
-       type="arrow"
-       hidden="true"
-       onpopupshown="gCustomizeMode._downloadPanelAutoHideTimeout = setTimeout(() => event.target.hidePopup(), 4000);"
-       onmouseover="clearTimeout(gCustomizeMode._downloadPanelAutoHideTimeout);"
-       onmouseout="gCustomizeMode._downloadPanelAutoHideTimeout = setTimeout(() => event.target.hidePopup(), 2000);"
-       onpopuphidden="clearTimeout(gCustomizeMode._downloadPanelAutoHideTimeout);"
-       >
-  <checkbox id="downloads-button-autohide-checkbox"
-            label="&customizeMode.autoHideDownloadsButton.label;" checked="true"
-            oncommand="gCustomizeMode.onDownloadsAutoHideChange(event)"/>
-</panel>
-
-<panel id="extension-notification-panel"
-       role="group"
-       type="arrow"
-       hidden="true"
-       flip="slide"
-       position="bottomcenter topright"
-       tabspecific="true">
-  <popupnotification id="extension-new-tab-notification"
-                     class="extension-controlled-notification"
-                     popupid="extension-new-tab"
-                     hidden="true"
-                     label="&newTabControlled.header.message;"
-                     buttonlabel="&newTabControlled.keepButton.label;"
-                     buttonaccesskey="&newTabControlled.keepButton.accesskey;"
-                     secondarybuttonlabel="&newTabControlled.disableButton.label;"
-                     secondarybuttonaccesskey="&newTabControlled.disableButton.accesskey;"
-                     closebuttonhidden="true"
-                     dropmarkerhidden="true"
-                     checkboxhidden="true">
-    <popupnotificationcontent orient="vertical">
-      <description id="extension-new-tab-notification-description"/>
-    </popupnotificationcontent>
-  </popupnotification>
-  <popupnotification id="extension-homepage-notification"
-                     class="extension-controlled-notification"
-                     popupid="extension-homepage"
-                     hidden="true"
-                     label="&homepageControlled.header.message;"
-                     buttonlabel="&homepageControlled.keepButton.label;"
-                     buttonaccesskey="&homepageControlled.keepButton.accesskey;"
-                     secondarybuttonlabel="&homepageControlled.disableButton.label;"
-                     secondarybuttonaccesskey="&homepageControlled.disableButton.accesskey;"
-                     closebuttonhidden="true"
-                     dropmarkerhidden="true"
-                     checkboxhidden="true">
-    <popupnotificationcontent orient="vertical">
-      <description id="extension-homepage-notification-description"/>
-    </popupnotificationcontent>
-  </popupnotification>
-  <popupnotification id="extension-tab-hide-notification"
-                     class="extension-controlled-notification"
-                     popupid="extension-tab-hide"
-                     hidden="true"
-                     label="&tabHideControlled.header.message;"
-                     buttonlabel="&tabHideControlled.keepButton.label;"
-                     buttonaccesskey="&tabHideControlled.keepButton.accesskey;"
-                     secondarybuttonlabel="&tabHideControlled.disableButton.label;"
-                     secondarybuttonaccesskey="&tabHideControlled.disableButton.accesskey;"
-                     closebuttonhidden="true"
-                     dropmarkerhidden="true"
-                     checkboxhidden="true">
-    <popupnotificationcontent orient="vertical">
-      <description id="extension-tab-hide-notification-description"/>
-    </popupnotificationcontent>
-  </popupnotification>
-</panel>
--- a/mail/components/customizableui/content/panelUI.js
+++ b/mail/components/customizableui/content/panelUI.js
@@ -1,57 +1,151 @@
 /* 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/. */
 
+/* globals AppConstants CanDetachAttachments CharsetMenu
+  currentAttachments CustomizableUI ExtensionParent ExtensionSupport FullScreen
+  getIconForAttachment goUpdateAttachmentCommands initAddonPrefsMenu
+  initAppMenuPopup InitAppmenuViewBodyMenu InitAppMessageMenu
+  InitAppmenuViewMessagesMenu InitAppFolderViewsMenu InitAppViewSortByMenu
+  InitMessageTags InitRecentlyClosedTabsPopup InitViewFolderViewsMenu
+  InitViewHeadersMenu InitViewLayoutStyleMenu MozXULElement msgWindow
+  onViewToolbarsPopupShowing RefreshCustomViewsPopup RefreshTagsPopup
+  RefreshViewPopup SanitizeAttachmentDisplayName Services ShortcutUtils
+  UpdateCharsetMenu updateEditUIVisibility UpdateFullZoomMenu XPCOMUtils */
+
 ChromeUtils.defineModuleGetter(this, "AppMenuNotifications",
                                "resource://gre/modules/AppMenuNotifications.jsm");
-ChromeUtils.defineModuleGetter(this, "NewTabUtils",
-                               "resource://gre/modules/NewTabUtils.jsm");
+
 ChromeUtils.defineModuleGetter(this, "PanelMultiView",
                                "resource:///modules/PanelMultiView.jsm");
 
+// Needed for character encoding subviews.
+XPCOMUtils.defineLazyGetter(this, "gBundle", function() {
+  const kUrl = "chrome://global/locale/charsetMenu.properties";
+  return Services.strings.createBundle(kUrl);
+});
+
 /**
  * Maintains the state and dispatches events for the main menu panel.
  */
-
 const PanelUI = {
   /** Panel events that we listen for. **/
   get kEvents() {
-    return ["popupshowing", "popupshown", "popuphiding", "popuphidden"];
+    return ["popupshowing", "popupshown", "popuphiding", "popuphidden",
+      "ViewShowing"];
   },
   /**
    * Used for lazily getting and memoizing elements from the document. Lazy
    * getters are set in init, and memoizing happens after the first retrieval.
    */
   get kElements() {
     return {
       mainView: "appMenu-mainView",
       multiView: "appMenu-multiView",
-      helpView: "PanelUI-helpView",
-      libraryView: "appMenu-libraryView",
-      libraryRecentHighlights: "appMenu-library-recentHighlights",
-      menuButton: "PanelUI-menu-button",
+      menuButtonMail: "button-appmenu",
+      menuButtonChat: "button-chat-appmenu",
       panel: "appMenu-popup",
-      notificationPanel: "appMenu-notification-popup",
-      addonNotificationContainer: "appMenu-addon-banners",
+      navbar: "mail-bar3",
+      // TODO appmenu - do we need all of these?
+      // notificationPanel: "appMenu-notification-popup",
+      // addonNotificationContainer: "appMenu-addon-banners",
       overflowFixedList: "widget-overflow-fixed-list",
-      overflowPanel: "widget-overflow",
-      navbar: "nav-bar",
+      // overflowPanel: "widget-overflow",
     };
   },
 
+  /**
+   * Used for the View / Text Encoding view.
+   * Not ideal: copied from: mozilla-central/toolkit/modules/CharsetMenu.jsm
+   * This set contains encodings that are in the Encoding Standard, except:
+   *  - XSS-dangerous encodings (except ISO-2022-JP which is assumed to be
+   *    too common not to be included).
+   *  - x-user-defined, which practically never makes sense as an end-user-chosen
+   *    override.
+   *  - Encodings that IE11 doesn't have in its correspoding menu.
+   */
+  kEncodings: new Set([
+    // Globally relevant
+    "UTF-8",
+    "windows-1252",
+    // Arabic
+    "windows-1256",
+    "ISO-8859-6",
+    // Baltic
+    "windows-1257",
+    "ISO-8859-4",
+    // "ISO-8859-13", // Hidden since not in menu in IE11
+    // Central European
+    "windows-1250",
+    "ISO-8859-2",
+    // Chinese, Simplified
+    "GBK",
+    // Chinese, Traditional
+    "Big5",
+    // Cyrillic
+    "windows-1251",
+    "ISO-8859-5",
+    "KOI8-R",
+    "KOI8-U",
+    "IBM866", // Not in menu in Chromium. Maybe drop this?
+    // "x-mac-cyrillic", // Not in menu in IE11 or Chromium.
+    // Greek
+    "windows-1253",
+    "ISO-8859-7",
+    // Hebrew
+    "windows-1255",
+    "ISO-8859-8",
+    // Japanese
+    "Shift_JIS",
+    "EUC-JP",
+    "ISO-2022-JP",
+    // Korean
+    "EUC-KR",
+    // Thai
+    "windows-874",
+    // Turkish
+    "windows-1254",
+    // Vietnamese
+    "windows-1258",
+    // Hiding rare European encodings that aren't in the menu in IE11 and would
+    // make the menu messy by sorting all over the place
+    // "ISO-8859-3",
+    // "ISO-8859-10",
+    // "ISO-8859-14",
+    // "ISO-8859-15",
+    // "ISO-8859-16",
+    // "macintosh"
+  ]),
+
+  // Used for the View / Text Encoding view.
+  // Not ideal: copied from: mozilla-central/toolkit/modules/CharsetMenu.jsm
+  // Always at the start of the text encodings view, in this order, followed by
+  // a separator.
+  kPinnedEncodings: [
+    "UTF-8",
+    "windows-1252",
+  ],
+
   _initialized: false,
   _notifications: null,
 
   init() {
     this._initElements();
 
-    this.menuButton.addEventListener("mousedown", this);
-    this.menuButton.addEventListener("keypress", this);
+    [this.menuButtonMail, this.menuButtonChat].forEach(button => {
+      // There's no chat button in the messageWindow.xul context.
+      if (button) {
+        button.addEventListener("mousedown", this);
+        button.addEventListener("keypress", this);
+      }
+    });
+
+    this.menuButton = this.menuButtonMail;
 
     Services.obs.addObserver(this, "fullscreen-nav-toolbox");
     Services.obs.addObserver(this, "appMenu-notifications");
 
     XPCOMUtils.defineLazyPreferenceGetter(this, "autoHideToolbarInFullScreen",
       "browser.fullscreen.autohide", false, (pref, previousValue, newValue) => {
         // On OSX, or with autohide preffed off, MozDOMFullscreen is the only
         // event we care about, since fullscreen should behave just like non
@@ -73,28 +167,23 @@ const PanelUI = {
 
     if (this.autoHideToolbarInFullScreen) {
       window.addEventListener("fullscreen", this);
     } else {
       window.addEventListener("MozDOMFullscreen:Entered", this);
       window.addEventListener("MozDOMFullscreen:Exited", this);
     }
 
-    XPCOMUtils.defineLazyPreferenceGetter(this, "libraryRecentHighlightsEnabled",
-      "browser.library.activity-stream.enabled", false, (pref, previousValue, newValue) => {
-        if (!newValue)
-          this.clearLibraryRecentHighlights();
-      });
-
     window.addEventListener("activate", this);
     CustomizableUI.addListener(this);
 
-    for (let event of this.kEvents) {
-      this.notificationPanel.addEventListener(event, this);
-    }
+    // We are not currently using the notificationPanel.
+    // for (let event of this.kEvents) {
+    //   this.notificationPanel.addEventListener(event, this);
+    // }
 
     // We do this sync on init because in order to have the overflow button show up
     // we need to know whether anything is in the permanent panel area.
     this.overflowFixedList.hidden = false;
     // Also unhide the separator. We use CSS to hide/show it based on the panel's content.
     this.overflowFixedList.previousElementSibling.hidden = false;
     CustomizableUI.registerMenuPanel(this.overflowFixedList, CustomizableUI.AREA_FIXED_OVERFLOW_PANEL);
     this.updateOverflowStatus();
@@ -106,81 +195,93 @@ const PanelUI = {
 
   _initElements() {
     for (let [k, v] of Object.entries(this.kElements)) {
       // Need to do fresh let-bindings per iteration
       let getKey = k;
       let id = v;
       this.__defineGetter__(getKey, function() {
         delete this[getKey];
+        // eslint-disable-next-line consistent-return
         return this[getKey] = document.getElementById(id);
       });
     }
   },
 
   _eventListenersAdded: false,
   _ensureEventListenersAdded() {
     if (this._eventListenersAdded)
       return;
     this._addEventListeners();
   },
 
   _addEventListeners() {
     for (let event of this.kEvents) {
       this.panel.addEventListener(event, this);
     }
-
-    this.helpView.addEventListener("ViewShowing", this._onHelpViewShow);
     this._eventListenersAdded = true;
   },
 
   _removeEventListeners() {
     for (let event of this.kEvents) {
       this.panel.removeEventListener(event, this);
     }
-    this.helpView.removeEventListener("ViewShowing", this._onHelpViewShow);
     this._eventListenersAdded = false;
   },
 
   uninit() {
     this._removeEventListeners();
-    for (let event of this.kEvents) {
-      this.notificationPanel.removeEventListener(event, this);
-    }
+
+    // We are not currently using the notificationPanel.
+    // for (let event of this.kEvents) {
+    //   this.notificationPanel.removeEventListener(event, this);
+    // }
 
     Services.obs.removeObserver(this, "fullscreen-nav-toolbox");
     Services.obs.removeObserver(this, "appMenu-notifications");
 
     window.removeEventListener("MozDOMFullscreen:Entered", this);
     window.removeEventListener("MozDOMFullscreen:Exited", this);
     window.removeEventListener("fullscreen", this);
     window.removeEventListener("activate", this);
-    this.menuButton.removeEventListener("mousedown", this);
-    this.menuButton.removeEventListener("keypress", this);
+
+    [this.menuButtonMail, this.menuButtonChat].forEach(button => {
+      // There's no chat button in the messageWindow.xul context.
+      if (button) {
+        button.removeEventListener("mousedown", this);
+        button.removeEventListener("keypress", this);
+      }
+    });
+
     CustomizableUI.removeListener(this);
-    this.libraryView.removeEventListener("ViewShowing", this);
   },
 
   /**
-   * Opens the menu panel if it's closed, or closes it if it's
-   * open.
+   * Opens the menu panel if it's closed, or closes it if it's open.
    *
-   * @param aEvent the event that triggers the toggle.
+   * @param event the event that triggers the toggle.
    */
-  toggle(aEvent) {
+  toggle(event) {
     // Don't show the panel if the window is in customization mode,
     // since this button doubles as an exit path for the user in this case.
     if (document.documentElement.hasAttribute("customizing")) {
       return;
     }
+
+    // Since we have several menu buttons, make sure the current one is used.
+    // This works for now, but in the long run, if we're showing badges etc.
+    // then the current menuButton needs to be set when the app's view/tab
+    // changes, not just when the menu is toggled.
+    this.menuButton = event.target;
+
     this._ensureEventListenersAdded();
     if (this.panel.state == "open") {
       this.hide();
     } else if (this.panel.state == "closed") {
-      this.show(aEvent);
+      this.show(event);
     }
   },
 
   /**
    * Opens the menu panel. If the event target has a child with the
    * toolbarbutton-icon attribute, the panel will be anchored on that child.
    * Otherwise, the panel is anchored on the event target itself.
    *
@@ -232,67 +333,162 @@ const PanelUI = {
           break;
         }
         this._notifications = AppMenuNotifications.notifications;
         this._updateNotifications(true);
         break;
     }
   },
 
-  handleEvent(aEvent) {
+  handleEvent(event) {
     // Ignore context menus and menu button menus showing and hiding:
-    if (aEvent.type.startsWith("popup") &&
-        aEvent.target != this.panel) {
+    if (event.type.startsWith("popup") &&
+        event.target != this.panel) {
       return;
     }
-    switch (aEvent.type) {
+    switch (event.type) {
       case "popupshowing":
-        updateEditUIVisibility();
+        initAppMenuPopup();
         // Fall through
       case "popupshown":
-        if (aEvent.type == "popupshown") {
+        if (event.type == "popupshown") {
           CustomizableUI.addPanelCloseListeners(this.panel);
         }
         // Fall through
       case "popuphiding":
-        if (aEvent.type == "popuphiding") {
-          updateEditUIVisibility();
-        }
         // Fall through
       case "popuphidden":
         this._updateNotifications();
-        this._updatePanelButton(aEvent.target);
-        if (aEvent.type == "popuphidden") {
+        this._updatePanelButton(event.target);
+        if (event.type == "popuphidden") {
           CustomizableUI.removePanelCloseListeners(this.panel);
         }
         break;
       case "mousedown":
-        if (aEvent.button == 0)
-          this.toggle(aEvent);
+        if (event.button == 0) {
+          this.toggle(event);
+        }
         break;
       case "keypress":
-        if (aEvent.key == " " || aEvent.key == "Enter") {
-          this.toggle(aEvent);
-          aEvent.stopPropagation();
+        if (event.key == " " || event.key == "Enter") {
+          this.toggle(event);
+          event.stopPropagation();
         }
         break;
       case "MozDOMFullscreen:Entered":
       case "MozDOMFullscreen:Exited":
       case "fullscreen":
       case "activate":
         this._updateNotifications();
         break;
       case "ViewShowing":
-        if (aEvent.target == this.libraryView) {
-          this.onLibraryViewShowing(aEvent.target).catch(Cu.reportError);
-        }
+        PanelUI._handleViewShowingEvent(event);
         break;
     }
   },
 
+  /**
+   * When a ViewShowing event happens when a <panelview> element is shown,
+   * do any required set up for that particular view.
+   *
+   * @param {ViewShowingEvent} event  ViewShowing event.
+   */
+  _handleViewShowingEvent(event) {
+    // Typically event.target for "ViewShowing" is a <panelview> element.
+    PanelUI._ensureShortcutsShown(event.target);
+
+    switch (event.target.id) {
+      case "appMenu-attachmentsView":
+        this._onAttachmentsViewShow(event);
+        break;
+      case "appMenu-attachmentView":
+        this._onAttachmentViewShow(event);
+        break;
+      case "appMenu-foldersView":
+        this._onFoldersViewShow(event);
+        break;
+      case "appMenu-addonsView":
+        initAddonPrefsMenu(event.target.querySelector(".panel-subview-body"),
+          "toolbarbutton",
+          "subviewbutton subviewbutton-iconic",
+          "subviewbutton subviewbutton-iconic");
+        break;
+      case "appMenu-preferencesView":
+        onViewToolbarsPopupShowing(event,
+          "mail-toolbox",
+          document.getElementById("appmenu_quickFilterBar"),
+          "toolbarbutton",
+          "subviewbutton subviewbutton-iconic");
+        break;
+      case "appMenu-preferencesLayoutView":
+        PanelUI._onPreferencesLayoutViewShow(event);
+        break;
+      // View
+      case "appMenu-viewSortByView":
+        InitAppViewSortByMenu();
+        break;
+      case "appMenu-viewMessagesView":
+        RefreshViewPopup(event.target);
+        break;
+      case "appMenu-viewMessagesTagsView":
+        PanelUI._refreshDynamicView(event, RefreshTagsPopup);
+        break;
+      case "appMenu-viewMessagesCustomViewsView":
+        PanelUI._refreshDynamicView(event, RefreshCustomViewsPopup);
+        break;
+      case "appMenu-viewThreadsView":
+        InitAppmenuViewMessagesMenu();
+        break;
+      case "appMenu-viewHeadersView":
+        InitViewHeadersMenu();
+        break;
+      case "appMenu-viewMessageBodyAsView":
+        InitAppmenuViewBodyMenu();
+        break;
+      case "appMenu-viewFeedsView":
+        InitAppmenuViewBodyMenu();
+        break;
+      case "appMenu-viewZoomView":
+        UpdateFullZoomMenu();
+        break;
+      case "appMenu-viewTextEncodingView":
+        this._onTextEncodingViewShow(event);
+        break;
+      case "appMenu-viewTextEncodingDetectorsView":
+        this._onTextEncodingDetectorsViewShow(event);
+        break;
+      // Go
+      case "appMenu-goRecentlyClosedTabsView":
+        PanelUI._refreshDynamicView(event, InitRecentlyClosedTabsPopup);
+        break;
+      // Message
+      case "appMenu-messageView":
+        InitAppMessageMenu();
+        break;
+      case "appMenu-messageTagView":
+        PanelUI._refreshDynamicView(event, InitMessageTags);
+        break;
+    }
+  },
+
+  /**
+   * Refreshes some views that are dynamically populated. Typically called by
+   * event listeners responding to a ViewShowing event. It calls a given refresh
+   * function (that populates the view), passing appmenu-specific arguments.
+   *
+   * @param {ViewShowingEvent} event    ViewShowing event.
+   * @param {Function} refreshFunction  Function that refreshes a particular view.
+   */
+  _refreshDynamicView(event, refreshFunction) {
+    refreshFunction(event.target.querySelector(".panel-subview-body"),
+      "toolbarbutton",
+      "subviewbutton subviewbutton-iconic",
+      "toolbarseparator");
+  },
+
   get isReady() {
     return !!this._isReady;
   },
 
   get isNotificationPanelOpen() {
     let panelState = this.notificationPanel.state;
 
     return panelState == "showing" || panelState == "open";
@@ -317,25 +513,16 @@ const PanelUI = {
 
     await window.delayedStartupPromise;
     this._ensureEventListenersAdded();
     this.panel.hidden = false;
     this._isReady = true;
   },
 
   /**
-   * Switch the panel to the help view if it's not already
-   * in that view.
-   */
-  showHelpView(aAnchor) {
-    this._ensureEventListenersAdded();
-    this.multiView.showSubView("PanelUI-helpView", aAnchor);
-  },
-
-  /**
    * Shows a subview in the panel with a given ID.
    *
    * @param aViewId the ID of the subview to show.
    * @param aAnchor the element that spawned the subview.
    * @param aEvent the event triggering the view showing.
    */
   async showSubView(aViewId, aAnchor, aEvent) {
     let domEvent = null;
@@ -364,18 +551,16 @@ const PanelUI = {
       return;
     }
 
     if (!aAnchor) {
       Cu.reportError("Expected an anchor when opening subview with id: " + aViewId);
       return;
     }
 
-    this.ensureLibraryInitialized(viewNode);
-
     let container = aAnchor.closest("panelmultiview");
     if (container) {
       container.showSubView(aViewId, aAnchor);
     } else if (!aAnchor.open) {
       aAnchor.open = true;
 
       let tempPanel = document.createXULElement("panel");
       tempPanel.setAttribute("type", "arrow");
@@ -438,145 +623,16 @@ const PanelUI = {
         tempPanel.addEventListener("popuphidden", panelRemover);
       } else {
         panelRemover();
       }
     }
   },
 
   /**
-   * Sets up the event listener for when the Library view is shown.
-   *
-   * @param {panelview} viewNode The library view.
-   */
-  ensureLibraryInitialized(viewNode) {
-    if (viewNode != this.libraryView || viewNode._initialized)
-      return;
-
-    viewNode._initialized = true;
-    viewNode.addEventListener("ViewShowing", this);
-  },
-
-  /**
-   * When the Library view is showing, we can start fetching and populating the
-   * list of Recent Highlights.
-   * This is done asynchronously and may finish when the view is already visible.
-   *
-   * @param {panelview} viewNode The library view.
-   */
-  async onLibraryViewShowing(viewNode) {
-    // Since the library is the first view shown, we don't want to add a blocker
-    // to the event, which would make PanelMultiView wait to show it. Instead,
-    // we keep the space currently reserved for the items, but we hide them.
-    if (this._loadingRecentHighlights || !this.libraryRecentHighlightsEnabled) {
-      return;
-    }
-
-    // Make the elements invisible synchronously, before the view is shown.
-    this.makeLibraryRecentHighlightsInvisible();
-
-    // Perform the rest asynchronously while protecting from re-entrancy.
-    this._loadingRecentHighlights = true;
-    try {
-      await this.fetchAndPopulateLibraryRecentHighlights();
-    } finally {
-      this._loadingRecentHighlights = false;
-    }
-  },
-
-  /**
-   * Fetches the list of Recent Highlights and replaces the items in the Library
-   * view with the results.
-   */
-  async fetchAndPopulateLibraryRecentHighlights() {
-    let highlights = await NewTabUtils.activityStreamLinks.getHighlights({
-      // As per bug 1402023, hard-coded limit, until Activity Stream develops a
-      // richer list.
-      numItems: 6,
-      withFavicons: true,
-      excludePocket: true,
-    }).catch(ex => {
-      // Just hide the section if we can't retrieve the items from the database.
-      Cu.reportError(ex);
-      return [];
-    });
-
-    // Since the call above is asynchronous, the panel may be already hidden
-    // at this point, but we still prepare the items for the next time the
-    // panel is shown, so their space is reserved. The part of this function
-    // that adds the elements is the least expensive anyways.
-    this.clearLibraryRecentHighlights();
-    if (!highlights.length) {
-      return;
-    }
-
-    let container = this.libraryRecentHighlights;
-    container.hidden = container.previousElementSibling.hidden =
-      container.previousElementSibling.previousElementSibling.hidden = false;
-    let fragment = document.createDocumentFragment();
-    for (let highlight of highlights) {
-      let button = document.createXULElement("toolbarbutton");
-      button.classList.add("subviewbutton", "highlight", "subviewbutton-iconic", "bookmark-item");
-      let title = highlight.title || highlight.url;
-      button.setAttribute("label", title);
-      button.setAttribute("tooltiptext", title);
-      button.setAttribute("type", "highlight-" + highlight.type);
-      button.setAttribute("onclick", "PanelUI.onLibraryHighlightClick(event)");
-      if (highlight.favicon) {
-        button.setAttribute("image", highlight.favicon);
-      }
-      button._highlight = highlight;
-      fragment.appendChild(button);
-    }
-    container.appendChild(fragment);
-  },
-
-  /**
-   * Make all nodes from the 'Recent Highlights' section invisible while we
-   * refresh its contents. This is done while the Library view is opening to
-   * avoid showing potentially stale items, but still keep the space reserved.
-   */
-  makeLibraryRecentHighlightsInvisible() {
-    for (let button of this.libraryRecentHighlights.children) {
-      button.style.visibility = "hidden";
-    }
-  },
-
-  /**
-   * Remove all the nodes from the 'Recent Highlights' section and hide it as well.
-   */
-  clearLibraryRecentHighlights() {
-    let container = this.libraryRecentHighlights;
-    while (container.firstChild) {
-      container.firstChild.remove();
-    }
-    container.hidden = container.previousElementSibling.hidden =
-      container.previousElementSibling.previousElementSibling.hidden = true;
-  },
-
-  /**
-   * Event handler; invoked when an item of the Recent Highlights is clicked.
-   *
-   * @param {MouseEvent} event Click event, originating from the Highlight.
-   */
-  onLibraryHighlightClick(event) {
-    let button = event.target;
-    if (event.button > 1 || !button._highlight) {
-      return;
-    }
-    if (event.button == 1) {
-      // Bug 1402849, close library panel on mid mouse click
-      CustomizableUI.hidePanelForNode(button);
-    }
-    window.openUILink(button._highlight.url, event, {
-      triggeringPrincipal: Services.scriptSecurityManager.createNullPrincipal({}),
-    });
-  },
-
-  /**
    * NB: The enable- and disableSingleSubviewPanelAnimations methods only
    * affect the hiding/showing animations of single-subview panels (tempPanel
    * in the showSubView method).
    */
   disableSingleSubviewPanelAnimations() {
     this._disableAnimations = true;
   },
 
@@ -612,46 +668,343 @@ const PanelUI = {
    * Sets the anchor node into the open or closed state, depending
    * on the state of the panel.
    */
   _updatePanelButton() {
     this.menuButton.open = this.panel.state == "open" ||
                            this.panel.state == "showing";
   },
 
-  _onHelpViewShow(aEvent) {
-    // Call global menu setup function
-    buildHelpMenu();
+  /**
+   * Event handler for showing the Preferences/Layout view. Removes "checked"
+   * from all layout menu items and then checks the current layout menu item.
+   *
+   * @param {ViewShowingEvent} event  ViewShowing event.
+   */
+  _onPreferencesLayoutViewShow(event) {
+    event.target.querySelectorAll("[name='viewlayoutgroup']")
+      .forEach(item => item.removeAttribute("checked"));
+
+    InitViewLayoutStyleMenu(event, true);
+  },
+
+  /**
+   * Refreshes and populates the attachments view when it is shown, adding attachment items, etc.
+   * See similar function FillAttachmentListPopup.
+   *
+   * @param {ViewShowingEvent} event  The "ViewShowing" event.
+   */
+  _onAttachmentsViewShow(event) {
+    const viewBody = event.target.querySelector(".panel-subview-body");
+
+    // First clear out the old attachment items. They are above the separator.
+    while (viewBody.firstChild.localName == "toolbarbutton") {
+      viewBody.firstChild.remove();
+    }
+
+    for (const [attachmentIndex, attachment] of currentAttachments.entries()) {
+      PanelUI._addAttachmentToAttachmentsView(viewBody, attachment, attachmentIndex + 1);
+    }
+
+    goUpdateAttachmentCommands();
+  },
+
+  /**
+   * Add an attachment button to the attachments view panel.
+   * See the similar function addAttachmentToPopup.
+   *
+   * @param {Element} viewBody         Parent element that will receive the attachment button.
+   * @param {Object} attachment        Attachment data.
+   * @param {Number} attachmentIndex   1-based index of the attachment.
+   */
+  _addAttachmentToAttachmentsView(viewBody, attachment, attachmentIndex) {
+    if (!viewBody) {
+      return;
+    }
+
+    const item = document.createXULElement("toolbarbutton");
+    if (!item) {
+      return;
+    }
+
+    // Insert the item just before the separator.
+    item.setAttribute("class", "subviewbutton subviewbutton-iconic subviewbutton-nav");
+    item.setAttribute("image", getIconForAttachment(attachment));
+    item.setAttribute("closemenu", "none");
+
+    // Find the separator index.
+    let separatorIndex = 0;
+    while (viewBody.childNodes[separatorIndex].localName != "toolbarseparator") {
+      separatorIndex += 1;
+    }
 
-    let helpMenu = document.getElementById("menu_HelpPopup");
-    let items = this.getElementsByTagName("vbox")[0];
-    let attrs = ["oncommand", "onclick", "label", "key", "disabled"];
+    // The accesskeys for the attachments in the menu start with 1 (not 0).
+    const displayName = SanitizeAttachmentDisplayName(attachment);
+    const label = document.getElementById("bundle_messenger")
+                          .getFormattedString("attachmentDisplayNameFormat",
+                                              [attachmentIndex, displayName]);
+    item.setAttribute("crop", "center");
+    item.setAttribute("label", label);
+    item.setAttribute("accesskey", attachmentIndex % 10);
+
+    // Each attachment gets its own subview with options for opening, saving, deleting, etc.
+    item.setAttribute("oncommand", "PanelUI.showSubView('appMenu-attachmentView', this)");
+
+    // Add the attachment data to the item so that when the item is clicked and the subview is
+    // shown, we can access the attachment data from the ViewShowing event's explicitOriginalTarget.
+    item.attachment = attachment;
+
+    // TODO appmenu - Test that these classes still work as intended.
+    if (attachment.isExternalAttachment) {
+      if (!attachment.hasFile) {
+        item.classList.add("notfound");
+      } else {
+        // TODO appmenu - Is this still needed?  It's from the old menupopup code.
+        //
+        // The text-link class must be added to the <label> and have a <menu> hover rule.
+        // Adding to <menu> makes hover overflow the underline to the popup items.
+        // const label = item.firstChild.nextSibling;
+        // label.classList.add("text-link");
+      }
+    }
 
-    // Remove all buttons from the view
-    while (items.firstChild) {
-      items.firstChild.remove();
+    if (attachment.isDeleted) {
+      item.classList.add("notfound");
+    }
+
+    if (!attachment.hasFile) {
+      item.setAttribute("disabled", "true");
+    }
+
+    viewBody.insertBefore(item, viewBody.childNodes[separatorIndex]);
+  },
+
+  /**
+   * Refreshes and populates the single attachment view (open, save, etc.) when it is shown.
+   * See similar function addAttachmentToPopup.
+   *
+   * @param {ViewShowingEvent} event  The "ViewShowing" event.
+   */
+  _onAttachmentViewShow(event) {
+    const attachment = event.explicitOriginalTarget.attachment;
+    const bundle = document.getElementById("bundle_messenger");
+
+    const detached = attachment.isExternalAttachment;
+    const deleted  = !attachment.hasFile;
+    const canDetach = CanDetachAttachments() && !deleted && !detached;
+
+    const attachmentView = document.getElementById("appMenu-attachmentView");
+    attachmentView.setAttribute("title", attachment.name);
+
+    const viewBody = attachmentView.querySelector(".panel-subview-body");
+
+    // Clear out old view items.
+    while (viewBody.firstChild) {
+      viewBody.firstChild.remove();
     }
 
-    // Add the current set of menuitems of the Help menu to this view
-    let menuItems = Array.prototype.slice.call(helpMenu.getElementsByTagName("menuitem"));
-    let fragment = document.createDocumentFragment();
-    for (let node of menuItems) {
-      if (node.hidden)
-        continue;
-      let button = document.createXULElement("toolbarbutton");
-      // Copy specific attributes from a menuitem of the Help menu
-      for (let attrName of attrs) {
-        if (!node.hasAttribute(attrName))
-          continue;
-        button.setAttribute(attrName, node.getAttribute(attrName));
+    // Create the "open" item.
+    const openButton = document.createXULElement("toolbarbutton");
+    openButton.attachment = attachment;
+    openButton.setAttribute("class", "subviewbutton subviewbutton-iconic");
+    openButton.setAttribute("oncommand", "this.attachment.open();");
+    openButton.setAttribute("label", bundle.getString("openLabel"));
+    openButton.setAttribute("accesskey", bundle.getString("openLabelAccesskey"));
+    if (deleted) {
+      openButton.setAttribute("disabled", "true");
+    }
+    viewBody.appendChild(openButton);
+
+    // Create the "save" item.
+    const saveButton = document.createXULElement("toolbarbutton");
+    saveButton.attachment = attachment;
+    saveButton.setAttribute("class", "subviewbutton subviewbutton-iconic");
+    saveButton.setAttribute("oncommand", "this.attachment.save();");
+    saveButton.setAttribute("label", bundle.getString("saveLabel"));
+    saveButton.setAttribute("accesskey", bundle.getString("saveLabelAccesskey"));
+    if (deleted) {
+      saveButton.setAttribute("disabled", "true");
+    }
+    viewBody.appendChild(saveButton);
+
+    // Create the "detach" item.
+    const detachButton = document.createXULElement("toolbarbutton");
+    detachButton.attachment = attachment;
+    detachButton.setAttribute("class", "subviewbutton subviewbutton-iconic");
+    detachButton.setAttribute("oncommand", "this.attachment.detach(true);");
+    detachButton.setAttribute("label", bundle.getString("detachLabel"));
+    detachButton.setAttribute("accesskey", bundle.getString("detachLabelAccesskey"));
+    if (!canDetach) {
+      detachButton.setAttribute("disabled", "true");
+    }
+    viewBody.appendChild(detachButton);
+
+    // Create the "delete" item.
+    const deleteButton = document.createXULElement("toolbarbutton");
+    deleteButton.attachment = attachment;
+    deleteButton.setAttribute("class", "subviewbutton subviewbutton-iconic");
+    deleteButton.setAttribute("oncommand", "this.attachment.detach(false);");
+    deleteButton.setAttribute("label", bundle.getString("deleteLabel"));
+    deleteButton.setAttribute("accesskey", bundle.getString("deleteLabelAccesskey"));
+    if (!canDetach) {
+      deleteButton.setAttribute("disabled", "true");
+    }
+    viewBody.appendChild(deleteButton);
+
+    // Create the "open containing folder" item, for existing detached only.
+    if (attachment.isFileAttachment) {
+      const separator = document.createXULElement("toolbarseparator");
+      viewBody.appendChild(separator);
+      const openFolderButton = document.createXULElement("toolbarbutton");
+      openFolderButton.attachment = attachment;
+      openFolderButton.setAttribute("class", "subviewbutton subviewbutton-iconic");
+      openFolderButton.setAttribute("oncommand", "this.attachment.openFolder();");
+      openFolderButton.setAttribute("label", bundle.getString("openFolderLabel"));
+      openFolderButton.setAttribute("accesskey", bundle.getString("openFolderLabelAccesskey"));
+      if (deleted) {
+        openFolderButton.setAttribute("disabled", "true");
       }
-      button.setAttribute("class", "subviewbutton");
-      fragment.appendChild(button);
+      viewBody.appendChild(openFolderButton);
+    }
+  },
+
+  /**
+   * Event listener for showing the Folders view.
+   *
+   * @param {ViewShowingEvent} event  ViewShowing event.
+   */
+  _onFoldersViewShow(event) {
+    event.target.querySelectorAll('[name="viewmessages"]')
+      .forEach(item => item.removeAttribute("checked"));
+
+    InitAppFolderViewsMenu();
+    InitViewFolderViewsMenu(event);
+  },
+
+  /**
+   * Create a toolbarbutton DOM node for a text encoding menu item.
+   * Similar to the CharsetMenu.build function.
+   *
+   * @param {Document} doc     The document where the node will be created.
+   * @param {Object} nodeInfo  Contains attributes to set on the node.
+   * @returns {Element}        The DOM node.
+   */
+  _createTextEncodingNode(doc, nodeInfo) {
+    const node = doc.createXULElement("toolbarbutton");
+    node.setAttribute("type", "radio");
+    node.setAttribute("name", nodeInfo.name + "Group");
+    node.setAttribute(nodeInfo.name, nodeInfo.value);
+    node.setAttribute("label", nodeInfo.label);
+    if (nodeInfo.accesskey) {
+      node.setAttribute("accesskey", nodeInfo.accesskey);
+    }
+    node.setAttribute("class", "subviewbutton subviewbutton-iconic");
+    return node;
+  },
+
+  /**
+   * Event listener for showing the View/Text_Encoding view.
+   * Similar to the CharsetMenu.build function.
+   *
+   * @param {ViewShowingEvent} event  ViewShowing event.
+   */
+  _onTextEncodingViewShow(event) {
+    const panelView = event.target;
+    const doc = panelView.ownerDocument;
+    const parent = panelView.querySelector(".panel-subview-body");
+    const showDetectors = panelView.getAttribute("detectors") != "false";
+
+    // Clear the view before recreating it.
+    while (parent.firstChild) {
+      parent.firstChild.remove();
     }
-    items.appendChild(fragment);
+
+    if (showDetectors) {
+      // Add toolbarbutton for detectors subview.
+      const node = doc.createXULElement("toolbarbutton");
+      node.setAttribute("class", "subviewbutton subviewbutton-nav");
+      node.setAttribute("closemenu", "none");
+
+      node.setAttribute("label",
+        gBundle.GetStringFromName("charsetMenuAutodet"));
+
+      node.setAttribute("accesskey",
+        gBundle.GetStringFromName("charsetMenuAutodet.key"));
+
+      node.setAttribute("oncommand",
+        "PanelUI.showSubView('appMenu-viewTextEncodingDetectorsView', this)");
+
+      parent.appendChild(node);
+      parent.appendChild(doc.createXULElement("toolbarseparator"));
+    }
+
+    // Add a toolbarbutton for each character encoding.
+    const pinnedInfoCache = CharsetMenu.getCharsetInfo(
+      PanelUI.kPinnedEncodings, false);
+
+    const charsetInfoCache = CharsetMenu.getCharsetInfo(PanelUI.kEncodings);
+
+    pinnedInfoCache.forEach(charsetInfo => parent.appendChild(
+      PanelUI._createTextEncodingNode(doc, charsetInfo)));
+
+    parent.appendChild(doc.createXULElement("toolbarseparator"));
+
+    charsetInfoCache.forEach(charsetInfo => parent.appendChild(
+      PanelUI._createTextEncodingNode(doc, charsetInfo)));
+
+    UpdateCharsetMenu(msgWindow.mailCharacterSet, parent);
+  },
+
+  /**
+   * Event listener for showing the View/Text_Encoding/Auto-Detect view.
+   * Similar to the CharsetMenu.build function.
+   *
+   * @param {ViewShowingEvent} event  ViewShowing event.
+   */
+  _onTextEncodingDetectorsViewShow(event) {
+    const panelView = event.target;
+    const parent = panelView.querySelector(".panel-subview-body");
+    const doc = parent.ownerDocument;
+
+    // Clear the view before recreating it.
+    while (parent.firstChild) {
+      parent.firstChild.remove();
+    }
+
+    // Populate the view with toolbarbuttons.
+    panelView.setAttribute("title",
+      gBundle.GetStringFromName("charsetMenuAutodet"));
+
+    const detectorInfoCache = CharsetMenu.getDetectorInfo();
+
+    detectorInfoCache.forEach(detectorInfo => parent.appendChild(
+        PanelUI._createTextEncodingNode(doc, detectorInfo)));
+
+    parent.appendChild(doc.createXULElement("toolbarseparator"));
+
+    // Make the current selection checked. (Like UpdateDetectorMenu function.)
+    const detector = Services.prefs.getComplexValue("intl.charset.detector",
+      Ci.nsIPrefLocalizedString);
+
+    const item = parent.getElementsByAttribute("detector", detector).item(0);
+
+    if (item) {
+      item.setAttribute("checked", "true");
+    }
+  },
+
+  /**
+   * Set the text encoding detector preference. Used for the
+   * View / Text Encoding / Auto-Detect view.
+   *
+   * @param {Event} event  The 'oncommand' event.
+   */
+  setTextEncodingDetector(event) {
+    Services.prefs.setStringPref("intl.charset.detector",
+      event.target.getAttribute("detector"));
   },
 
   _updateQuitTooltip() {
     if (AppConstants.platform == "win") {
       return;
     }
 
     let tooltipId = AppConstants.platform == "macosx" ?
@@ -869,17 +1222,19 @@ const PanelUI = {
     let iconAnchor =
       document.getAnonymousElementByAttribute(candidate, "class",
                                               "toolbarbutton-badge-stack") ||
       document.getAnonymousElementByAttribute(candidate, "class",
                                               "toolbarbutton-icon");
     return iconAnchor || candidate;
   },
 
-  _addedShortcuts: false,
+  // This is unused:
+  // _addedShortcuts: false,
+
   _ensureShortcutsShown(view = this.mainView) {
     if (view.hasAttribute("added-shortcuts")) {
       return;
     }
     view.setAttribute("added-shortcuts", "true");
     for (let button of view.querySelectorAll("toolbarbutton[key]")) {
       let keyId = button.getAttribute("key");
       let key = document.getElementById(keyId);
--- a/mail/components/customizableui/moz.build
+++ b/mail/components/customizableui/moz.build
@@ -3,21 +3,23 @@
 # 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/.
 
 DIRS += [
     'content',
 ]
 
-BROWSER_CHROME_MANIFESTS += ['test/browser.ini']
+# TODO appmenu - Not currently used for Thunderbird.
+# BROWSER_CHROME_MANIFESTS += ['test/browser.ini']
 
-TESTING_JS_MODULES += [
-    'test/CustomizableUITestUtils.jsm',
-]
+# TODO appmenu - Not currently used for Thunderbird.
+# TESTING_JS_MODULES += [
+#     'test/CustomizableUITestUtils.jsm',
+# ]
 
 EXTRA_JS_MODULES += [
     'CustomizableUI.jsm',
     'CustomizableWidgets.jsm',
     'CustomizeMode.jsm',
     'DragPositionManager.jsm',
     'PanelMultiView.jsm',
     'SearchWidgetTracker.jsm',
--- a/mail/components/moz.build
+++ b/mail/components/moz.build
@@ -7,16 +7,17 @@
 # least one module from search/ on all platforms
 DIRS += [
     'about-support',
     'accountcreation',
     'activity',
     'addrbook',
     'cloudfile',
     'compose',
+    'customizableui',
     'devtools',
     'downloads',
     'enterprisepolicies',
     'extensions',
     'im',
     'migration',
     'newmailaccount',
     'preferences',
--- a/mail/extensions/mailviews/content/msgViewPickerOverlay.js
+++ b/mail/extensions/mailviews/content/msgViewPickerOverlay.js
@@ -83,18 +83,18 @@ var ViewPickerBinding = {
    *  no way to change it.)
    */
   get isVisible() {
     return document.getElementById("viewPicker") != null;
   },
 
   /**
    * Return the string value representing the current mail view value as
-   *  understood by the view picker widgets.  The value is the index for
-   *  everything but tags.  for tags it's the ":"-prefixed tagname.
+   * understood by the view picker widgets.  The value is the index for
+   * everything but tags.  for tags it's the ":"-prefixed tagname.
    */
   get currentViewValue() {
     if (gFolderDisplay.view.mailViewIndex == kViewItemTags)
       return kViewTagMarker + gFolderDisplay.view.mailViewData;
     return gFolderDisplay.view.mailViewIndex + "";
   },
 
   /**
@@ -103,137 +103,176 @@ var ViewPickerBinding = {
   get currentViewLabel() {
     let viewPicker = document.getElementById("viewPicker");
     return viewPicker.getAttribute("label");
   },
 
   /**
    * The effective view has changed, update the widget.
    */
-  updateDisplay(aEvent, aGiveUpIfNotFound) {
+  updateDisplay(event) {
     let viewPicker = document.getElementById("viewPicker");
     if (viewPicker) {
       let value = this.currentViewValue;
 
       let viewPickerPopup = document.getElementById("viewPickerPopup");
       let selectedItem =
         viewPickerPopup.querySelector('[value="' + value + '"]');
       if (!selectedItem) {
-        // we may have a new item, so refresh to make it show up
+        // We may have a new item, so refresh to make it show up.
         RefreshAllViewPopups(viewPickerPopup, true);
         selectedItem = viewPickerPopup.querySelector('[value="' + value + '"]');
       }
       viewPicker.setAttribute("label",
                               selectedItem && selectedItem.getAttribute("label"));
     }
   },
 };
 ViewPickerBinding._init();
 
 function LaunchCustomizeDialog() {
   OpenOrFocusWindow({}, "mailnews:mailviewlist", "chrome://messenger/content/mailViewList.xul");
 }
 
 /**
- * All of these Refresh*ViewPopup* methods have to deal with two menu
- *  variations.  They are accessible from the "View... Messages" menu as well as
- *  the view picker menu list in the toolbar.  aIsMenulist will be false in the
- *  former case and true in the latter case.
+ * All of these Refresh*ViewPopup* methods have to deal with several menu
+ * instances. For example, the "View... Messages" menu, the view picker menu
+ * list in the toolbar, in appmenu/View/Messages, etc.
+ *
+ * @param {Element} viewPopup  A menu popup element.
  */
-function RefreshAllViewPopups(aViewPopup) {
-  RefreshViewPopup(aViewPopup);
-  var menupopups = aViewPopup.getElementsByTagName("menupopup");
+function RefreshAllViewPopups(viewPopup) {
+  RefreshViewPopup(viewPopup);
+  let menupopups = viewPopup.getElementsByTagName("menupopup");
   if (menupopups.length > 1) {
-    // when we have menupopups, we assume both tags and custom views are there
+    // When we have menupopups, we assume both tags and custom views are there.
     RefreshTagsPopup(menupopups[0]);
     RefreshCustomViewsPopup(menupopups[1]);
   }
 }
 
-
-function RefreshViewPopup(aViewPopup) {
-  // mark default views if selected
+/**
+ * Refresh the view messages popup menu/panel. For example set checked and
+ * hidden state on menu items. Used for example for appmenu/View/Messages panel.
+ *
+ * @param {Element} viewPopup  A menu popup element.
+ */
+function RefreshViewPopup(viewPopup) {
+  // Mark default views if selected.
   let currentViewValue = ViewPickerBinding.currentViewValue;
 
-  let viewAll = aViewPopup.querySelector('[value="' + kViewItemAll + '"]');
+  let viewAll = viewPopup.querySelector('[value="' + kViewItemAll + '"]');
   viewAll.setAttribute("checked", currentViewValue == kViewItemAll);
-  let viewUnread =
-    aViewPopup.querySelector('[value="' + kViewItemUnread + '"]');
+
+  let viewUnread = viewPopup.querySelector('[value="' + kViewItemUnread + '"]');
   viewUnread.setAttribute("checked", currentViewValue == kViewItemUnread);
 
   let viewNotDeleted =
-    aViewPopup.querySelector('[value="' + kViewItemNotDeleted + '"]');
-  var folderArray = GetSelectedMsgFolders();
-  if (folderArray.length == 0)
+    viewPopup.querySelector('[value="' + kViewItemNotDeleted + '"]');
+
+  let folderArray = GetSelectedMsgFolders();
+  if (folderArray.length == 0) {
     return;
+  }
 
-  // only show the "Not Deleted" item for IMAP servers that are using the IMAP
-  // delete model
+  // Only show the "Not Deleted" item for IMAP servers that are using the IMAP
+  // delete model.
   viewNotDeleted.setAttribute("hidden", true);
   var msgFolder = folderArray[0];
   var server = msgFolder.server;
   if (server.type == "imap") {
-    let imapServer =
-      server.QueryInterface(Ci.nsIImapIncomingServer);
+    let imapServer = server.QueryInterface(Ci.nsIImapIncomingServer);
+
     if (imapServer.deleteModel == Ci.nsMsgImapDeleteModels.IMAPDelete) {
       viewNotDeleted.setAttribute("hidden", false);
       viewNotDeleted.setAttribute("checked",
-                                  currentViewValue == kViewItemNotDeleted);
+        currentViewValue == kViewItemNotDeleted);
     }
   }
 }
 
-
-function RefreshCustomViewsPopup(aMenupopup) {
-  // for each mail view in the msg view list, add an entry in our combo box
-  if (!gMailViewList)
+/**
+ * Refresh the contents of the custom views popup menu/panel.
+ * Used for example for appmenu/View/Messages/CustomViews panel.
+ *
+ * @param {Element} parent        Parent element that will recieve the menu items.
+ * @param {string} [elementName]  Type of menu items to create (e.g. "menuitem", "toolbarbutton").
+ * @param {string} [classes]      Classes to set on the menu items.
+ */
+function RefreshCustomViewsPopup(parent, elementName = "menuitem", classes) {
+  if (!gMailViewList) {
     gMailViewList = Cc["@mozilla.org/messenger/mailviewlist;1"]
                       .getService(Ci.nsIMsgMailViewList);
-  // remove all menuitems
-  while (aMenupopup.hasChildNodes())
-    aMenupopup.lastChild.remove();
+  }
+
+  // Remove all menu items.
+  while (parent.hasChildNodes()) {
+    parent.lastChild.remove();
+  }
+
+  // Rebuild the list.
+  const currentView = ViewPickerBinding.currentViewValue;
+  const numItems = gMailViewList.mailViewCount;
 
-  // now rebuild the list
-  var currentView = ViewPickerBinding.currentViewValue;
-  var numItems = gMailViewList.mailViewCount;
-  for (var i = 0; i < numItems; ++i) {
-    var viewInfo = gMailViewList.getMailViewAt(i);
-    var menuitem = document.createXULElement("menuitem");
-    menuitem.setAttribute("label", viewInfo.prettyName);
-    menuitem.setAttribute("value", kViewItemFirstCustom + i);
-    menuitem.setAttribute("type", "radio");
-    if (kViewItemFirstCustom + i == currentView)
-      menuitem.setAttribute("checked", true);
-    aMenupopup.appendChild(menuitem);
+  for (let i = 0; i < numItems; ++i) {
+    const viewInfo = gMailViewList.getMailViewAt(i);
+    const item = document.createXULElement(elementName);
+
+    item.setAttribute("label", viewInfo.prettyName);
+    item.setAttribute("value", kViewItemFirstCustom + i);
+    item.setAttribute("type", "radio");
+
+    if (classes) {
+      item.setAttribute("class", classes);
+    }
+    if (kViewItemFirstCustom + i == currentView) {
+      item.setAttribute("checked", true);
+    }
+    parent.appendChild(item);
   }
 }
 
+/**
+ * Refresh the contents of the tags popup menu/panel. For example, used for
+ * appmenu/View/Messages/Tags.
+ *
+ * @param {Element} parent        Parent element that will recieve the menu items.
+ * @param {string} [elementName]  Type of menu items to create (e.g. "menuitem", "toolbarbutton").
+ * @param {string} [classes]      Classes to set on the menu items.
+ */
+function RefreshTagsPopup(parent, elementName = "menuitem", classes) {
+  // Remove all pre-existing menu items.
+  while (parent.hasChildNodes()) {
+    parent.lastChild.remove();
+  }
 
-function RefreshTagsPopup(aMenupopup) {
-  // remove all menuitems
-  while (aMenupopup.hasChildNodes())
-    aMenupopup.lastChild.remove();
+  // Create tag menu items.
+  const currentTagKey = gFolderDisplay.view.mailViewIndex == kViewItemTags ?
+    gFolderDisplay.view.mailViewData : "";
 
-  // create tag menuitems
-  let currentTagKey = gFolderDisplay.view.mailViewIndex == kViewItemTags ?
-                        gFolderDisplay.view.mailViewData : "";
-  let tagArray = MailServices.tags.getAllTags({});
-  for (let i = 0; i < tagArray.length; ++i) {
-    let tagInfo = tagArray[i];
-    let menuitem = document.createXULElement("menuitem");
-    menuitem.setAttribute("label", tagInfo.tag);
-    menuitem.setAttribute("value", kViewTagMarker + tagInfo.key);
-    menuitem.setAttribute("type", "radio");
-    if (tagInfo.key == currentTagKey)
-      menuitem.setAttribute("checked", true);
-    let color = tagInfo.color;
-    if (color)
-      menuitem.setAttribute("style", "color: " + color + ";");
-    aMenupopup.appendChild(menuitem);
-  }
+  const tagArray = MailServices.tags.getAllTags({});
+
+  tagArray.forEach(tagInfo => {
+    const item = document.createXULElement(elementName);
+
+    item.setAttribute("label", tagInfo.tag);
+    item.setAttribute("value", kViewTagMarker + tagInfo.key);
+    item.setAttribute("type", "radio");
+
+    if (tagInfo.key == currentTagKey) {
+      item.setAttribute("checked", true);
+    }
+    if (tagInfo.color) {
+      item.setAttribute("style", `color: ${tagInfo.color};`);
+    }
+    if (classes) {
+      item.setAttribute("class", classes);
+    }
+    parent.appendChild(item);
+  });
 }
 
 function ViewPickerOnLoad() {
   var viewPickerPopup = document.getElementById("viewPickerPopup");
   if (viewPickerPopup)
     RefreshAllViewPopups(viewPickerPopup, true);
 }
 
--- a/mail/test/mozmill/composition/test-reply-multipart-charset.js
+++ b/mail/test/mozmill/composition/test-reply-multipart-charset.js
@@ -70,21 +70,20 @@ function subtest_replyEditAsNewForward_c
     // Only if the preview pane is on, we can check the following.
     assert_selected_and_displayed(mc, msg);
   }
 
   if (aOverride) {
     // Display the message using the override charset.
     // Use the app menu which is also available on Mac.
     mc.click(mc.eid("button-appmenu"));
-    mc.click_menus_in_sequence(mc.e("appmenu-popup"), [
-      {label: "View"},
-      {label: "Text Encoding"},
-      {label: aOverride},
-    ]);
+    mc.click_appmenu_in_sequence(mc.e("appMenu-mainView"),
+      [ {label: "View"},
+        {label: "Text Encoding"} ],
+      {label: aOverride});
   }
 
   let fwdWin;
   switch (aAction) {
   case 1: // Reply.
     fwdWin = open_compose_with_reply();
     break;
   case 2: // Edit as new.
--- a/mail/test/mozmill/content-tabs/test-addons-mgr.js
+++ b/mail/test/mozmill/content-tabs/test-addons-mgr.js
@@ -46,27 +46,29 @@ function test_open_addons_with_url() {
  * Bug 1462923
  * Check if the "Tools->Add-on Options" menu item works and shows our add-on.
  * This relies on the MozMill extension having optionsURL defined in install.rdf,
  * however simplistic the preferences XUL document may be.
  */
 function test_addon_prefs() {
   // Open Add-on Options.
   mc.click(mc.eid("button-appmenu"));
-  let popups = mc.click_menus_in_sequence(mc.e("appmenu-popup"), [ { id: "appmenu_addons" } ], true);
+  const subview = mc.click_appmenu_in_sequence(mc.e("appMenu-mainView"),
+    [{id: "appmenu_addons"}]);
 
-  let foundAddon = false;
   plan_for_modal_dialog("mozmill-prefs", function(controller) {
-     // Add |mc.sleep(1000);| here to see the popup dialog.
+    // Add |mc.sleep(1000);| here to see the popup dialog.
     controller.window.close();
   });
 
   // MozMill add-on should be somewhere in the list. When found, click it.
-  for (let item of popups[popups.length - 1].children) {
-    if (item.tagName == "menuitem" && item.getAttribute("collapsed") != "true" &&
+  let foundAddon = false;
+  for (let item of subview.children) {
+    if (item.tagName == "toolbarbutton" &&
+        item.getAttribute("collapsed") != "true" &&
         item.label == "MozMill") {
       foundAddon = true;
       mc.click(new elib.Elem(item));
       break;
     }
   }
   assert_true(foundAddon);
 
--- a/mail/test/mozmill/folder-display/test-watch-ignore-thread.js
+++ b/mail/test/mozmill/folder-display/test-watch-ignore-thread.js
@@ -28,27 +28,24 @@ function setupModule(module) {
 
   be_in_folder(folder);
   make_display_threaded();
   expand_all_threads();
 }
 
 /**
  * Click one of the menu items in the appmenu View | Messages menu.
- * @param aMenuId the id of the menu item to click.
+ * @param {string} menuId  The id of the menu item to click.
  */
-function clickViewMessagesItem(aMenuId) {
+function clickViewMessagesItem(menuId) {
   mc.click(mc.eid("button-appmenu"));
-  mc.click_menus_in_sequence(mc.e("appmenu-popup"),
-    [
-      {id: "appmenu_View"},
-      {id: "appmenu_viewMessagesMenu"},
-      {id: aMenuId},
-    ]
-  );
+  mc.click_appmenu_in_sequence(mc.e("appMenu-mainView"),
+    [ {id: "appmenu_View"},
+      {id: "appmenu_viewMessagesMenu"} ],
+    {id: menuId});
 }
 
 /**
  * Test that Ignore Thread works as expected.
  */
 function test_ignore_thread() {
   let t1root = thread1.getMsgHdr(0);
 
--- a/mail/test/mozmill/folder-pane/test-folder-pane-consumers.js
+++ b/mail/test/mozmill/folder-pane/test-folder-pane-consumers.js
@@ -28,19 +28,20 @@ function setupModule(module) {
   let server = setupLocalServer(NNTP_PORT);
   nntpAccount = MailServices.accounts.FindAccountForServer(server);
 }
 
 function test_virtual_folder_selection_tree() {
   plan_for_modal_dialog("mailnews:virtualFolderProperties",
                         subtest_create_virtual_folder);
   mc.click(mc.eid("button-appmenu"));
-  mc.click_menus_in_sequence(mc.e("appmenu-popup"),
-                             [ { id: "appmenu_newMessage" },
-                               { id: "appmenu_newVirtualFolder" } ]);
+  mc.click_appmenu_in_sequence(mc.e("appMenu-mainView"),
+    [{id: "appmenu_new"}],
+    {id: "appmenu_newVirtualFolder"});
+
   wait_for_modal_dialog("mailnews:virtualFolderProperties");
 }
 
 function subtest_create_virtual_folder(vfc) {
   // Open the folder chooser.
   plan_for_modal_dialog("mailnews:virtualFolderList",
                         subtest_check_virtual_folder_list);
   vfc.click(vfc.eid("folderListPicker"));
@@ -56,23 +57,24 @@ function subtest_create_virtual_folder(v
 function subtest_check_virtual_folder_list(listc) {
   let tree = listc.e("folderPickerTree");
   // We should see the folders from the 2 base local accounts here.
   assert_true(tree.view.rowCount > 0, "Folder tree was empty in virtual folder selection!");
   listc.window.document.documentElement.cancelDialog();
 }
 
 function test_offline_sync_folder_selection_tree() {
-  plan_for_modal_dialog("mailnews:synchronizeOffline",
-                        subtest_offline_sync);
+  plan_for_modal_dialog("mailnews:synchronizeOffline", subtest_offline_sync);
+
   mc.click(mc.eid("button-appmenu"));
-  mc.click_menus_in_sequence(mc.e("appmenu-popup"),
-                             [ { id: "appmenu_File" },
-                               { id: "appmenu_offline" },
-                               { id: "appmenu_synchronizeOffline" } ]);
+  mc.click_appmenu_in_sequence(mc.e("appMenu-mainView"),
+    [ {id: "appmenu_File"},
+      {id: "appmenu_offline"} ],
+    {id: "appmenu_synchronizeOffline"});
+
   wait_for_modal_dialog("mailnews:synchronizeOffline");
 }
 
 function subtest_offline_sync(osc) {
   // Open the folder chooser.
   plan_for_modal_dialog("mailnews:selectOffline",
                         subtest_check_offline_folder_list);
   osc.click(osc.eid("select"));
--- a/mail/test/mozmill/folder-tree-modes/test-mode-switching.js
+++ b/mail/test/mozmill/folder-tree-modes/test-mode-switching.js
@@ -23,18 +23,18 @@ var unreadFolder;
 var favoriteFolder;
 var toggle_menu;
 var toggle_appmenu;
 var tree;
 var modeList_menu;
 var modeList_appmenu;
 var view_menu;
 var view_menupopup;
-var appmenu;
-var appmenu_popup;
+var appmenu_button;
+var appmenu_mainView;
 var menu_state;
 
 function setupModule(module) {
   for (let lib of MODULE_REQUIRES) {
     collector.getModule(lib).installInto(module);
   }
 
   rootFolder = inboxFolder.server.rootFolder;
@@ -48,22 +48,22 @@ function setupModule(module) {
 
   make_new_sets_in_folder(unreadFolder, [{count: 1}]);
   favoriteFolder.setFlag(Ci.nsMsgFolderFlags.Favorite);
 
   toggle_menu = mc.e("menu_compactFolderView");
   toggle_appmenu = mc.e("appmenu_compactFolderView");
 
   modeList_menu = mc.e("menu_FolderViewsPopup");
-  modeList_appmenu = mc.e("appmenu_FolderViewsPopup");
+  modeList_appmenu = mc.e("appMenu-foldersView");
 
   view_menu = mc.eid("menu_View");
   view_menupopup = mc.e("menu_View_Popup");
-  appmenu = mc.eid("button-appmenu");
-  appmenu_popup = mc.e("appmenu-popup");
+  appmenu_button = mc.eid("button-appmenu");
+  appmenu_mainView = mc.e("appMenu-mainView");
 
   tree = mc.folderTreeView;
 
   select_no_folders();
   // Main menu is needed for this whole test file.
   menu_state = toggle_main_menu(true);
 }
 
@@ -86,40 +86,44 @@ function assert_compact_state(aChecked, 
  * Check whether the expected folder mode is selected in menus and internally.
  *
  * @param aMode  The name of the expected mode.
  */
 function assert_mode_selected(aMode) {
   assert_equals(tree.mode, aMode);
   let baseMode = tree.baseMode();
   assert_compact_state(baseMode != tree.mode);
-  let popuplist;
   // We need to open the menu because only then the right mode is set in them.
   if (!mc.mozmillModule.isMac) {
     // On OS X the main menu seems not accessible for clicking from mozmill.
     mc.click(view_menu);
-    popuplist = mc.click_menus_in_sequence(view_menupopup, [ { id: modeList_menu.parentNode.id } ], true);
+    let popuplist = mc.click_menus_in_sequence(view_menupopup, [ { id: modeList_menu.parentNode.id } ], true);
     assert_true(modeList_menu.querySelector('[value="' + baseMode + '"]').hasAttribute("checked"));
     mc.close_popup_sequence(popuplist);
   }
-  mc.click(appmenu);
-  popuplist = mc.click_menus_in_sequence(appmenu_popup, [ { id: modeList_appmenu.parentNode.id } ], true);
-  assert_true(modeList_menu.querySelector('[value="' + baseMode + '"]').hasAttribute("checked"));
-  mc.close_popup_sequence(popuplist);
+  mc.click(appmenu_button);
+  mc.click_appmenu_in_sequence(appmenu_mainView,
+    [ {id: "appmenu_View"},
+      {id: "appmenu_FolderViews"} ]);
+  assert_true(modeList_appmenu.querySelector('[value="' + baseMode + '"]').hasAttribute("checked"));
+  // Close the appmenu by clicking the appmenu button again.
+  mc.click(appmenu_button);
 }
 
 /**
  * Toggle the folder mode by clicking in the menu.
  *
- * @param aMode  The base name of the mode to select.
+ * @param mode  The base name of the mode to select.
  */
-function select_mode_in_menu(aMode) {
-  mc.click(appmenu);
-  mc.click_menus_in_sequence(appmenu_popup, [ { id: modeList_appmenu.parentNode.id },
-                                              { value: aMode } ]);
+function select_mode_in_menu(mode) {
+  mc.click(appmenu_button);
+  mc.click_appmenu_in_sequence(appmenu_mainView,
+    [ {id: "appmenu_View"},
+      {id: "appmenu_FolderViews"} ],
+    {value: mode});
 }
 
 /**
  * Toggle the Compact view option by clicking in the menu.
  */
 function toggle_compact_in_menu() {
   // For some reason, clicking the menuitem does not work by any means,
   // therefore we just simulate it here.
--- a/mail/test/mozmill/folder-widget/test-message-filters.js
+++ b/mail/test/mozmill/folder-widget/test-message-filters.js
@@ -86,25 +86,27 @@ function test_message_filter_shows_newsg
 function test_customize_toolbar_doesnt_double_get_mail_menu() {
   be_in_folder(folderA);
 
   /**
    * Get the getAllNewMessages menu and check the number of items.
    */
   function check_getAllNewMsgMenu() {
     wait_for_window_focused(mc.window);
-    mc.click(mc.eid("button-appmenu"), 5, 5);
-    let popups = mc.click_menus_in_sequence(mc.e("appmenu-popup"),
-                                            [ { id: "appmenu_File" },
-                                              { id: "appmenu_getNewMsgFor" } ], true);
 
-    assert_equals(popups[popups.length - 1].children.length, 5,
+    mc.click(mc.eid("button-appmenu"));
+    const subview = mc.click_appmenu_in_sequence(mc.e("appMenu-mainView"),
+      [ {id: "appmenu_File"},
+        {id: "appmenu_getNewMsgFor"} ]);
+
+    assert_equals(subview.children.length, 5,
                   "Incorrect number of items for GetNewMessages before customization");
 
-    mc.close_popup_sequence(popups);
+    // TODO appmenu - Now click somewhere that causes the appmenu to close.
+    // (Once this test is no longer skipped, see below.)
   }
 
   check_getAllNewMsgMenu();
 
   plan_for_new_window("mailnews:customizeToolbar");
   // Open the customization dialog.
   mc.rightClick(mc.eid("mail-bar3"));
   mc.click(mc.eid("CustomizeMailToolbar"));
@@ -114,16 +116,20 @@ function test_customize_toolbar_doesnt_d
   wait_for_window_focused(customc.window);
   plan_for_window_close(customc);
   customc.click(customc.eid("donebutton"));
   wait_for_window_close();
 
   check_getAllNewMsgMenu();
 }
 test_customize_toolbar_doesnt_double_get_mail_menu.EXCLUDED_PLATFORMS = ["darwin"];
+// TODO appmenu - Skipped because it depends on the folder-menupopup code being
+// adapted for use in the appmenu.  Namely the call to click_appmenu_in_sequence
+// won't work because the UI it expects will not be there yet.
+test_customize_toolbar_doesnt_double_get_mail_menu.__force_skip__ = true;
 
 /* A helper function that opens up the new filter dialog (assuming that the
  * main filters dialog is already open), creates a simple filter, and then
  * closes the dialog.
  */
 function create_simple_filter() {
   // Open the "Tools » Message Filters…" window,
   // a.k.a. "tasksMenu » filtersCmd".
--- a/mail/test/mozmill/shared-modules/test-window-helpers.js
+++ b/mail/test/mozmill/shared-modules/test-window-helpers.js
@@ -949,16 +949,47 @@ var AugmentEverybodyWith = {
     defer_click: function _augmented_defer_click(aWhatToClick) {
       let dis = this;
       dis.window.setTimeout(function() {
                               dis.click(aWhatToClick);
                             }, 1000);
     },
 
     /**
+     * Check if a node's attributes match all those given in actionObj.
+     * Nodes that are obvious containers are skipped, and their children
+     * will be used to recursively find a match instead.
+     *
+     * @param {Element} node      The node to check.
+     * @param {Object} actionObj  Contains attribute-value pairs to match.
+     * @return {Element|null}     The matched node or null if no match.
+     */
+    findMatch(node, actionObj) {
+      // Ignore some elements and just use their children instead.
+      if (node.localName == "hbox" || node.localName == "vbox") {
+        for (let i = 0; i < node.children.length; i++) {
+          let childMatch = this.findMatch(node.children[i]);
+          if (childMatch)
+            return childMatch;
+        }
+        return null;
+      }
+
+      let matchedAll = true;
+      for (let name in actionObj) {
+        let value = actionObj[name];
+        if (!node.hasAttribute(name) || node.getAttribute(name) != value) {
+          matchedAll = false;
+          break;
+        }
+      }
+      return matchedAll ? node : null;
+    },
+
+    /**
      * Dynamically-built/XBL-defined menus can be hard to work with, this makes it
      *  easier.
      *
      * @param aRootPopup  The base popup. The caller is expected to activate it
      *     (by clicking/rightclicking the right widget). We will only wait for it
      *     to open if it is in the process.
      * @param aActions  An array of objects where each object has attributes
      *     with a value defined. We pick the menu item whose DOM node matches
@@ -976,76 +1007,35 @@ var AugmentEverybodyWith = {
                              ", state=" + aRootPopup.state));
       }
       // These popups sadly do not close themselves, so we need to keep track
       // of them so we can make sure they end up closed.
       let closeStack = [aRootPopup];
 
       let curPopup = aRootPopup;
       for (let [iAction, actionObj] of aActions.entries()) {
-        /**
-         * Check if aNode attributes match all those given in actionObj.
-         * Nodes that are obvious containers are skipped, and their children
-         * will be used to recursively find a match instead.
-         */
-        let findMatch = function(aNode) {
-          // Ignore some elements and just use their children instead.
-          if (aNode.localName == "hbox" || aNode.localName == "vbox") {
-            for (let i = 0; i < aNode.children.length; i++) {
-              let childMatch = findMatch(aNode.children[i]);
-              if (childMatch)
-                return childMatch;
-            }
-            return null;
-          }
-
-          let matchedAll = true;
-          for (let name in actionObj) {
-            let value = actionObj[name];
-            if (!aNode.hasAttribute(name) ||
-                aNode.getAttribute(name) != value) {
-              matchedAll = false;
-              break;
-            }
-          }
-          return (matchedAll) ? aNode : null;
-        };
-
         let matchingNode = null;
         let kids = curPopup.children;
         for (let iKid = 0; iKid < kids.length; iKid++) {
           let node = kids[iKid];
-          matchingNode = findMatch(node);
+          matchingNode = this.findMatch(node, actionObj);
           if (matchingNode)
             break;
         }
 
         if (!matchingNode) {
           throw new Error("Did not find matching menu item for action index " +
                           iAction + ": " + JSON.stringify(actionObj));
         }
 
-        if ((matchingNode.localName == "splitmenu") &&
-            ((iAction < aActions.length - 1) || aKeepOpen)) {
-          // For splitmenus, click the submenu arrow to open its menupopup,
-          // unless this is the last item being searched for. In that case,
-          // click the main item.
-          this.click(new elib.Elem(matchingNode.menu));
-        } else {
-          this.click(new elib.Elem(matchingNode));
-        }
+        this.click(new elib.Elem(matchingNode));
 
         let newPopup = null;
         if ("menupopup" in matchingNode) {
           newPopup = matchingNode.menupopup;
-        } else if ((matchingNode.localName == "splitmenu") &&
-                   ("menupopup" in matchingNode.menu)) {
-          // We should actually fetch matchingNode.menu.menupopup here,
-          // but it doesn't seem to work.
-          newPopup = matchingNode.querySelector("menupopup");
         }
         if (newPopup) {
           curPopup = newPopup;
           closeStack.push(curPopup);
           utils.waitFor(() => curPopup.state == "open",
                         () => ("Popup never opened at action depth " + iAction +
                                "; id=" + curPopup.id + ", state=" + curPopup.state),
                         5000, 50);
@@ -1073,16 +1063,97 @@ var AugmentEverybodyWith = {
           this.keypress(new elib.Elem(curPopup), "VK_ESCAPE", {});
         utils.waitFor(() => curPopup.state == "closed",
                       () => ("Popup did not close! id=" + curPopup.id +
                              ", state=" + curPopup.state), 5000, 50);
       }
     },
 
     /**
+     * Click through the appmenu. Uses a recursive style approach with a
+     * sequence of event listeners handling "ViewShown" events. The `navTargets`
+     * parameter specifies items to click to navigate through the menu. The
+     * optional `nonNavTarget` parameter specifies a final item to click to
+     * perform a command after navigating through the menu. If this argument is
+     * omitted, callers can interact with the last view panel that is returned.
+     * Callers will then need to close the appmenu when they are done with it.
+     *
+     * @param {Element} mainView  The initial appmenu panelview, namely
+     *     <panelview id="appMenu-mainView">. The caller is expected to open it
+     *     (e.g. by clicking the appmenu button). We wait for it to open if it
+     *     isn't open yet.
+     * @param {Object[]} navTargets  Array of objects that contain
+     *     attribute->value pairs. We pick the menu item whose DOM node matches
+     *     all the attribute->value pairs. We click whatever we find. We throw
+     *     if the element being asked for is not found.
+     * @param {Object} [nonNavTarget]  Contains attribute->value pairs used
+     *                                 to identify a final menu item to click.
+     * @return {Element}  The <vbox class="panel-subview-body"> element inside
+     *                    the last shown <panelview>.
+     */
+    click_appmenu_in_sequence(mainView, navTargets, nonNavTarget) {
+      const rootPopup = this.e("appMenu-popup");
+      const controller = this;
+
+      function viewShownListener(navTargets, nonNavTarget, allDone, event) {
+        // Set up the next listener if there are more navigation targets.
+        if (navTargets.length > 0) {
+          rootPopup.addEventListener("ViewShown",
+            viewShownListener.bind(null, navTargets.slice(1), nonNavTarget, allDone),
+            {once: true});
+        }
+
+        const subview = event.target.querySelector(".panel-subview-body");
+
+        // Click a target if there is a target left to click.
+        const clickTarget = navTargets[0] || nonNavTarget;
+
+        if (clickTarget) {
+          const kids = Array.from(subview.children);
+          const findFunction = node => controller.findMatch(node, clickTarget);
+
+          // Some views are dynamically populated after ViewShown, so we wait.
+          utils.waitFor(
+            () => kids.find(findFunction),
+            () => "Waited but did not find matching menu item for target: " +
+                  JSON.stringify(clickTarget));
+
+          const foundNode = kids.find(findFunction);
+
+          controller.click(new elib.Elem(foundNode));
+        }
+
+        // We are all done when there are no more navigation targets.
+        if (navTargets.length == 0) {
+          allDone(subview);
+        }
+      }
+
+      let done = false;
+      let subviewToReturn;
+      const allDone = (subview) => {
+        subviewToReturn = subview;
+        done = true;
+      };
+
+      utils.waitFor(() => rootPopup.getAttribute("panelopen") == "true",
+        "Waited for the appmenu to open, but it never opened.");
+
+      // Because the appmenu button has already been clicked in the calling
+      // code (to match click_menus_in_sequence), we have to call the first
+      // viewShownListener manually, using a fake event argument, to start the
+      // series of event listener calls.
+      const fakeEvent = {target: mainView};
+      viewShownListener(navTargets, nonNavTarget, allDone, fakeEvent);
+
+      utils.waitFor(() => done, "Timed out in click_appmenu_in_sequence.");
+      return subviewToReturn;
+    },
+
+    /**
      * mark_action helper method that produces something that can be concat()ed
      *  onto a list being passed to mark_action in order to describe the focus
      *  state of the window.  For now this will be a variable-length list but
      *  could be changed to a single object in the future.
      */
     describeFocus() {
       let arr = [
         "in window:",
--- a/mail/themes/linux/customizableui/panelUI.css
+++ b/mail/themes/linux/customizableui/panelUI.css
@@ -1,13 +1,13 @@
 /* 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/. */
 
-%include ../../shared/customizableui/panelUI.inc.css
+@import url("chrome://messenger/skin/shared/customizableui/panelUI.css");
 
 #BMB_bookmarksPopup menupopup {
   -moz-appearance: none;
   background: var(--arrowpanel-background);
   color: var(--arrowpanel-color);
   border: 1px solid var(--arrowpanel-border-color);
   margin-top: -6px;
   padding-top: 1px;
--- a/mail/themes/linux/jar.mn
+++ b/mail/themes/linux/jar.mn
@@ -82,16 +82,17 @@ classic.jar:
   skin/classic/messenger/addressbook/icons/contact-generic.png             (mail/addrbook/contact-generic.png)
   skin/classic/messenger/addressbook/icons/contact-generic-tiny.png        (mail/addrbook/contact-generic-tiny.png)
   skin/classic/messenger/addressbook/icons/abcard-large.png   (mail/addrbook/abcard-large.png)
   skin/classic/messenger/addressbook/icons/remote-addrbook.png (mail/addrbook/remote-addrbook.png)
   skin/classic/messenger/addressbook/icons/remote-addrbook-error.png      (mail/addrbook/remote-addrbook-error.png)
   skin/classic/messenger/addressbook/icons/secure-remote-addrbook.png     (mail/addrbook/secure-remote-addrbook.png)
   skin/classic/messenger/messengercompose/messengercompose.css (mail/compose/messengercompose.css)
   skin/classic/messenger/downloads/aboutDownloads.css         (mail/downloads/aboutDownloads.css)
+  skin/classic/messenger/customizableui/panelUI.css           (customizableui/panelUI.css)
 % skin messenger-newsblog classic/1.0 %skin/classic/messenger-newsblog/
   skin/classic/messenger-newsblog/feed-subscriptions.css      (mail/newsblog/feed-subscriptions.css)
   skin/classic/messenger-newsblog/rss-feed.png                (mail/newsblog/rss-feed.png)
   skin/classic/messenger-newsblog/rss-feed-folder.png         (mail/newsblog/rss-feed-folder.png)
   skin/classic/messenger/preferences/alwaysAsk.png            (mail/preferences/alwaysAsk.png)
   skin/classic/messenger/preferences/preferences.css          (mail/preferences/preferences.css)
   skin/classic/messenger/preferences/applications.css         (mail/preferences/applications.css)
   skin/classic/messenger/preferences/dialog.css               (mail/preferences/dialog.css)
--- a/mail/themes/linux/mail/primaryToolbar.css
+++ b/mail/themes/linux/mail/primaryToolbar.css
@@ -211,35 +211,17 @@ toolbar[mode="text"] .button-appmenu .to
 
 .msgNotificaton-smallText {
   padding-inline-start: 10px;
   font-size: 90%;
 }
 
 /* AppMenu styling */
 
-.splitmenu-menuitem {
-  -moz-appearance: menuitem;
-  -moz-box-align: center;
-  max-width: 42em;
-  color: MenuText;
-  font: menu;
-  list-style-image: none;
-  margin-inline-end: 1px;
-  -moz-image-region: auto;
-}
-
-.splitmenu-menuitem[_moz-menuactive="true"] {
-  color: -moz-menuhovertext;
-  background-color: -moz-menuhover;
-}
-
-.splitmenu-menuitem[disabled="true"] {
-  color: GrayText;
-}
+/* TODO appmenu - remove? needed? */
 
 #appmenuSecondaryPane {
   border-inline-start: 1px solid ThreeDShadow;
 }
 
 .appmenuPane-spacer {
   min-height: 1em;
 }
@@ -289,21 +271,17 @@ toolbar[mode="text"] .button-appmenu .to
 
 #appmenu-quit {
   list-style-image: url("chrome://messenger/skin/icons/quit.svg");
 }
 
 #appmenu_find {
   list-style-image: url("chrome://messenger/skin/icons/search-glass.svg");
 }
-/*
-#appmenu_find > .splitmenu-menuitem {
-  -moz-binding: url("chrome://global/content/bindings/menu.xml#menuitem-iconic");
-}
-*/
+
 #appmenu_addons {
   list-style-image: url("chrome://mozapps/skin/extensions/extensionGeneric-16.svg");
 }
 
 #appmenu_openHelp {
   list-style-image: url(chrome://global/skin/icons/help.svg);
 }
 
--- a/mail/themes/osx/customizableui/panelUI.css
+++ b/mail/themes/osx/customizableui/panelUI.css
@@ -1,13 +1,13 @@
 /* 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/. */
 
-%include ../../shared/customizableui/panelUI.inc.css
+@import url("chrome://messenger/skin/shared/customizableui/panelUI.css");
 
 .restoreallitem > .toolbarbutton-icon {
   display: none;
 }
 
 .subviewbutton {
   padding-inline-start: 18px;
 }
@@ -84,19 +84,23 @@ menu.subviewbutton > .menu-right {
 .panel-button {
   -moz-appearance: none;
   border-radius: 2px;
   background-color: var(--arrowpanel-dimmed);
   color: inherit;
   padding: 2px 6px;
 }
 
-.panel-button@buttonStateHover@ {
+/* With original pre-processor step:
+   .panel-button@buttonStateHover@ */
+.panel-button:not(:-moz-any([disabled],[open],:active)):-moz-any(:hover,:focus) {
   background-color: var(--arrowpanel-dimmed-further);
 }
 
-.panel-button@buttonStateActive@ {
-  background-color: var(--arrowpanel-dimmed-even-further);
+/* With original pre-processor step:
+   .panel-button@buttonStateActive@ */
+.panel-button:not([disabled]):-moz-any([open],:hover:active) {
+   background-color: var(--arrowpanel-dimmed-even-further);
 }
 
 .panel-button:-moz-focusring {
   box-shadow: var(--focus-ring-box-shadow);
 }
--- a/mail/themes/osx/jar.mn
+++ b/mail/themes/osx/jar.mn
@@ -99,16 +99,17 @@ classic.jar:
   skin/classic/messenger/messengercompose/emoticon_wink.png       (mail/compose/emoticon_wink.png)
   skin/classic/messenger/messengercompose/emoticon_yell.png       (mail/compose/emoticon_yell.png)
   skin/classic/messenger/messengercompose/emotes@2x.png           (mail/compose/emotes@2x.png)
   skin/classic/messenger/messengercompose/format-buttons.png      (mail/compose/format-buttons.png)
   skin/classic/messenger/messengercompose/format-buttons@2x.png   (mail/compose/format-buttons@2x.png)
   skin/classic/messenger/messengercompose/insert-menu.png         (mail/compose/insert-menu.png)
   skin/classic/messenger/messengercompose/insert-menu@2x.png      (mail/compose/insert-menu@2x.png)
   skin/classic/messenger/downloads/aboutDownloads.css             (mail/downloads/aboutDownloads.css)
+  skin/classic/messenger/customizableui/panelUI.css               (customizableui/panelUI.css)
 % skin messenger-newsblog classic/1.0 %skin/classic/messenger-newsblog/
   skin/classic/messenger-newsblog/feed-subscriptions.css         (mail/newsblog/feed-subscriptions.css)
   skin/classic/messenger-newsblog/rss-feed.png                   (mail/newsblog/rss-feed.png)
   skin/classic/messenger-newsblog/rss-feed@2x.png                (mail/newsblog/rss-feed@2x.png)
   skin/classic/messenger-newsblog/rss-feed-folder.png            (mail/newsblog/rss-feed-folder.png)
   skin/classic/messenger-newsblog/rss-feed-folder@2x.png         (mail/newsblog/rss-feed-folder@2x.png)
   skin/classic/messenger/preferences/alwaysAsk.png               (mail/preferences/alwaysAsk.png)
   skin/classic/messenger/preferences/application.png             (mail/preferences/application.png)
--- a/mail/themes/osx/mail/primaryToolbar.css
+++ b/mail/themes/osx/mail/primaryToolbar.css
@@ -239,53 +239,17 @@ toolbar[mode="text"] .button-appmenu .to
 
 .msgNotification-smallText {
   padding-inline-start: 10px;
   font-size: 90%;
 }
 
 /* AppMenu styling */
 
-.splitmenu-menuitem {
-  -moz-appearance: menuitem;
-  -moz-box-align: center;
-  color: MenuText;
-  font: -moz-pull-down-menu;
-  list-style-image: none;
-  -moz-image-region: auto;
-  margin-inline-end: 1px;
-  padding-bottom: 2px;
-  padding-inline-start: 10px;
-  padding-inline-end: 0;
-}
-
-.splitmenu-menuitem[_moz-menuactive="true"] {
-  color: -moz-mac-menutextselect;
-  background-color: Highlight;
-}
-
-.splitmenu-menuitem[disabled="true"],
-.splitmenu-menu[_moz-menuactive="true"][disabled="true"],
-.splitmenu-menuitem[_moz-menuactive="true"][disabled="true"] {
-  color: -moz-mac-menutextdisable;
-  background-color: transparent;
-}
-
-.splitmenu-menuitem[iconic="true"] {
-  /* 2px higher than those without icons */
-  padding-top: 1px;
-  padding-bottom: 3px;
-  list-style-image: inherit;
-  -moz-image-region: inherit;
-}
-
-.splitmenu-menuitem[iconic="true"] > .menu-iconic-left > .menu-iconic-icon {
-  margin-inline-start: 0;
-  width: 16px;
-}
+/* TODO appmenu - remove? needed? */
 
 .appmenu-edit-button {
   -moz-appearance: none;
   border-width: 0;
   padding: 0 2px;
 }
 
 .appmenu-edit-button[disabled="true"] {
@@ -328,40 +292,20 @@ toolbar[mode="text"] .button-appmenu .to
   padding-inline-end: 15px;
 }
 
 .appmenuPane-spacer {
   min-height: 1em;
 }
 
 #appmenuSecondaryPane > :-moz-any(menu, menuitem):not([_moz-menuactive]),
-#appmenuSecondaryPane > :-moz-any(menu, menuitem)[_moz-menuactive][disabled],
-#appmenuSecondaryPane > splitmenu >
-  :-moz-any(.splitmenu-menu, .splitmenu-menuitem):not([_moz-menuactive]) {
+#appmenuSecondaryPane > :-moz-any(menu, menuitem)[_moz-menuactive][disabled] {
   background-color: transparent;
 }
 
-.splitmenu-menu,
-#appmenu-editmenu {
-  -moz-box-pack: end;
-  padding-inline-start: 5px;
-  padding-inline-end: 15px;
-}
-
-.splitmenu-menu > .menu-accel-container,
-#appmenu-editmenu > .menu-accel-container {
-  margin: 0;
-}
-
-.splitmenu-menu > .menu-right,
-#appmenu-editmenu > .menu-right {
-  margin-inline-start: 5px;
-}
-
-.splitmenu-menuitem > .menu-iconic-left,
 #appmenu-popup
   menuitem:not([type="radio"]):not([type="checkbox"]):not(.folderMenuItem) >
   .menu-iconic-left {
   display: none;
 }
 
 .appmenu-edit-button {
   -moz-context-properties: fill, fill-opacity;
rename from mail/themes/shared/customizableui/panelUI.inc.css
rename to mail/themes/shared/customizableui/panelUI.css
--- a/mail/themes/shared/customizableui/panelUI.inc.css
+++ b/mail/themes/shared/customizableui/panelUI.css
@@ -1,41 +1,39 @@
 /* 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/. */
 
-%filter substitution
+:root {
+  --menu-panel-width: 22.35em;
+  --wide-menu-panel-width: 29em;
+  --standalone-subview-width: 30em;
+  --panel-palette-icon-size: 16px;
+
+  /* XXXgijs This is the ugliest bit of code I think I've ever written for Mozilla.
+  Basically, the [extra 0.1px in the 1.1px] is there to avoid CSS rounding errors
+  causing buttons to wrap. For gory details, refer to
+  https://bugzilla.mozilla.org/show_bug.cgi?id=963365#c11 */
+  --menu-panel-button-width: calc(--menu-panel-width / 3 - 1.1px);
 
-%define menuPanelWidth 22.35em
-%define wideMenuPanelWidth 29em
-%define standaloneSubviewWidth 30em
-% XXXgijs This is the ugliest bit of code I think I've ever written for Mozilla.
-% Basically, the 0.1px is there to avoid CSS rounding errors causing buttons to wrap.
-% For gory details, refer to https://bugzilla.mozilla.org/show_bug.cgi?id=963365#c11
-% There's no calc() here (and therefore lots of calc() where this is used) because
-% we don't support nested calc(): https://bugzilla.mozilla.org/show_bug.cgi?id=968761
-%define menuPanelButtonWidth (@menuPanelWidth@ / 3 - 0.1px)
-%define buttonStateHover :not(:-moz-any([disabled],[open],:active)):-moz-any(:hover,:focus)
-%define menuStateHover :not(:-moz-any([disabled],:active))[_moz-menuactive]
-%define buttonStateActive :not([disabled]):-moz-any([open],:hover:active)
-%define menuStateActive :not([disabled])[_moz-menuactive]:active
-%define menuStateMenuActive :not([disabled])[_moz-menuactive]
-%define inAnyPanel :-moz-any(:not([cui-areatype="toolbar"]), [overflowedItem=true])
-%define panelPaletteIconSize 16px
+  --appmenu-warning-background-color: #FFEFBF;
+  --appmenu-warning-background-color-hover: #FFE8A2;
+  --appmenu-warning-background-color-active: #FFE38F;
+  --appmenu-warning-color: black;
+  --appmenu-warning-border-color: hsl(45,100%,77%);
+  --appmenu-warning-background-color-bright-text: hsla(55,100%,50%,.1);
+  --appmenu-warning-backgound-color-hover-bright-text: hsla(55,100%,50%,.15);
+  --appmenu-warning-background-color-active-bright-text: hsla(55,100%,50%,.2);
+  --appmenu-warning-color-bright-text: #F9F9FA;
+}
 
-%define appmenuWarningBackgroundColor #FFEFBF
-%define appmenuWarningBackgroundColorHover #FFE8A2
-%define appmenuWarningBackgroundColorActive #FFE38F
-%define appmenuWarningColor black
-%define appmenuWarningBorderColor hsl(45,100%,77%)
-
-%define appmenuWarningBackgroundColorBrightText hsla(55,100%,50%,.1)
-%define appmenuWarningBackgroundColorHoverBrightText hsla(55,100%,50%,.15)
-%define appmenuWarningBackgroundColorActiveBrightText hsla(55,100%,50%,.2)
-%define appmenuWarningColorBrightText #F9F9FA
+/* In mozilla-central the following variables are defined, but they are simply
+   inlined below because we aren't using a pre-processing step. */
+/* %define menuStateMenuActive :not([disabled])[_moz-menuactive] */
+/* %define inAnyPanel :-moz-any(:not([cui-areatype="toolbar"]), [overflowedItem=true]) */
 
 :root:not([uidensity=compact]):not([chromehidden~="toolbar"]) #PanelUI-button {
   margin-inline-start: 3px;
   border-inline-start: 1px solid;
   border-image: linear-gradient(
     transparent 4px,
     var(--lwt-toolbar-vertical-separator, rgba(0,0,0,.1)) 4px,
     var(--lwt-toolbar-vertical-separator, rgba(0,0,0,.1)) calc(100% - 4px),
@@ -48,16 +46,22 @@
   border-image-source: linear-gradient(
     transparent 4px,
     var(--lwt-toolbar-vertical-separator, rgba(255,255,255,.2)) 4px,
     var(--lwt-toolbar-vertical-separator, rgba(255,255,255,.2)) calc(100% - 4px),
     transparent calc(100% - 4px)
   );
 }
 
+/* TODO appmenu - added, more needed? */
+panelview:not([visible]) {
+  visibility: collapse;
+}
+
+/* TODO appmenu - "PanelUI-menu-button" is not used as an id in Thunderbird.
 #PanelUI-menu-button[badge-status] > .toolbarbutton-badge-stack > .toolbarbutton-badge {
   display: -moz-box;
   height: 10px;
   width: 10px;
   background-size: contain;
   border: none;
 }
 
@@ -67,22 +71,25 @@
 }
 
 #PanelUI-menu-button[badge-status="update-available"] > .toolbarbutton-badge-stack > .toolbarbutton-badge,
 #PanelUI-menu-button[badge-status="update-manual"] > .toolbarbutton-badge-stack > .toolbarbutton-badge,
 #PanelUI-menu-button[badge-status="update-restart"] > .toolbarbutton-badge-stack > .toolbarbutton-badge,
 #PanelUI-menu-button[badge-status="update-unsupported"] > .toolbarbutton-badge-stack > .toolbarbutton-badge {
   border-radius: 50%;
   box-shadow: none;
+  */
   /* "!important" is necessary to override the rule in toolbarbutton.css */
+  /*
   margin: -7px 0 0 !important;
   margin-inline-end: -4px !important;
   min-width: 12px;
   min-height: 12px;
 }
+*/
 
 #PanelUI-menu-button[badge-status="update-available"] > .toolbarbutton-badge-stack > .toolbarbutton-badge,
 #PanelUI-menu-button[badge-status="update-manual"] > .toolbarbutton-badge-stack > .toolbarbutton-badge,
 #PanelUI-menu-button[badge-status="update-restart"] > .toolbarbutton-badge-stack > .toolbarbutton-badge {
   background: #74BF43 url(chrome://browser/skin/update-badge.svg) no-repeat center;
 }
 
 #PanelUI-menu-button[badge-status="update-unsupported"] > .toolbarbutton-badge-stack > .toolbarbutton-badge {
@@ -100,36 +107,41 @@
   background: #FFE900 url(chrome://browser/skin/update-badge.svg) no-repeat center;
   border-radius: 50%;
 }
 
 .panel-banner-item[notificationid^=update] {
   list-style-image: url(chrome://branding/content/icon16.png);
 }
 
+/* TODO appmenu - "PanelUI-menu-button" is not used as an id in Thunderbird.
+/*
 #PanelUI-menu-button[badge-status="addon-alert"] > .toolbarbutton-badge-stack > .toolbarbutton-badge,
 #PanelUI-menu-button[badge-status="fxa-needs-authentication"] > .toolbarbutton-badge-stack > .toolbarbutton-badge {
   height: 13px;
   background: url(chrome://browser/skin/warning.svg) center / contain no-repeat transparent;
   box-shadow: none;
   border-radius: 0;
+  */
   /* Use the included fallbacks defined in the SVG file instead of inheriting from .toolbarbutton-1. */
+  /*
   -moz-context-properties: none;
 }
 
 #PanelUI-menu-button[badge-status] > .toolbarbutton-badge-stack > .toolbarbutton-badge:-moz-window-inactive {
   filter: grayscale(100%);
 }
 
 #nav-bar[brighttext] #PanelUI-menu-button[badge-status="addon-alert"] > .toolbarbutton-badge-stack > .toolbarbutton-badge,
 #nav-bar[brighttext] #PanelUI-menu-button[badge-status="fxa-needs-authentication"] > .toolbarbutton-badge-stack > .toolbarbutton-badge {
   -moz-context-properties: fill, stroke;
   fill: #FFE900;
   stroke: transparent;
 }
+*/
 
 .cui-widget-panel,
 #widget-overflow {
   font: menu;
 }
 
 panelview {
   -moz-box-orient: vertical;
@@ -232,18 +244,28 @@ panel[photon] > .panel-arrowcontainer > 
   padding: 0;
 }
 
 #wrapper-edit-controls:-moz-any([place="palette"],[place="menu-panel"]) > #edit-controls,
 #wrapper-zoom-controls:-moz-any([place="palette"],[place="menu-panel"]) > #zoom-controls {
   margin-inline-start: 0;
 }
 
+#appmenu-edit-button {
+  margin-inline-start: 0;
+  padding-inline-end: 7px;
+  padding-inline-start: 7px;
+}
+
+#appmenu-edit-button::after {
+  margin-inline-start: 0;
+}
+
 #BMB_bookmarksPopup {
-  max-width: @standaloneSubviewWidth@;
+  max-width: var(--standalone-subview-width);
 }
 
 #confirmation-hint {
   --arrowpanel-background: #0060df;
   --arrowpanel-border-color: #0060df;
   --arrowpanel-color: #fff;
 }
 
@@ -353,37 +375,37 @@ panelview:not([mainview]) .toolbarbutton
 
 #appMenu-popup > .panel-arrowcontainer > .panel-arrowcontent,
 panel[photon] > .panel-arrowcontainer > .panel-arrowcontent {
   padding: 0;
 }
 
 #appMenu-popup panelview,
 #customizationui-widget-multiview panelview:not([extension]) {
-  min-width: @menuPanelWidth@;
+  min-width: var(--menu-panel-width);
   max-width: 35em;
 }
 
 #customizationui-widget-multiview #appMenu-libraryView,
 #pageActionPanel panelview,
 #widget-overflow panelview {
-  min-width: @wideMenuPanelWidth@;
-  max-width: @wideMenuPanelWidth@;
+  min-width: var(--wide-menu-panel-width);
+  max-width: var(--wide-menu-panel-width);
 }
 
 /* Add 2 * 16px extra width for touch mode button padding. */
 #appMenu-popup[touchmode] panelview {
-  min-width: calc(@menuPanelWidth@ + 32px);
+  min-width: calc(var(--menu-panel-width) + 32px);
 }
 
 .cui-widget-panel.cui-widget-panelWithFooter > .panel-arrowcontainer > .panel-arrowcontent {
   padding-bottom: 0;
 }
 
-.toolbaritem-combined-buttons@inAnyPanel@ > toolbarbutton > .toolbarbutton-icon {
+.toolbaritem-combined-buttons:-moz-any(:not([cui-areatype="toolbar"]), [overflowedItem=true]) > toolbarbutton > .toolbarbutton-icon {
   min-width: 0;
   min-height: 0;
   margin: 0;
 }
 
 .animate-out {
   animation-name: widget-animate-out;
   animation-fill-mode: forwards;
@@ -406,35 +428,35 @@ toolbarpaletteitem[place="menu-panel"] >
   -moz-box-flex: 1;
 }
 
 /* Help webextension buttons fit in. */
 toolbarpaletteitem[place="palette"] > toolbarbutton[constrain-size="true"] > .toolbarbutton-icon,
 toolbarpaletteitem[place="palette"] > toolbarbutton[constrain-size="true"] > .toolbarbutton-badge-stack > .toolbarbutton-icon,
 toolbarbutton[constrain-size="true"][cui-areatype="menu-panel"] > .toolbarbutton-icon,
 toolbarbutton[constrain-size="true"][cui-areatype="menu-panel"] > .toolbarbutton-badge-stack > .toolbarbutton-icon {
-  height: @panelPaletteIconSize@;
-  width: @panelPaletteIconSize@;
+  height: var(--panel-palette-icon-size);
+  width: var(--panel-palette-icon-size);
 }
 
 #customization-palette .toolbarbutton-1 {
   -moz-appearance: none;
   -moz-box-orient: vertical;
   padding: 12px 0 9px;
   margin: 0;
 }
 
 /* above we treat the container as the icon for the margins, that is so the
 /* badge itself is positioned correctly. Here we make sure that the icon itself
 /* has the minimum size we want, but no padding/margin. */
 .customization-palette .toolbarbutton-1 > .toolbarbutton-badge-stack > .toolbarbutton-icon {
-  width: @panelPaletteIconSize@;
-  height: @panelPaletteIconSize@;
-  min-width: @panelPaletteIconSize@;
-  min-height: @panelPaletteIconSize@;
+  width: var(--panel-palette-icon-size);
+  height: var(--panel-palette-icon-size);
+  min-width: var(--panel-palette-icon-size);
+  min-height: var(--panel-palette-icon-size);
   margin: 0;
   padding: 0;
 }
 
 #zoom-in-button > .toolbarbutton-text,
 #zoom-out-button > .toolbarbutton-text,
 #zoom-reset-button > .toolbarbutton-icon {
   display: none;
@@ -446,39 +468,39 @@ toolbarbutton[constrain-size="true"][cui
   width: 16px;
   height: 16px;
   margin-inline-start: 10px;
   margin-inline-end: 12px;
   display: -moz-box;
 }
 
 .addon-banner-item {
-  background-color: @appmenuWarningBackgroundColor@;
-  color: @appmenuWarningColor@;
+  background-color: var(--appmenu-warning-background-color);
+  color: var(--appmenu-warning-color);
   /* Force border to override `.addon-banner-item` selector below */
-  border-top: 1px solid @appmenuWarningBorderColor@ !important;
+  border-top: 1px solid var(--appmenu-warning-border-color) !important;
   display: flex;
   flex: 1 1 0%;
-  width: calc(@menuPanelWidth@ + 30px);
+  width: calc(var(--menu-panel-width) + 30px);
   padding-inline-start: 15px;
   border-inline-start-style: none;
   -moz-image-region: rect(0, 16px, 16px, 0);
 }
 
 .addon-banner-item:last-child {
-  border-bottom: 1px solid @appmenuWarningBorderColor@;
+  border-bottom: 1px solid var(--appmenu-warning-border-color);
 }
 
 .addon-banner-item:focus,
 .addon-banner-item:hover {
-  background-color: @appmenuWarningBackgroundColorHover@;
+  background-color: var(--appmenu-warning-background-color-hover);
 }
 
 .addon-banner-item:hover:active {
-  background-color: @appmenuWarningBackgroundColorActive@;
+  background-color: var(--appmenu-warning-background-color-active);
 }
 
 .addon-banner-item > .toolbarbutton-icon {
   width: 16px;
   height: 16px;
 }
 
 .addon-banner-item::after {
@@ -591,30 +613,30 @@ toolbarbutton[constrain-size="true"][cui
 #appMenu-fxa-container[fxastatus="unverified"] > #appMenu-fxa-status > #appMenu-fxa-label,
 #appMenu-fxa-container[fxastatus="login-failed"] > #appMenu-fxa-status > #appMenu-fxa-label {
   list-style-image: url(chrome://browser/skin/warning.svg);
   -moz-image-region: rect(0, 16px, 16px, 0);
 }
 
 #appMenu-fxa-container[fxastatus="login-failed"],
 #appMenu-fxa-container[fxastatus="unverified"] {
-  background-color: @appmenuWarningBackgroundColor@;
-  color: @appmenuWarningColor@;
-  border-top: 1px solid @appmenuWarningBorderColor@;
-  border-bottom: 1px solid @appmenuWarningBorderColor@;
+  background-color: var(--appmenu-warning-background-color);
+  color: var(--appmenu-warning-color);
+  border-top: 1px solid var(--appmenu-warning-border-color);
+  border-bottom: 1px solid var(--appmenu-warning-border-color);
 }
 
 #appMenu-fxa-container[fxastatus="login-failed"] > #appMenu-fxa-status:hover,
 #appMenu-fxa-container[fxastatus="unverified"] > #appMenu-fxa-status:hover {
-  background-color: @appmenuWarningBackgroundColorHover@;
+  background-color: var(--appmenu-warning-background-color-hover);
 }
 
 #appMenu-fxa-container[fxastatus="login-failed"] > #appMenu-fxa-status:hover:active,
 #appMenu-fxa-container[fxastatus="unverified"] > #appMenu-fxa-status:hover:active {
-  background-color: @appmenuWarningBackgroundColorActive@;
+  background-color: var(--appmenu-warning-background-color-active);
 }
 
 /* Tracking Protection Button & Toggle */
 
 #appMenu-tp-label {
   -moz-context-properties: fill;
   fill: currentColor;
   -moz-box-flex: 1;
@@ -649,46 +671,46 @@ toolbarbutton[constrain-size="true"][cui
 
 .addon-banner-item {
   flex: 1;
   padding-inline-start: 15px;
   border-inline-start-style: none;
 }
 
 :root[lwt-popup-brighttext] .addon-banner-item {
-  color: @appmenuWarningColorBrightText@;
-  background: @appmenuWarningBackgroundColorBrightText@;
+  color: var(--appmenu-warning-color-bright-text);
+  background: var(--appmenu-warning-background-color-bright-text);
   /* override `.addon-banner-item` border-top !important defined above */
   border: 0 !important;
 }
 
 :root[lwt-popup-brighttext] .addon-banner-item:hover,
 :root[lwt-popup-brighttext] .addon-banner-item:focus {
-  background: @appmenuWarningBackgroundColorHoverBrightText@;
+  background: var(--appmenu-warning-backgound-color-hover-bright-text);
 }
 
 :root[lwt-popup-brighttext] .addon-banner-item:hover:active,
 :root[lwt-popup-brighttext] .addon-banner-item:focus:active {
-  background: @appmenuWarningBackgroundColorActiveBrightText@;
+  background: var(--appmenu-warning-background-color-active-bright-text);
 }
 
 :root[lwt-popup-brighttext] #appMenu-fxa-container[fxastatus="login-failed"],
 :root[lwt-popup-brighttext] #appMenu-fxa-container[fxastatus="unverified"] {
-  background-color: @appmenuWarningBackgroundColorBrightText@;
-  color: @appmenuWarningColorBrightText@;
+  background-color: var(--appmenu-warning-background-color-bright-text);
+  color: var(--appmenu-warning-color-bright-text);
 }
 
 :root[lwt-popup-brighttext] #appMenu-fxa-container[fxastatus="login-failed"] > #appMenu-fxa-status:hover,
 :root[lwt-popup-brighttext] #appMenu-fxa-container[fxastatus="unverified"] > #appMenu-fxa-status:hover {
-  background-color: @appmenuWarningBackgroundColorHoverBrightText@;
+  background-color: var(--appmenu-warning-backgound-color-hover-bright-text)
 }
 
 :root[lwt-popup-brighttext] #appMenu-fxa-container[fxastatus="login-failed"] > #appMenu-fxa-status:hover:active,
 :root[lwt-popup-brighttext] #appMenu-fxa-container[fxastatus="unverified"] > #appMenu-fxa-status:hover:active {
-  background-color: @appmenuWarningBackgroundColorActiveBrightText@;
+  background-color: var(--appmenu-warning-background-color-active-bright-text);
 }
 
 /* Firefox Account Toolbar Panel */
 
 #fxa-avatar-image {
   width: 16px;
   height: 16px;
 }
@@ -744,21 +766,24 @@ toolbarbutton[constrain-size="true"][cui
   font-weight: normal;
   padding: .6em 0 .6em;
 }
 
 .PanelUI-fxa-signin-instruction-label {
   /* Use 'lighter' font for this to de-emphasize it compared to the title.
    * We use 300 on Linux because 100 is too light (lacks contrast with
    * the background) for some fonts in combination with anti-aliasing. */
-%if defined(XP_MACOSX) || defined(XP_WIN)
+
+/* TODO appmenu */
+/* %if defined(XP_MACOSX) || defined(XP_WIN)
   font-weight: lighter;
-%else
+%else */
   font-weight: 300;
-%endif
+/* %endif */
+
 }
 
 .fxa-avatar-subpanel {
   padding-top: 8px;
   padding-bottom: 4px;
 }
 
 .fxa-avatar-subpanel-description {
@@ -1103,17 +1128,17 @@ panelview .toolbarbutton-1,
 
 .subviewbutton[shortcut]::after {
   content: attr(shortcut);
   float: right;
 }
 
 .PanelUI-subView .subviewbutton-nav::after {
   -moz-context-properties: fill, fill-opacity;
-  content: url(chrome://browser/skin/back-12.svg);
+  content: url("chrome://messenger/skin/icons/back-12.svg");
   fill: currentColor;
   fill-opacity: 0.6;
   float: right;
   transform: translateY(1px);
 }
 
 #main-window:not([customizing]) .subviewbutton-nav[disabled=true]::after {
   opacity: 0.4;
@@ -1154,17 +1179,17 @@ panelview .toolbarbutton-1,
   color: inherit;
 }
 
 #appMenu-popup .toolbaritem-combined-buttons {
   -moz-box-align: center;
   -moz-box-orient: horizontal;
   border: 0;
   border-radius: 0;
-  margin-inline-end: 8px;
+  margin-inline-end: 6px;
 }
 
 panelmultiview .toolbaritem-combined-buttons > label {
   -moz-box-flex: 1;
   margin: 0;
   padding: 4px 0px;
 }
 
@@ -1193,21 +1218,21 @@ panelmultiview .toolbaritem-combined-but
 #appMenu-zoomReset-button {
   min-height: unset;
   border: 1px solid var(--panel-separator-color);
   border-radius: 10000px;
   padding: 1px 8px;
   background-color: var(--arrowpanel-dimmed);
 }
 
-#appMenu-zoomReset-button@buttonStateHover@ {
+#appMenu-zoomReset-button:not(:-moz-any([disabled],[open],:active)):-moz-any(:hover,:focus) {
   background-color: var(--arrowpanel-dimmed-further);
 }
 
-#appMenu-zoomReset-button@buttonStateActive@ {
+#appMenu-zoomReset-button:not([disabled]):-moz-any([open],:hover:active) {
   background-color: var(--arrowpanel-dimmed-even-further);
 }
 
 #appMenu-zoomReset-button > .toolbarbutton-text {
   min-width: calc(3ch + 8px);
   text-align: center;
 }
 
@@ -1227,53 +1252,53 @@ panelmultiview .toolbaritem-combined-but
 .subview-subheader {
   color: var(--panel-disabled-color);
 }
 
 panelview .toolbarbutton-1 {
   margin-top: 6px;
 }
 
-panelview .toolbarbutton-1@buttonStateHover@,
-toolbarbutton.subviewbutton@buttonStateHover@,
-.navigable.subviewbutton@buttonStateHover@,
-menu.subviewbutton@menuStateHover@,
-menuitem.subviewbutton@menuStateHover@,
-.widget-overflow-list .toolbarbutton-1@buttonStateHover@,
-.toolbaritem-combined-buttons@inAnyPanel@ > toolbarbutton@buttonStateHover@ {
+panelview .toolbarbutton-1:not(:-moz-any([disabled],[open],:active)):-moz-any(:hover,:focus),
+toolbarbutton.subviewbutton:not(:-moz-any([disabled],[open],:active)):-moz-any(:hover,:focus),
+.navigable.subviewbutton:not(:-moz-any([disabled],[open],:active)):-moz-any(:hover,:focus),
+menu.subviewbutton:not(:-moz-any([disabled],:active))[_moz-menuactive],
+menuitem.subviewbutton:not(:-moz-any([disabled],:active))[_moz-menuactive],
+.widget-overflow-list .toolbarbutton-1:not(:-moz-any([disabled],[open],:active)):-moz-any(:hover,:focus),
+.toolbaritem-combined-buttons:-moz-any(:not([cui-areatype="toolbar"]), [overflowedItem=true]) > toolbarbutton:not(:-moz-any([disabled],[open],:active)):-moz-any(:hover,:focus) {
   color: inherit;
   background-color: var(--arrowpanel-dimmed);
 }
 
-panelview .toolbarbutton-1@buttonStateActive@,
-toolbarbutton.subviewbutton@buttonStateActive@,
-.navigable.subviewbutton@buttonStateActive@,
-menu.subviewbutton@menuStateActive@,
-menuitem.subviewbutton@menuStateActive@,
-.widget-overflow-list .toolbarbutton-1@buttonStateActive@,
-.toolbaritem-combined-buttons@inAnyPanel@ > toolbarbutton@buttonStateActive@ {
+panelview .toolbarbutton-1:not([disabled]):-moz-any([open],:hover:active),
+toolbarbutton.subviewbutton:not([disabled]):-moz-any([open],:hover:active),
+.navigable.subviewbutton:not([disabled]):-moz-any([open],:hover:active),
+menu.subviewbutton:not([disabled])[_moz-menuactive]:active,
+menuitem.subviewbutton:not([disabled])[_moz-menuactive]:active,
+.widget-overflow-list .toolbarbutton-1:not([disabled]):-moz-any([open],:hover:active),
+.toolbaritem-combined-buttons:-moz-any(:not([cui-areatype="toolbar"]), [overflowedItem=true]) > toolbarbutton:not([disabled]):-moz-any([open],:hover:active) {
   color: inherit;
   background-color: var(--arrowpanel-dimmed-further);
   box-shadow: 0 1px 0 hsla(210,4%,10%,.03) inset;
 }
 
 .subviewbutton.panel-subview-footer {
   margin: 0;
   background-color: var(--arrowpanel-dimmed);
   border-top: 1px solid var(--panel-separator-color);
   border-radius: 0;
 }
 
-menuitem.panel-subview-footer@menuStateHover@,
-.subviewbutton.panel-subview-footer@buttonStateHover@ {
+menuitem.panel-subview-footer:not(:-moz-any([disabled],:active))[_moz-menuactive],
+.subviewbutton.panel-subview-footer:not(:-moz-any([disabled],[open],:active)):-moz-any(:hover,:focus) {
   background-color: var(--arrowpanel-dimmed-further);
 }
 
-menuitem.panel-subview-footer@menuStateActive@,
-.subviewbutton.panel-subview-footer@buttonStateActive@ {
+menuitem.panel-subview-footer:not([disabled])[_moz-menuactive]:active,
+.subviewbutton.panel-subview-footer:not([disabled]):-moz-any([open],:hover:active) {
   background-color: var(--arrowpanel-dimmed-even-further);
   box-shadow: 0 1px 0 hsla(210,4%,10%,.05) inset;
 }
 
 #BMB_bookmarksPopup .subviewbutton:not([disabled="true"]) {
   color: inherit;
 }
 
@@ -1397,85 +1422,88 @@ toolbarpaletteitem[place="palette"] > .t
 
 toolbarpaletteitem[place="palette"] > #search-container {
   min-width: 7em;
   width: 7em;
   min-height: 37px;
   max-height: 37px;
 }
 
-.toolbaritem-combined-buttons@inAnyPanel@ > toolbarbutton {
+.toolbaritem-combined-buttons:-moz-any(:not([cui-areatype="toolbar"]), [overflowedItem=true]) > toolbarbutton {
   border: 0;
   margin: 0;
   -moz-box-flex: 1;
   padding-top: 4px;
   padding-bottom: 4px;
   -moz-box-orient: horizontal;
 }
 
 /* In customize mode, extend the buttons *only* in the panel, just to make them not look stupid */
 toolbarpaletteitem[place="menu-panel"] > .toolbaritem-combined-buttons > toolbarbutton {
-  min-width: calc(@menuPanelButtonWidth@ - 1px);
-  max-width: calc(@menuPanelButtonWidth@ - 1px);
+  min-width: var(--menu-panel-button-width);
+  max-width: var(--menu-panel-button-width);
 }
 
-.toolbaritem-combined-buttons@inAnyPanel@ > toolbarbutton:not(.toolbarbutton-1)[disabled] {
+.toolbaritem-combined-buttons:-moz-any(:not([cui-areatype="toolbar"]), [overflowedItem=true]) > toolbarbutton:not(.toolbarbutton-1)[disabled] {
   opacity: 0.4;
   /* Override toolbarbutton.css which sets the color to GrayText */
   color: inherit;
 }
 
 #zoom-controls[cui-areatype="toolbar"] > #zoom-reset-button > .toolbarbutton-text {
-%ifdef XP_MACOSX
+
+/* TODO appmenu */
+/* %ifdef XP_MACOSX
   min-width: 6ch;
-%else
+%else */
   min-width: 7ch;
-%endif
+/* %endif */
+
 }
 
-.toolbaritem-combined-buttons@inAnyPanel@ > separator {
+.toolbaritem-combined-buttons:-moz-any(:not([cui-areatype="toolbar"]), [overflowedItem=true]) > separator {
   -moz-appearance: none;
   -moz-box-align: stretch;
   margin: .5em 0;
   width: 1px;
   height: auto;
   background: var(--panel-separator-color);
   transition-property: margin;
   transition-duration: 10ms;
   transition-timing-function: ease;
 }
 
-.toolbaritem-combined-buttons@inAnyPanel@:hover > separator {
+.toolbaritem-combined-buttons:-moz-any(:not([cui-areatype="toolbar"]), [overflowedItem=true]):hover > separator {
   margin: 0;
 }
 
 #widget-overflow > .panel-arrowcontainer > .panel-arrowcontent {
   padding: 0;
 }
 
 #widget-overflow-mainView .panel-subview-body {
   overflow-y: auto;
   overflow-x: hidden;
 }
 
 .widget-overflow-list {
-  width: @wideMenuPanelWidth@;
+  width: var(--wide-menu-panel-width);
 }
 
 /* In customize mode, the overflow list is constrained by its container,
  * so we set width: auto to avoid the scrollbar not fitting.
  */
 #customization-panelHolder > .widget-overflow-list {
   width: auto;
 }
 
 toolbaritem[overflowedItem=true],
 .widget-overflow-list .toolbarbutton-1 {
   width: 100%;
-  max-width: @wideMenuPanelWidth@;
+  max-width: var(--wide-menu-panel-width);
   background-repeat: no-repeat;
   background-position: 0 center;
 }
 
 .widget-overflow-list .toolbarbutton-1 {
   -moz-box-align: center;
   -moz-box-orient: horizontal;
 }
@@ -1548,24 +1576,24 @@ toolbarpaletteitem[place="menu-panel"] >
   -moz-box-align: center;
   padding: 1px;
   margin: 0 0 2px;
   background-color: transparent;
   border-radius: 2px;
   border: 1px solid transparent;
 }
 
-.subviewradio@buttonStateHover@ {
+.subviewradio:not(:-moz-any([disabled],[open],:active)):-moz-any(:hover,:focus) {
   background-color: var(--arrowpanel-dimmed);
   border-color: var(--panel-separator-color);
 }
 
 .subviewradio[selected],
 .subviewradio[selected]:hover,
-.subviewradio@buttonStateActive@ {
+.subviewradio:not([disabled]):-moz-any([open],:hover:active) {
   background-color: var(--arrowpanel-dimmed-further);
   border-color: var(--panel-separator-color);
   box-shadow: 0 1px 0 hsla(210,4%,10%,.03) inset;
 }
 
 .subviewradio > .radio-check {
   -moz-appearance: none;
   width: 16px;
@@ -1718,17 +1746,17 @@ toolbarpaletteitem[place="menu-panel"] >
 .panel-header > .subviewbutton-back + label {
   /* Add the size of the back button to center properly. */
   margin-inline-end: 32px;
 }
 
 .panel-header > .subviewbutton-back {
   -moz-context-properties: fill;
   fill: var(--arrowpanel-color);
-  list-style-image: url(chrome://browser/skin/arrow-left.svg);
+  list-style-image: url("chrome://messenger/skin/icons/arrow-left.svg");
   padding: 8px;
 }
 
 .subviewbutton-back:-moz-locale-dir(rtl) {
   transform: scaleX(-1);
 }
 
 .subviewbutton-back > .toolbarbutton-text {
@@ -1758,34 +1786,37 @@ toolbarpaletteitem[place="menu-panel"] >
   font-size: .9em;
 }
 
 .subviewbutton.download > .action-button {
   -moz-appearance: none; /* To avoid native Windows hover styling */
   -moz-context-properties: fill, fill-opacity;
   fill: currentColor;
   fill-opacity: 1;
-%ifdef XP_MACOSX
+
+/* TODO appmenu */
+/* %ifdef XP_MACOSX
   list-style-image: url("chrome://browser/skin/search-glass.svg");
-%else
+%else */
   list-style-image: url("chrome://browser/skin/folder.svg");
-%endif
-  /* Measurement to vertically center this button: 1 line of text minus half of 4px top margin. */
+/* %endif */
+
+/* Measurement to vertically center this button: 1 line of text minus half of 4px top margin. */
   margin: calc(1em - 2px) 0 0;
   padding: 4px;
 }
 
 .subviewbutton.download[canRetry] > .action-button {
   list-style-image: url("chrome://browser/skin/reload.svg");
 }
 
 .subviewbutton.download:not([canShow]):not([canRetry]) > .action-button {
   fill: currentColor;
   fill-opacity: 0.4;
 }
 
-.subviewbutton.download:-moz-any([canShow],[canRetry]) > .action-button@buttonStateHover@ {
+.subviewbutton.download:-moz-any([canShow],[canRetry]) > .action-button:not(:-moz-any([disabled],[open],:active)):-moz-any(:hover,:focus) {
   background-color: var(--arrowpanel-dimmed-further);
 }
 
-.subviewbutton.download:-moz-any([canShow],[canRetry]) > .action-button@buttonStateActive@ {
+.subviewbutton.download:-moz-any([canShow],[canRetry]) > .action-button:not([disabled]):-moz-any([open],:hover:active) {
   background-color: var(--arrowpanel-dimmed-even-further);
 }
--- a/mail/themes/shared/jar.inc.mn
+++ b/mail/themes/shared/jar.inc.mn
@@ -25,16 +25,17 @@
 #ifdef MOZ_UPDATER
   skin/classic/messenger/icons/app-update.svg                 (../shared/mail/icons/app-update.svg)
   skin/classic/messenger/icons/app-update-badge.svg           (../shared/mail/icons/app-update-badge.svg)
 #endif
   skin/classic/messenger/icons/appbutton.svg                  (../shared/mail/icons/appbutton.svg)
   skin/classic/messenger/icons/archive.svg                    (../shared/mail/icons/archive.svg)
   skin/class