FiltaQuilla icon indicating copy to clipboard operation
FiltaQuilla copied to clipboard

Discussion: How to filter for "content-type: text/calendar"

Open sebastian-philipp opened this issue 1 year ago • 3 comments

Hi there,

this is not really a bug or a feature request, more like a ask for help for a JS filter that no longer works.

In https://superuser.com/a/965211/295374 there is an old filter to filter messages for content-type: text/calendar, and I'm interested in this as well. Unfortunately it no longer works.

Maybe there is a even better better way to filter for messages with calendar invites? I'm interested, cause they're really filling up my inbox.

Anyway. Here is my slightly updated version:

{
    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 = {counter: 0, result: callback.call(thisObject)};

        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);
        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);
            console.log("aHeaders=" + aHeaders.get(sHeaderToLookFor))
            if (!bFoundIt)
                bFoundIt = pattern.test(aHeaders.get(sHeaderToLookFor));
        }
    });

    waitFor(function () {
        return called;
    }, "msgHdrGetHeaders timed out", 5000, 100);
    console.log("bFoundIt: " + bFoundIt);
    bFoundIt;
}

but this only prints aHeaders=multipart/mixed; boundary="----=_Part_29631_1119653187.1675464421720" for those messages. Any I'm also not really able to find any documentation for MsgHdrToMimeMessage.

Thank you!

sebastian-philipp avatar Mar 08 '23 10:03 sebastian-philipp