2

メールが送信されるたびに、送信者の名前と受信者の名前を警告することになっている非常に単純な 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 );
4

2 に答える 2

3

msgIdentity ウィジェットを介して送信 ID を取得できます。

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

次に、アカウント マネージャーを使用して ID 情報を検索します。

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);
    }
  }
}
于 2010-12-01T22:44:10.020 に答える
2

または、TB 7.0+ では、次のように、より便利かつ簡単に:

alert(gCurrentIdentity.email);

反復する必要はありませんgetService()。TB によって既に設定されています。https://dxr.mozilla.org/comm-central/source/mail/components/compose/content/MsgComposeCommands.js#71を参照してください。

于 2012-10-29T18:57:16.143 に答える