The Deep End

go to! email!

Thursday, February 24, 2005

Thunderbird Extensions: Navigating Folders

Your Thunderbird extension may need, at some point, to find a folder, delete a folder, get the messages in a folder, or whatever. And here's how!
var view = GetDBView();
var fldrlocal = view.getFolderForViewIndex(0).rootFolder;
var fldrtemplates = fldrlocal.FindSubFolder("Templates");
var subfdr = fldrtemplates.FindSubFolder("Inferior Subfolder");

First of all, GetDBView() wasn't defined somewhere else in my .js file; apparently it is defined somewhere in the Thunderbird source, because you can use it and it works. Again, thanks to the DictionarySearch extension, because I got some of this code from there.

A major limitation of this code is that it assumes the folder at "View Index 0" has a root folder!!!

The only reason that this wouldn't work is if you had selected "Local Folders" instead of an actual folder. Normally this isn't a problem because by default "Inbox" is selected.

Something that I don't understand is the correlation between the list of folders in the Folders pane and the "ViewIndex". From prior experimentation I know that if you select a folder and then call getURIForViewIndex(int) then the uri returned will be the message uri of the somethingth message of whatever folder you have selected.

My guess is that a "ViewIndex" actually refers to a message, and getURI gets the message Uri while getFolder gets the parent folder. However, this may not be the case and should not be assumed to be true. If anyone really does know what a ViewIndex is, please feel free to comment or email me.

Once you've actually found a folder, moving around gets pretty easy. nsIMsgFolder is the XPCOM model of a folder, and there are some useful and self-explanatory functions at XulPlanet!


Post a Comment

<< Home