Is it possible to get the event if a mail has been received in thunderbird?
Thank you in advance for the answers.
Greetings Mario
Mario,
I have tried to get this in my ThunderbirdBiff addon. I could not find a
way to "hook" this. If you do, please let me know. Instead, I set up a
polling which iterates over the accounts and checks the biffState flag
of account's server. Not the same thing but it gets a similar result.
David
Check out an extension called Growl Notify or something like that. I
copied some code from it to listen for new messages. You basically need
to add a folder listener to some root folder.
-einar-
OnItemAdded: function(parentItem, item, viewString) {
if (parentItem instanceof Components.interfaces.nsIMsgFolder) {
if (parentItem.flags & MSG_FOLDER_FLAG_INBOX) { // check inboxes only
if (item instanceof Components.interfaces.nsIMsgDBHdr) {
if (!item.isRead && (item.flags & 0x10000)) { // check new items
only
doSomething(item);
}
}
}
}
}
function register4MailEvents() {
var mailSession =
Components.classes["@mozilla.org/messenger/services/session;1"].getService(Components.interfaces.nsIMsgMailSession);
var notifyFlags = Components.interfaces.nsIFolderListener.added;
mailSession.AddFolderListener(spamatoFolderListener,notifyFlags);
}
var folderListener = {
OnItemAdded: function(parentItem, item, viewString) {
...
}
}
function register4MailEvents() {
var mailSession =
Components.classes["@mozilla.org/messenger/services/session;1"].getService(Components.interfaces.nsIMsgMailSession);
var notifyFlags =
Components.interfaces.nsIFolderListener.added;
mailSession.AddFolderListener(folderListener,notifyFlags);
}
> Is it possible to get the event if a mail has been received in
> thunderbird?
You can listen for mail:biff-state-changed observer notifications, but I
believe the facility has only recently been added so if you use that
technique your extension will only work in Thunderbird 2.
Alternatively, use a root folder listener, but listen for the integer
BiffState property; the value is 0 for new mail.
--
Warning: May contain traces of nuts.
Neil,
Is there one root folder for the entire T-Bird or is there one per
account? In my extension, T-BirdBiff, I really only want to know if new
mail hass arrived - regardless of account or quantity. So if I only need
one listener for all accounts, that would be easier than sorting out
each account individually. Thanks for the tips.
> Is there one root folder for the entire T-Bird or is there one per
> account?
The mail session collects all the notifications for all accounts. In
fact, the individual account listeners are not readily available from
JavaScript.