Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Is it possible to write your own filters for Thunderbird, I don't care what language is used.

I want to be able to do a full analysis of the email (headers and text) and take certain actions based on the content.

Bonus points if I'm able to compare the current email with older received messages (mainly to remove duplicate log messages)

share|improve this question
add comment

4 Answers

up vote 2 down vote accepted

Actually it is doable with FiltaQuilla. (Tried FiltaQuilla 1.1.0, with Thunderbird 3.1.9).

Below is a test script put under "javascript action with body" supplied by FiltaQuilla. It does show all the header properties and the body in the error console.

Once those data fields are available to the code, it needs to traverse through messenger folders and messages to compare them. Maybe using the "threadParent" property on the hdr can simplify the logic, refer to nsIMsgDBHdr on MDC for a hint. In the code, extra properties can be set. For example, set "hdr.myvar='1234'" in the code for duplicated messages, then in a later filter match myvar to 1234 and do a normal action to delete them.

Since this script is the action part of a filter, the condition part of the filter needs to match all messages of interest. In this test the script is arranged after an action to copy the message to a local folder, that may or may not be necessary but it does download the message body to the local machine on an IMAP account so the action will do have a body to access.

//FiltaQuilla filter action script: 
for (let index = 0; index < msgHdrs.length; index++)
{ //get msg hdr:
  let hdr = msgHdrs.queryElementAt(index, Ci.nsIMsgDBHdr);

  //show subject: get it in two ways
  let s = hdr.getStringProperty("subject");
  if ( s != undefined && s.length != undefined && s.length > 0)
      Cu.reportError("  flt log1: " + s.length + " " + s);
  Cu.reportError("  flt log2: " + hdr.subject );

  //show all properties of hdr: uncomment to show.
  //let e = hdr.propertyEnumerator;
  //while ( e.hasMore() ) Cu.reportError("  flt log3: " + e.getNext() ); 

  //get body: from an example on MDC: getMessageBody(aMessageHeader)
  //Actions configured in the filter: Without [1], it takes long long time. 
  //    [1] copy msg to a local folder. 
  //    [2] "Javascript Action with Body" with this script. 
  { let messenger = Components.classes["@mozilla.org/messenger;1"]
                      .createInstance(Components.interfaces.nsIMessenger);
    let listener = Components.classes["@mozilla.org/network/sync-stream-listener;1"]
                      .createInstance(Components.interfaces.nsISyncStreamListener);
    let uri = hdr.folder.getUriForMsg(hdr);
    messenger.messageServiceFromURI(uri)
                .streamMessage(uri, listener, null, null, false, "");
    let folder = hdr.folder;
    let body = folder.getMsgTextFromStream(listener.inputStream,
                              hdr.Charset, 65536, 32768, false, true, { });
    //show body:
    Cu.reportError("  flt log4: " + body.length + " " + body);
  }
}
share|improve this answer
add comment

No, this doesn't seem to be possible.

Such processing is probably easiest to do on the mail server, with stuff like procmail, Courier maildrop, amavisd-new, etc.

Amavisd-new is specifically designed to pass mail to external processing programs before delivery, usually anti-virus and anti-spam daemons.

If you cannot do it on the server side, you would need to write an extension, but that is probably far too much work.

Finally, maybe you can satisfy a good part of your needs with the FiltaQuilla extension, which supports regular expressions, running external programs, and javascript actions. You can find more info on the author's page.

Personally, if I didn't have access to the mail server and if FiltaQuilla didn't satisfy my needs, I would chose to set up a local Postfix / IMAP mail server fetching the mail from the ISP and processing it before delivery with my custom scripts. It should be much easier than writing a TB extension. But it may be overkill for your needs.

share|improve this answer
    
Wonder why this has been "unaccepted", when it was actually the first to mention, among other possibilities, the apparently preferred FiltaQuilla extension. –  mivk Oct 2 '11 at 15:02
add comment

You could look for a POP3/IMAP proxy that has the scriptable filtering capabilities you need. It could be a proxy which runs on the same PC as Thunderbird.

share|improve this answer
add comment

With the extension: http://mesquilla.com/extensions/filtaquilla/

you can create JavaScript and/or external files to execute, so it looks like a solid "maybe"

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.