On 16.01.2013 15:51, Jonathan Protzenko wrote:
> Hi,
>
> Please use fixIterator when you post such snippets, people don't have to
> deal with enumerators "by hand" in Thunderbird-land. This has caused a
> lot of problems (especially with nsISimpleEnumerator going away) so I
> think it's time to advertise that little-known yet very useful module :).
>
> Thanks,
>
> jonathan
>
Thanks Jonathan for your feedback.
I found that 'fixIterator' only by chance .. it would be great to have a
more public presentation of all (your) "little-known yet very useful
module" .. should say "modules"!
I have used 'fixIterator' already for a function to get the identity for
a given mail address (see below). But isn't that also loading code with
the .import?
Günter
> ext.msgnr.getIdentity = function (address) {
> // =========================================================================
> const Cu = Components.utils;
> const Ci = Components.interfaces;
> Cu.import("resource:///modules/iteratorUtils.jsm");
> Cu.import("resource:///modules/mailServices.js"); // needed for MailServices.compose etc.
> Cu.import("resource://gre/modules/Services.jsm"); // needed for Services.io etc.
>
> var identity = null;
> for each (var account in fixIterator(MailServices.accounts.accounts, Ci.nsIMsgAccount)) {
> for each (var id in fixIterator(account.identities, Ci.nsIMsgIdentity)) {
> // We're only interested in identities that have a real email.
> if (id.email == ext.mail.address(address).email) {
> identity = id;
> break;
> }
> }
> }
> if (identity == null) ext.msgnr.getAccountMngr().defaultAccount.defaultIdentity;
> return identity;
> };