[英]Save e-mail body and its attachments from Thunderbird
我正在尝试使用自定义加载项从javascript保存电子邮件正文及其附件,但无法按照http://forums.mozillazine.org/viewtopic.php?f=19&t中的说明进行操作= 2030903您有什么建议吗? 电子邮件正文可以保存为本地EML格式吗? 谢谢!
alert("Messages selected: " + gFolderDisplay.selectedCount);
let enumerator = gFolderDisplay.selectedMessages;
for each (let msgHdr in fixIterator(enumerator, Ci.nsIMsgDBHdr)) {
var messageID = msgHdr.messageId;
alert("MessageID: " + messageID);
var subject = msgHdr.mime2DecodedSubject;
alert("Subject: " + subject);
MsgHdrToMimeMessage(msgHdr, null, function (aMsgHdr, aMimeMsg) {
try {
alert("Size of the message: " + aMimeMsg.size);
alert("Structure of the message:\n" + aMimeMsg.prettyString(true, undefined, true));
let attachments = aMimeMsg.allUserAttachments || aMimeMsg.allAttachments;
alert("Number of attachments: " + attachments.length);
for (let [index, att] in Iterator(attachments))
{
alert ("URL: " + att.url + " Name: " + att.name);
let ioService = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
let neckoURL = null;
neckoURL = ioService.newURI(att.url, null, null);
neckoURL.QueryInterface(Ci.nsIMsgMessageUrl);
let uri = neckoURL.uri;
let attInfo = new AttachmentInfo(att.contentType, att.url, att.name, uri, att.isExternal);
attInfo.save();
}
} catch (err) {
alert(err);
}
}, true, { examineEncryptedParts: true, });
}
[编辑]上面的代码确实保存了附件,但是打开了“另存为”对话框。 可以安静地完成吗? 电子邮件正文可以保存为本地EML格式吗? 谢谢! [/编辑]
我写了上面的例子。 您几乎完成了工作,并且找出了最难的部分。 这是我为弄清楚如何回答您的问题所做的工作。
save
只是nsIMessenger :: saveAttachment的代理,在http://mxr.mozilla.org/comm-central/source/mailnews/base/public/nsIMessenger.idl#81中定义 saveAttachmentToFile
方法! 可能是您所需要的。 阅读该定义,似乎是一个不错的候选者http://mxr.mozilla.org/comm-central/source/mailnews/base/src/nsMessenger.cpp#614 您可能需要传递已经打开的nsIFile函数(请参见https://developer.mozilla.org/en/XPCOM_Interface_Reference/nsIFile,因为那里有很好的参考资料),以及附件的URI(在您的uri
中可用)代码),消息的uri(可能类似于msgHdr.folder.getUriForMsg(msgHdr)
),内容类型(此处为att.contentType
)和实现nsIUrlListener
的侦听nsIUrlListener
(在此处定义: http://mxr.mozilla。 org / comm-central / source / mailnews / base / public / nsIUrlListener.idl#48 ,请参阅https://github.com/protz/GMail-Conversation-View/blob/master/modules/message.js#L1492非常准系统的实现-您可能应该在此处挂接自己的函数,以检查一切是否正常)。
我没有尝试过此代码,但我对指南的正确性很有信心。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.