I used to be thoroughly confused about Mozilla extensions and how you plug in stuff to work with Firefox and Thunderbird. Since my experiments with writing Songbee, I've become much happier with XUL and Javascript and therefore the whole extension concept, and looking back, it's actually very simple. Perhaps one day I'll write a nice easy tutorial about how to do it. Perhaps, though, it's better just to say that it's actually not as scary as it looks.
Anyway, now, whenever I come across something that Firefox or Thunderbird won't do the way I want, I'll just do it myself. For instance, one of the things I liked about mutt is that it would sort my outgoing mail into "sent" folders by month: so, outbox-200703 and so on. The first thing we need to do is translate that concept into Javascript: We want to add the current year and month to a given string, and set that as our main Fcc folder preference. The tricky thing with Mozilla is always knowing how to tie into the rest of the system, but you can usually finding that by reading through code that does something similar to what you want. For instance, I find that other code sets preferences by getting a handle to the "preferences service" and then calling the setCharPref method on that handle. So the JavaScript side of things looks like this:
gPrefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
var now = new Date();
var mon = now.getMonth()+1;
var str = "outbox-"+now.getFullYear()+(mon < 10 ? "0"+mon : mon);
gPrefs.setCharPref("mail.identity.id1.fcc_folder", "imap://simon@alibi.simon-cozens.org/"+str);
Now where do we put this? I had some trouble finding a hook to hang this onto, before realising that Mozilla has a generic hook to run Javascript from: the "hidden window". So we overlay the hidden window with a bit of XUL:
[% FILTER html %][% END%]
And this is all hooked together in the chrome manifest:
content dated-fcc chrome/content/ overlay chrome://messenger/content/hiddenWindow.xul chrome://dated-fcc/content/dated-fcc.xul
The first line tells the system where to find all the "dated-fcc" files, and the second says that we're putting our XUL file on top of the hidden window. And, well, that's all. I've written a Thunderbird extension. Actually, I've written three in the past couple of weeks: one to control the behaviour of Thunderbird/Firefox when talking to things with bad SSL certificates, one to provide more activity feedback when Thunderbird's doing things, and this one.
So if Mozilla doesn't do what you want, there's no excuse. You have the source, you can hack it, and it's not as scary as it first appears.
Full version - 3 Comments