MozillaZine

Event triggered on add of message to TB folder?

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

Post Posted January 10th, 2017, 12:01 pm

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

DanRaisch
Moderator

User avatar
 
Posts: 115785
Joined: September 23rd, 2004, 8:57 pm
Location: Somewhere on the right coast

Post Posted January 10th, 2017, 4:06 pm

Perhaps you haven't considered using Message Filters for that purpose.

GenghisKen
 
Posts: 5
Joined: January 1st, 2017, 11:17 am

Post Posted January 10th, 2017, 6:46 pm

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.

DanRaisch
Moderator

User avatar
 
Posts: 115785
Joined: September 23rd, 2004, 8:57 pm
Location: Somewhere on the right coast

Post Posted January 10th, 2017, 8:33 pm

How is the account set up in Thunderbird, as POP or IMAP?

GenghisKen
 
Posts: 5
Joined: January 1st, 2017, 11:17 am

Post Posted January 11th, 2017, 8:04 am

The account with the folders I want to watch is Google IMAP. The account to which I want messages copied is 'Local Folders'.

DanRaisch
Moderator

User avatar
 
Posts: 115785
Joined: September 23rd, 2004, 8:57 pm
Location: Somewhere on the right coast

Post Posted January 11th, 2017, 8:31 am

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

Post Posted January 11th, 2017, 2:24 pm

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: 2228
Joined: February 3rd, 2009, 6:29 pm

Post Posted January 11th, 2017, 3:58 pm

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

Post Posted January 17th, 2017, 10:34 am

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

Return to Extension Development


Who is online

Users browsing this forum: No registered users and 3 guests