2016-12-17 5 views
1

私は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

mozillaコードベースをブラウズして時間がたっても、満足のいく解決策が見つかりました。

let source = "From - Sat Nov 1 12:39:54 2008\n" + 
      "X-Mozilla-Status: 0001\n" + 
      "X-Mozilla-Status2: 00000000\n" + 
      "Message-ID: <" + msgId + ">\n" + 
      "Date: Wed, 11 Jun 2008 20:32:02 -0400\n" + 
      "From: Tester <[email protected]>\n" + 
      "MIME-Version: 1.0\n" + 
      "To: [email protected]\n" + 
      "Subject: " + aSubject + "\n" + 
      "Content-Type: text/plain; charset=ISO-8859-1\n" + 
      "Content-Transfer-Encoding: 7bit\n" + 
      "\n" + aBody + "\n"; 

folder.QueryInterface(Components.interfaces.nsIMsgLocalMailFolder); 
folder.addMessage(source); 
関連する問題