Event triggered on add of message to TB folder?

Talk about add-ons and extension development.
Post Reply
GenghisKen
Posts: 5
Joined: January 1st, 2017, 11:17 am

Event triggered on add of message to TB folder?

Post by GenghisKen »

I would like to have an action triggered whenever a message (or messages) are added to a TB folder, whether they're copied there manually or end up there through the application of a filter.

Specifically, I'd like the incoming message to be copied to a location in 'Local Folders' for safekeeping.

I haven't found anything like this yet, and it's unclear if there's even an event API that covers this sort of thing, to which I could subscribe a hook.

Any pointers would be extremely welcome!

Thanks..
User avatar
DanRaisch
Moderator
Posts: 127186
Joined: September 23rd, 2004, 8:57 pm
Location: Somewhere on the right coast

Re: Event triggered on add of message to TB folder?

Post by DanRaisch »

Perhaps you haven't considered using Message Filters for that purpose.
GenghisKen
Posts: 5
Joined: January 1st, 2017, 11:17 am

Re: Event triggered on add of message to TB folder?

Post by GenghisKen »

I have, but as I described, they don't fit the bill. Dragging a message to a folder by hand isn't going to trigger a filter action. Filters work on where the message originates; I need something that acts when the message arrives in a destination folder.
User avatar
DanRaisch
Moderator
Posts: 127186
Joined: September 23rd, 2004, 8:57 pm
Location: Somewhere on the right coast

Re: Event triggered on add of message to TB folder?

Post by DanRaisch »

How is the account set up in Thunderbird, as POP or IMAP?
GenghisKen
Posts: 5
Joined: January 1st, 2017, 11:17 am

Re: Event triggered on add of message to TB folder?

Post by GenghisKen »

The account with the folders I want to watch is Google IMAP. The account to which I want messages copied is 'Local Folders'.
User avatar
DanRaisch
Moderator
Posts: 127186
Joined: September 23rd, 2004, 8:57 pm
Location: Somewhere on the right coast

Re: Event triggered on add of message to TB folder?

Post by DanRaisch »

OK, then the filters would work automatically only on messages newly arrived to the account's Inbox. You could set up a Saved Search that seeks messages in that Gmail account, including sub-folders, but the action triggered by such a search would not copy the new messages to separate folders but only to one destination folder under Local Folders, probably not an acceptable solution.

Is it critical that you access that account as an IMAP account?
GenghisKen
Posts: 5
Joined: January 1st, 2017, 11:17 am

Re: Event triggered on add of message to TB folder?

Post by GenghisKen »

Yes, there is no choice about the IMAP aspect. That's why I'm hoping there's some sort of event API that includes a 'message arrived in folder' event that I can hook.
morat
Posts: 6403
Joined: February 3rd, 2009, 6:29 pm

Re: Event triggered on add of message to TB folder?

Post by morat »

You can use a folder listener like the Mailbox Alert extension.

Code: Select all

var folderListener = {
  OnItemAdded: function (parentItem, item) {
    MailServices.mailSession.RemoveFolderListener(folderListener);
    var folder = parentItem.QueryInterface(Components.interfaces.nsIMsgFolder);
    var msgHdr = item.QueryInterface(Components.interfaces.nsIMsgDBHdr);
    alert([folder.abbreviatedName, msgHdr.mime2DecodedAuthor,
      msgHdr.mime2DecodedSubject, msgHdr.mime2DecodedRecipients].join("\n"));
  },
};
var notifyFlags = Components.interfaces.nsIFolderListener.added;
MailServices.mailSession.AddFolderListener(folderListener, notifyFlags);
https://dxr.mozilla.org/comm-release/so ... stener.idl
https://dxr.mozilla.org/comm-release/so ... ession.idl
GenghisKen
Posts: 5
Joined: January 1st, 2017, 11:17 am

Re: Event triggered on add of message to TB folder?

Post by GenghisKen »

That looks awesomely like what I want. Thanks! I'll check it out!
Post Reply