Endlich eine Lösung dafür gefunden. Der folgende JavaScript-Code funktioniert gut mit FiltaQuilla und 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; }
Ich habe die waitFor () - Funktion von https://searchcode.com/codesearch/view/21382111/ verwendet . Dieser Link scheint die Quelle aus der Thunderbird-Testbibliothek zu sein (/thunderbird-14.0/comm-release/mail/test/resources/mozmill/mozmill/extension/resource/modules/utils.js).
Wenn jemand anderes ein ähnliches Problem hat, bei dem er Header von E-Mails in IMAP-Ordnern analysieren will, kann er den obigen Code verwenden und "sHeaderToLookFor" und "sContentInHeader" an seine Bedürfnisse anpassen.