在Thunderbird扩展中收到邮件发件人 [英] Getting mail sender in a Thunderbird extension

查看:167
本文介绍了在Thunderbird扩展中收到邮件发件人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个非常简单的Thunderbird扩展,它应该在发送邮件时提醒发件人的姓名以及收件人的姓名。问题是gMsgCompose.compFields.from字段在下面的代码段中是空的(.to字段按预期工作),它处理compose-send-message事件。我在这里缺少什么?

  function send_event_handler(evt){
var msgcomposeWindow = document.getElementById(msgcomposeWindow );
var msg_type = msgcomposeWindow.getAttribute(msgtype);

//不要继续,除非这是一个实际的发送事件
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);


解决方案

您可以通过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){
//身份找到
alert(identity.email);
}
}
}


I am working on a very simple Thunderbird extension, which is supposed to alert the name of the sender along with the names of the recipients whenever a mail is sent. The problem is that gMsgCompose.compFields.from field is empty in the below snippet (the .to field works as expected), which handles the "compose-send-message" event. What am I missing here?

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 );

解决方案

You can get the sending identity through the msgIdentity widget:

var identityWidget = document.getElementById('msgIdentity');
var fromIdentityKey= self.identityWidget.value;

Then, lookup identity information using the account manager:

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);
    }
  }
}

这篇关于在Thunderbird扩展中收到邮件发件人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆