Skip to content

Instantly share code, notes, and snippets.

@jikamens
Created April 12, 2022 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jikamens/095b5056e8885c15fed6a076e4390f87 to your computer and use it in GitHub Desktop.
Save jikamens/095b5056e8885c15fed6a076e4390f87 to your computer and use it in GitHub Desktop.
// https://bugzilla.mozilla.org/show_bug.cgi?id=128072#c32
// Credit: Alexander Bergmann
"use strict;"
// Toggle Replied and Forwarded
if (location == "chrome://messenger/content/messenger.xhtml") {
let toggleRepliedAndForward = {
init: function() {
let contextMenu = document.getElementById("mailContext-mark");
if (contextMenu) {
let markMenupopup = contextMenu.getElementsByTagName("menupopup")[0];
let markMenuseparator = markMenupopup.getElementsByTagName("menuseparator")[0];
markMenupopup.insertBefore(this.createRepliedMenuitem("mailContext-markReplied", "Replied"), markMenuseparator);
markMenupopup.insertBefore(this.createForwardedMenuitem("mailContext-markForwarded", "Forwarded"), markMenuseparator);
contextMenu.addEventListener("popupshowing", this.popup, false);
}
},
createRepliedMenuitem: function(id, label) {
menuitem = document.createXULElement("menuitem");
menuitem.setAttribute("label", label);
menuitem.setAttribute("id", id);
menuitem.setAttribute("type", "checkbox");
menuitem.addEventListener("command", this.toggleReplied, false);
return menuitem;
},
createForwardedMenuitem: function(id, label) {
menuitem = document.createXULElement("menuitem");
menuitem.setAttribute("label", label);
menuitem.setAttribute("id", id);
menuitem.setAttribute("type", "checkbox");
menuitem.addEventListener("command", this.toggleForwarded, false);
return menuitem;
},
toggleReplied: function() {
let dBView = gDBView;
let markReplied = (dBView.hdrForFirstSelectedMessage.flags&0x02) == 0;
let uris = gFolderDisplay.selectedMessageUris;
for (let uri of uris) {
let hdr = messenger.msgHdrFromURI(uri);
dBView.db.MarkReplied(hdr.messageKey, markReplied, null);
let fdr = dBView.msgFolder;
if (fdr instanceof Components.interfaces.nsIMsgImapMailFolder) {
fdr.storeImapFlags(0x02, markReplied, [hdr.messageKey], null);
}
}
},
toggleForwarded: function() {
let dBView = gDBView;
let markForwarded = (dBView.hdrForFirstSelectedMessage.flags&0x1000) == 0;
let uris = gFolderDisplay.selectedMessageUris;
for (let uri of uris) {
let hdr = messenger.msgHdrFromURI(uri);
dBView.db.MarkForwarded(hdr.messageKey, markForwarded, null);
let fdr = dBView.msgFolder;
if (fdr instanceof Components.interfaces.nsIMsgImapMailFolder) {
fdr.storeImapFlags(0x0040, markForwarded, [hdr.messageKey], null);
}
}
},
popup: function() {
let dBView = gDBView;
let isMessageReplied = (dBView.hdrForFirstSelectedMessage.flags&0x02) != 0;
let isMessageForwarded = (dBView.hdrForFirstSelectedMessage.flags&0x1000) != 0;
document.getElementById("mailContext-markReplied").setAttribute("checked", isMessageReplied ? "true" : "");
document.getElementById("mailContext-markForwarded").setAttribute("checked", isMessageForwarded ? "true" : "");
}
}
toggleRepliedAndForward.init();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment