2

I have a list of email ids.i want to filter inbox messages and display only emails from those users in thunderbird. Please help me doing this.

This is what i tried so far and it's not working.But im getting completely irrelevant error message "We are unable to print or preview this page".

var gLocalIncomingServer = MailServices.accounts.localFoldersServer;
var gLocalMsgAccount = MailServices.accounts.FindAccountForServer(
 gLocalIncomingServer);

var gLocalRootFolder = gLocalIncomingServer.rootMsgFolder
                  .QueryInterface(Ci.nsIMsgLocalMailFolder);

const kInboxFlag = Components.interfaces.nsMsgFolderFlags.Inbox; 
var gLocalInboxFolder = gLocalRootFolder.getFolderWithFlags(kInboxFlag); 
gLocalRootFolder.findSubFolder(gLocalInboxFolder.URI); 

gLocalInboxFolder.setFlag(Ci.nsMsgFolderFlags.Mail);

 // Force an initialization of the Inbox folder database.
 var folderName = gLocalInboxFolder.prettiestName;

 var aValue = "[email protected]";
 var aAttrib = Ci.nsMsgSearchAttrib.Sender;
 var aop = nsMsgSearchOp.Contains;;
 var hitCount = 1;

var searchListener =
 {
  onSearchHit: function(dbHdr, folder) { hitCount++; },
  onSearchDone: function(status)
  {
    print("Finished search does " + aHitCount + " equal " + hitCount + "?");
    searchSession = null;
    do_check_eq(aHitCount, hitCount);
    if (onDone)
    onDone();
  },
 onNewSearch: function() {hitCount = 0;}
};

// define and initiate the search session

var hitCount;
var searchSession = Cc["@mozilla.org/messenger/searchSession;1"]
                    .createInstance(Ci.nsIMsgSearchSession);
searchSession.addScopeTerm(Ci.nsMsgSearchScope.offlineMail, gLocalInboxFolder);
var searchTerm = searchSession.createTerm();
searchTerm.attrib = aAttrib;

var value = searchTerm.value;
// This is tricky - value.attrib must be set before actual values
value.attrib = aAttrib;
value.str = aValue;
searchTerm.value = value;
if (aAttrib > nsMsgSearchAttrib.OtherHeader)
  searchTerm.arbitraryHeader = gArrayHdrs[aAttrib - 1 - nsMsgSearchAttrib.OtherHeader];
searchTerm.op = aOp;
searchTerm.booleanAnd = false;
searchSession.appendTerm(searchTerm);
searchSession.registerListener(searchListener);
searchSession.search(null);
alert("search is done:");

2 Answers 2

1

Have you seen this Mozilla page? How do I search for a particular contact property (name, email)?

0

You don't really need to write any JS code to accomplish this. Thunderbird's search mechanism can be used in two UI-accessible ways:

  • Define a "saved search" folder. This filters one or more folders with a set of criteria and presents the results in a single folder. See and be aware you probably want an offline search since it will be faster than asking the IMAP server: http://kb.mozillazine.org/Saved_Search

  • Define a "mail view" that can be applied to any folder. Customize the mail toolbar by right clicking on it, choosing "customize..." and dragging the combo-box labeled "Mail Views" to the toolbar. Close the customize dialog by hitting "Done". Click on the combo-box on the toolbar, choose "customize...", hit "new..." to define and name your filter criteria. You can then apply the mail view by clicking on the combo box and locating it under the "Custom Views" header.

For your filter criteria, you can either type in all the names as separate predicates where "any" rule matches, or you might want to use the "is in my address book" predicate and just put all of those people in a special address book. For example, such a rule would look like: "From" "is in my address book" "cool people". You can create a new address book via "File... New... Address Book" from the Address Book window.

If you prefer to do things programatically and you want to be able to have the list of people vary at runtime, you will want to check out my blog post on creating quick filter bar extensions, as that's the easiest way to hook custom filtering logic into the Thunderbird UI that won't break:

http://www.visophyte.org/blog/2010/05/02/thunderbird-quick-filter-bar-extensions-theyre-a-thing/

Code for that example currently lives here on github: github.com/asutherland/qfb-pivot

If your list of e-mails isn't going to change a lot, you can also create the "saved search folders" (virtual folders, internally), you should check out mxr.mozilla.org/comm-central/source/mailnews/base/src/virtualFolderWrapper.js and its createNewVirtualFolder method.

Apologies for de-hyperlinking two of the URLs, but the anti-spam mechanism won't let me have more than 2 links in the post...

1
  • Thanks for the answer.These list of emails will change based on user request (i.e they are dynamic).So creating virtual folders is not the correct solution.
    – sathis
    Mar 22, 2012 at 7:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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