i need some help if possible. I developing an addon which adds an extra StringReference header to a letter during send.

After it is in the "Sent" folder I would like to collect threadId (this is ok), and remove the extra StringReference from the header. I have found the following http://mdn.beonex.com/en/XPCOM_Interface_Reference/nsIMsgDBHdr.html:

In clear, if you want to do a persistent change to a message header, such as marking it as read, or replied to, or whatever, you MUST do it through its corresponding nsIMsgFolder (msgHdr.folder) or nsIMsgDatabase (msgHdr.folder.msgDatabase).

But I cannot make a working code, because I cannot get nsIMsgDatabase, but even if I could have this object for the actual msgHdrDb I should call Commit(type) with some commit type I cannot figure out. Could anyone help me with some example how to make permanent changes on a message in the msgHdrDb?

Thank you for you help in advance!

有帮助吗?

解决方案

I'm pretty sure this method does not work, as you'll be only modifying the locally-stored message header, not the actual message. While this works fine for local folders / POP3 accounts, it won't work for IMAP accounts, and the changes won't be propagated to the IMAP server.

There's actually a thread about this at https://groups.google.com/forum/#!topic/mozilla.dev.apps.thunderbird/yWGIYQ8bwfE ; it contains a lot of valuable information, and answers your question. You basically have to create a new copy of the message and inject it into the folder. Doing that, you can modify the headers. I think the bottom line is: just look at the source code of https://addons.mozilla.org/thunderbird/addon/header-tools-lite/?src=mozilla.dev.apps.thunderbird (header tools lite) to see how they do it.

Cheers,

其他提示

actually I figured it out. Of course it isn't complicated, but to help others, I answer my question.

// This mail is in the INBOX folder
if (MAIL_LIST[actualMsgHdrDb.messageId] != null) {
    // This is a FORCED answer mail in INBOX folder
    // Removing marker
    log("--------------------------- Removed from MAIL LIST ----------------------------");
    log("REMOVED MESSAGE:    "
            + MAIL_LIST[actualMsgHdrDb.messageId].subject);
    actualMsgHdrDb.setReferences("");

    MAIL_LIST[actualMsgHdrDb.messageId].subject = MAIL_LIST[actualMsgHdrDb.messageId].subject
            .replace(/Forced/, "Answered");

    log("REPLACED SUBJECT:   "
            + MAIL_LIST[actualMsgHdrDb.messageId].subject);

    /* THIS IS THE PART WHERE I FLUSH THE DATA TO DISK */
    MAIL_LIST[actualMsgHdrDb.messageId].folder.msgDatabase = null;

    log("SUBJECT HAS BEEN SET TO: "
            + MAIL_LIST[actualMsgHdrDb.messageId].subject);
    // Removing from list
    delete MAIL_LIST[actualMsgHdrDb.messageId];
}

There is actually an open source package, thunderbird-stdlib, that was developed that does exactly this. Code would look like this

Components.utils.import("chrome://path/to/thunderbird-stdlib/msgHdrUtils.js")

var msgHdr = ... get the message header ...;
msgHdrsModifyRaw([msgHdr], function(input) {
    // modify the raw input here.
    var modified = input.modify()
    return modified
});
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top