通过thunderbird扩展以html格式阅读电子邮件

时间:2013-09-30 17:59:13

标签: api native thunderbird thunderbird-addon

我正在使用

function MsgHdrToMimeMessage(aMsgHdr, aCallbackThis, aCallback,
                             aAllowDownload, aOptions) {

来自http://mxr.mozilla.org/comm-central/source/mailnews/db/gloda/modules/mimemsg.js#171的方法,通过thunderbird扩展程序读取所选的电子邮件。这种方法工作正常,唯一的麻烦是它通过从消息中剥离所有html来提供纯文本消息。

如何获取该邮件的html版本?

1 个答案:

答案 0 :(得分:1)

据我所知,你无法访问整个身体(使用mail和html标签)。您具有XPCOM可编写脚本接口nsIMsgDbHdr的功能和属性。 我有一个发送邮件的附加组件。我在以下代码片段的帮助下阅读了整个邮件正文。如您所见,我从磁盘读取整个邮件并将其内容加载到变量中。您也可以使用它来阅读完整的邮件正文。

function SendMailNow(aMsgDBHdr) {
    var aMsgURI = aMsgDBHdr.folder.getUriForMsg(aMsgDBHdr);

    var msgWindow = Components.classes["@mozilla.org/messenger/msgwindow;1"]
            .createInstance();
    msgWindow = msgWindow.QueryInterface(Components.interfaces.nsIMsgWindow);

    var msgStream = Components.classes["@mozilla.org/network/sync-stream-listener;1"]
            .createInstance();
    msgStream = msgStream.QueryInterface(Components.interfaces.nsIInputStream);

    var aMsgService = messenger.messageServiceFromURI(aMsgURI);

    var scriptInputStream = Components.classes["@mozilla.org/scriptableinputstream;1"]
            .createInstance();
    scriptInputStream = scriptInputStream
            .QueryInterface(Components.interfaces.nsIScriptableInputStream);

    scriptInputStream.init(msgStream);

    try {
        aMsgService.streamMessage(aMsgURI, // uri of message to stream
        msgStream, // a stream listener listening to the message
        msgWindow, // a nsIMsgWindow for progress and status feedback
        null, // a nsIUrlListener that is notified when url starts and stops
        false, // it will create a stream converter from message rfc2822 to
        null // Header added to the URI. e.g., header=filter
        );
    } catch (ex) {
    }

    // Creating content
    var content = "";
    while (scriptInputStream.available()) {
        content = content + scriptInputStream.read(512);
        if (content.match(/\r\n\r\n/) || content.match(/\n\n/)) {
            if (sendMail(content, aMsgDBHdr.messageId)) {
                log("SEND_DONE\t" + aMsgDBHdr.messageId + "\t"
                        + aMsgDBHdr.subject);
            } else {
                log("SEND_FAILED\t" + aMsgDBHdr.messageId + "\t"
                        + aMsgDBHdr.subject);
            }
        }
    }
}

我希望这会对你有所帮助!