Finally found a solution for that. Below JavaScript code works fine with FiltaQuilla and Thunderbird 38.2.0.
{ var sHeaderToLookFor = "content-type"; var sContentInHeader = "text/calendar"; var hwindow = Components.classes["@mozilla.org/appshell/appShellService;1"] .getService(Components.interfaces.nsIAppShellService) .hiddenDOMWindow; function waitFor(callback, message, timeout, interval, thisObject) { timeout = timeout || 5000; interval = interval || 100; var self = ; function wait() { self.counter += interval; self.result = callback.call(thisObject); } var timeoutInterval = hwindow.setInterval(wait, interval); var thread = Components.classes["@mozilla.org/thread-manager;1"].getService().currentThread; while ((self.result != true) && (self.counter < timeout)) { thread.processNextEvent(true); } hwindow.clearInterval(timeoutInterval); if (self.counter >= timeout) { message = message || arguments.callee.name + ": Timeout exceeded for '" + callback + "'"; throw new TimeoutError(message); } return true; } var bFoundIt = false; var called = false; function msgHdrGetHeaders(aMsgHdr, k) { let uri = aMsgHdr.folder.getUriForMsg(aMsgHdr); let messageService = MailServices.messenger.messageServiceFromURI(uri); MsgHdrToMimeMessage(aMsgHdr, null, function(aMsgHdr, aMimeMsg) { try { k(aMimeMsg); } catch (ex) { } finally { called = true; } }, true, { partsOnDemand: true, examineEncryptedParts:true }); } msgHdrGetHeaders(message, function (aHeaders) { if (aHeaders.has(sHeaderToLookFor)) { var pattern = new RegExp(sContentInHeader); // Application.console.log("InBetween_1"); if (!bFoundIt) bFoundIt = pattern.test(aHeaders.get(sHeaderToLookFor)); Application.console.log(bFoundIt); // Application.console.log("InBetween_2"); } }); waitFor(function () called, "Timeout waiting for message to be parsed"); // Application.console.log("AtEnd_1"); Application.console.log(bFoundIt); // Application.console.log("AtEnd_2"); bFoundIt; }
I used the waitFor() function from https://searchcode.com/codesearch/view/21382111/. That link seems to be the source from the Thunderbird test library (/thunderbird-14.0/comm-release/mail/test/resources/mozmill/mozmill/extension/resource/modules/utils.js)
Anyway, if someone else has a similar problem, where he wants to parse headers of emails on IMAP folders, he can use above code and just change "sHeaderToLookFor" and "sContentInHeader" to his needs.