سؤال

I'm trying to write a Thunderbird extension using XUL, a custom button that accesses the currently shown email message body and does something with it.

Apparently this would be possible using the global variable gDBView, as in the Display Mail User Agent extension:

var msgURI = null ;

if ( gDBView )
{
  msgURI = gDBView.URIForFirstSelectedMessage ;
}

if ( msgURI == null )
{
  return ;
}

var messenger = Components.classes["@mozilla.org/messenger;1"].createInstance (Components.interfaces.nsIMessenger ) ;
var msgService = messenger.messageServiceFromURI ( msgURI ) ;

Unfortunately if in my extension I replicate the row:

msgURI = gDBView.URIForFirstSelectedMessage ;    

I get the following error from the Thunderbird console:

gDBView is not defined

Is there a reason why this happens? And is this the best (and correct) way to access a mail body?

هل كانت مفيدة؟

المحلول

You're probably running your script in the wrong context, as Wladimir correctly guessed. An easy way to check that gDBView exists is, in the menus, to hit Tools > Error Console, then paste top.opener.gDBView, then hit Enter. This returns (for me) [xpconnect wrapped (nsISupports, nsIMsgDBView, nsITreeView)] which means the object indeed does exist.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top