在文件夹

时间:2016-12-17 14:18:10

标签: thunderbird

我正在写一个Thunderbird扩展,我想知道是否有办法创建一条消息并将其保存到某个文件夹中。代码看起来像这样。

create nsIMsgDBHdr header
header.subject = sub
header.from = from
header.to = to
header.body = body // although nsIMsgDBHdr doesen't have body attr
nsIMsgFolder folder
folder.save(header)

现在我正在用一种肮脏的方式来完成这项工作。我撰写消息以便稍后发送,将其存储在本地发件箱中,然后将其移动到给定的文件夹中。

var localSrv = accountManager.FindServer("nobody", "Local Folders", "none");
var localAcc = accountManager.FindAccountForServer(localSrv);
var outbox = localSrv.rootFolder.getChildNamed("Outbox");
var inbox = server.rootFolder.getChildNamed("Inbox");
var account = accountManager.FindAccountForServer(server);

let compFields = Components.classes["@mozilla.org/messengercompose/composefields;1"].createInstance(Components.interfaces.nsIMsgCompFields);
compFields.subject = subject;
compFields.from = fromAddr;
compFields.to = toAddr;
compFields.body = body;

let msgComposeParams = Components.classes["@mozilla.org/messengercompose/composeparams;1"].createInstance(Components.interfaces.nsIMsgComposeParams);
msgComposeParams.composeFields = compFields;

let gMsgCompose = Components.classes["@mozilla.org/messengercompose/compose;1"].createInstance(Components.interfaces.nsIMsgCompose);
gMsgCompose.initialize(msgComposeParams);
gMsgCompose.SendMsg(Components.interfaces.nsIMsgCompDeliverMode.Later,
                    account.defaultIdentity, // identity
                     account.key, // account
                     null, // message window
                     null); // nsIMsgProgress

let copyService = Components.classes["@mozilla.org/messenger/messagecopyservice;1"].getService(Components.interfaces.nsIMsgCopyService);

var jsMsgHdrArray = [];
var newestDate = -1;
var newestHdr;

for (let msgHdr in fixIterator(outbox.messages, Components.interfaces.nsIMsgDBHdr)) 
{
    if ( msgHdr.date > newestDate )
    {
        newestHdr = msgHdr;
        newestDate = msgHdr.date;
    }
}

jsMsgHdrArray.push(newestHdr);
let xpcomHdrArray = toXPCOMArray(jsMsgHdrArray, Components.interfaces.nsIMutableArray);  
copyService.CopyMessages(outbox, xpcomHdrArray, inbox, true, null, null, false);

1 个答案:

答案 0 :(得分:1)

经过数小时浏览mozilla代码库后,我找到了令人满意的解决方案。

synchronized