0

我正在使用

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

来自 http://mxr.mozilla.org/comm-central/source/mailnews/db/gloda/modules/mimemsg.js#171的方法通过雷鸟扩展阅读选定的电子邮件。此方法工作正常,唯一的问题是它通过从消息中剥离所有 html 来提供纯文本消息。

如何获取消息的 html 版本?

4

1 回答 1

1

据我所知,您无法访问整个正文(使用邮件和 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);
            }
        }
    }
}

我希望这能帮到您!

于 2013-09-30T20:14:47.347 回答