Skip to content

Instantly share code, notes, and snippets.

@brettz9
Last active January 1, 2017 01:49
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 brettz9/ca3a270874de6bc59de8f87480a1b034 to your computer and use it in GitHub Desktop.
Save brettz9/ca3a270874de6bc59de8f87480a1b034 to your computer and use it in GitHub Desktop.
Snippet for use with [Custom Buttons](https://addons.mozilla.org/en-US/thunderbird/addon/custom-buttons/) to open a specific email in Thunderbird from a custom toolbar button.
/*CODE*/
/*
See:
- https://dxr.mozilla.org/comm-central/source/mail/base/modules/
- https://dxr.mozilla.org/comm-central/source/mailnews/base/public/nsIMsgHdr.idl
- https://searchcode.com/codesearch/view/21378574/ (Gloda)
- https://searchcode.com/codesearch/view/21377672/ (datamodel.js)
- https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIMsgDBHdr
- eMarks souce! https://addons.mozilla.org/en-US/thunderbird/addon/emarks/
- https://developer.mozilla.org/en-US/docs/Mozilla/Thunderbird/Mail_client_architecture_overview
- https://developer.mozilla.org/en-US/docs/Mozilla/Thunderbird/Creating_a_Gloda_message_query
- https://developer.mozilla.org/en-US/Add-ons/Thunderbird/HowTos/Folders_and_message_lists
- https://developer.mozilla.org/en-US/Add-ons/Thunderbird/HowTos
- https://developer.mozilla.org/en-US/Add-ons/Thunderbird/Creating_a_Custom_Column
*/
// STEP 1: Uncomment the next two lines, create button and add code, select a message in Thunderbird, and execute button
// alert(gFolderDisplay.selectedMessage.messageId); // Gets the messageID of a currently selected email message
// return;
// STEP 2: Recomment the two lines above, replace the string in the next line with the messageId detected above, and reexecute button code:
let msgID = 'ef2c8e59-d1a6-0f1b-8f3b-3bb854ddccbe@yahoo.com';
try {
Components.utils.import("resource:///modules/gloda/public.js");
let query = Gloda.newQuery(Gloda.NOUN_MESSAGE);
query.headerMessageID(msgID);
let myListener = {
/* called when new items are returned by the database query or freshly indexed */
onItemsAdded: function myListener_onItemsAdded(aItems, aCollection) {
},
/* called when items that are already in our collection get re-indexed */
onItemsModified: function myListener_onItemsModified(aItems, aCollection) {
},
/* called when items that are in our collection are purged from the system */
onItemsRemoved: function myListener_onItemsRemoved(aItems, aCollection) {
},
/* called when our database query completes */
onQueryCompleted: function myListener_onQueryCompleted(aCollection) {
let hdr = aCollection.items[0];
ComposeMessage(Ci.nsIMsgCompType.Draft, Ci.nsIMsgCompFormat.Default, hdr.folderMessage, [hdr.folderMessageURI]);
setTimeout(function () {
try {
let wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
.getService(Components.interfaces.nsIWindowMediator);
let enumerator = wm.getEnumerator(null); // 'htmlmail' ?
while (enumerator.hasMoreElements()) {
let win = enumerator.getNext(); // [Object ChromeWindow]
if (('Write: ' + hdr.subject) === win.document.title) {
let cFrame = win.document.getElementById('content-frame');
let contWin = cFrame.contentWindow;
contWin.focus(); // Focusing the editor doesn't work here
break;
}
}
} catch (err) {
alert(err);
}
}, 750);
}
};
let collection = query.getCollection(myListener);
// var a = Gloda.getMessageCollectionForHeader(gFolderDisplay.selectedMessage, myListener, null);
} catch(err) {alert(err);}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment