我正在开发一个非常简单的Thunderbird扩展,它应该在发送邮件时提醒发件人的姓名以及收件人的姓名。问题是gMsgCompose.compFields.from字段在下面的代码段中是空的(.to字段按预期工作),它处理“compose-send-message”事件。我在这里缺少什么?
function send_event_handler( evt ) {
var msgcomposeWindow = document.getElementById( "msgcomposeWindow" );
var msg_type = msgcomposeWindow.getAttribute( "msgtype" );
// do not continue unless this is an actual send event
if( !(msg_type == nsIMsgCompDeliverMode.Now || msg_type == nsIMsgCompDeliverMode.Later) )
return;
var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService);
promptService.alert(window, "From", gMsgCompose.compFields.from);
promptService.alert(window, "To", gMsgCompose.compFields.to);
}
window.addEventListener( "compose-send-message", send_event_handler, true );
答案 0 :(得分:3)
您可以通过msgIdentity小部件获取发送标识:
var identityWidget = document.getElementById('msgIdentity');
var fromIdentityKey= self.identityWidget.value;
然后,使用客户经理查找身份信息:
var acctMgr = Components.classes["@mozilla.org/messenger/account-manager;1"]
.getService(Components.interfaces.nsIMsgAccountManager);
var accounts = acctMgr.accounts;
for (var i = 0; i < accounts.Count(); i++) {
var account = accounts.QueryElementAt(i, Components.interfaces.nsIMsgAccount);
var accountIdentities = account.identities;
for(var identCount = 0; identCount < accountIdentities.Count(); identCount++) {
var identity = accountIdentities.QueryElementAt(identCount,
Components.interfaces.nsIMsgIdentity);
if(identity.key == fromIdentityKey) {
// Identity found
alert(identity.email);
}
}
}
答案 1 :(得分:1)
或者在TB 7.0+中更方便和更方便简单地说:
alert(gCurrentIdentity.email);
无需getService()
并迭代,已经由TB设置,请参阅https://dxr.mozilla.org/comm-central/source/mail/components/compose/content/MsgComposeCommands.js#71