我想使用雷鸟源代码保存电子邮件附件。我得到了下面的代码在你的论坛..但它不工作
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, });
}
使用上面的代码,我可以遍历选定的消息。但没有保存附件。它显示了附件的数量。我还想为选定的邮件设置我自己的标签。我怎样才能做到这一点?请帮帮我……提前感谢
工作代码
var enumerator = gFolderDisplay.selectedMessages;
for each (var msgHdr in fixIterator(enumerator, Components.interfaces.nsIMsgDBHdr)) {
msgHdr.setStringProperty("docuHive","dhivelabel");
MsgHdrToMimeMessage(msgHdr, null, function (aMsgHdr, aMimeMsg) {
try {
var attachments = aMimeMsg.allUserAttachments || aMimeMsg.allAttachments;
for (var [index, att] in Iterator(attachments))
{
var ioService = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
var neckoURL = null;
neckoURL = ioService.newURI(att.url, null, null);
neckoURL.QueryInterface(Components.interfaces.nsIMsgMessageUrl);
var uri = neckoURL.uri;
var attInfo = new AttachmentInfo(att.contentType, att.url, att.name, uri, att.isExternal);
// getting the chrome directory
var file = Components.classes["@mozilla.org/file/directory_service;1"].
getService(Components.interfaces.nsIProperties).
get("AChrom", Components.interfaces.nsIFile);
var msguri = msgHdr.folder.getUriForMsg(msgHdr);
messenger = Components.classes["@mozilla.org/messenger;1"]
.createInstance(Components.interfaces.nsIMessenger);
alert(messenger);
messenger.saveAttachmentToFolder(att.contentType,att.url,"attachmentname.extension",msguri,file);
}
} catch (err) {
alert(err);
}
}, true, { examineEncryptedParts: true, });
}