Thunderbird Extensions: Navigating Folders
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
)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
getURIgets the message Uri while
getFoldergets 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!