Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Tunderbird

30 views
Skip to first unread message

Mario

unread,
Nov 23, 2006, 9:09:59 AM11/23/06
to
Hi all!

Is it possible to get the event if a mail has been received in thunderbird?

Thank you in advance for the answers.
Greetings Mario

us...@domain.invalid

unread,
Nov 23, 2006, 12:32:37 PM11/23/06
to

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

Einar Egilsson

unread,
Nov 23, 2006, 5:49:40 PM11/23/06
to

> I have tried to get this in my ThunderbirdBiff addon. I could not find a
> way to "hook" this.
> 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-

kenoa

unread,
Nov 24, 2006, 5:45:25 AM11/24/06
to
I've added a listener to the MailSession and listen to the onItemAdded
event. Additionally, I make sure that the item added is indeed a new
message. It looks roughly like this:

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);
}

kenoa

unread,
Nov 24, 2006, 5:49:13 AM11/24/06
to
Sorry, one part was missing, of course the OnItemAdded function must be
wrapped in the folderListener:

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);
}

Neil

unread,
Nov 24, 2006, 8:25:41 AM11/24/06
to
Mario wrote:

> 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.

us...@domain.invalid

unread,
Nov 24, 2006, 12:24:38 PM11/24/06
to

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.

Neil

unread,
Nov 24, 2006, 3:53:10 PM11/24/06
to
us...@domain.invalid wrote:

> 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.

0 new messages