The Deep End

go to graworks.com! email!

Tuesday, May 31, 2005

Thunderbird Extensions Documentation: Wielding the nsIEnumerator

This post deals with the two kinds of enumerators in Mozilla. nsISimpleEnumerator is really simple, and there's no reason to talk about that.

nsIEnumerator is really bizarre, and although this may seem obvious to everyone else, this might be helpful to anyone who's a little stuck.

Basically, nsIEnumerator runs happily until it crashes.

Here's some code that you can pretend is a while(friendlyAndNice.hasNext()) loop:
var keepGoing = 1;

blah

try{
nseSubFolders.first();
}catch(e1){
keepGoing = 0;
}


while(keepGoing == 1){
thing = blah.currentItem();


try{
nseSubFolders.next();
}catch(e2){
keepGoing = 0;
}
}

Thunderbird Extensions Documentation: Going from Message Key to Message Uri

A lot of functions that I've come across in Mozilla require something called a "message uri"-- like the nsIMessenger component's getMessageServiceFromUri. Since most of my other posts deal with something else called a "message key," here's how to convert between them:fdr.generateMessageURI(msgKey);

So you could write something like,
var fdr = hdr.folder;
fdr.generateMessageURI(hdr.messageKey);
. I think. If not, you may have to Get To The Folder From An Account or Local Folders (see post).

Thursday, May 19, 2005

Thunderbird Extensions: Adding Stuff to the Editor Tag

This post describes how to add stuff to the message body textbox in a compose window. The message body textbox is really a XUL element called the editor tag. If you search around the mozilla source (line 692 of messengercompose.xul), you'll find
<editor type="content-primary" id="content-frame" src="about:blank" name="browser.message.body" flex="1">
Apparently, the editor tag is really, in Javascript, a nsIEditorBoxObject. The Mozilla Documentation has some highly informative information about this, although it didn't really help me.

What did help me was wandering helplessly around the Internet and XulPlanet until I found The Answer. Here it is:
var domndEditor = document.getElementById("content-frame");
var htmlEditor = domndEditor.getHTMLEditor(domndEditor.contentWindow); //htmlEditor is the same
// thing as nsiEditor!!!

//this means that the editor
//is a bizarre mixture
//of about a gazillion
//interfaces.

//there may be some better way to do this if(body.toUpperCase().indexOf("html")==-1){
htmlEditor = htmlEditor.QueryInterface(Components.interfaces.nsIPlaintextEditor);
//this is so weird. htmlEditor, I command you to become an //nsIPlainTextEditor!!!
//...
//it worked!




htmlEditor.insertText(body);
}
else htmlEditor.insertHTML(body); //body is whatever text you'd like to //insert into the editor tag (or "that textbox message body thing in a //compose window")