Code snippets
Kai edited this page Mar 17, 2014
·
5 revisions
Two things to produce code, that ist better to read:
- Use
MailServices
to access services like thensIMsgAccountManager
. You have to importresource:///modules/mailServices.js
to use this. - Use
fixIterator
to iterate over mozillas custom arrays likensISupportsArray
. You have to importresource:///modules/iteratorUtils.jsm
to use this.
Components.utils.import("resource:///modules/mailServices.js");
Components.utils.import("resource:///modules/iteratorUtils.jsm");
var accounts = MailServices.accounts.accounts;
// Old way: var accounts = Components.classes["@mozilla.org/messenger/account-manager;1"].getService(Components.interfaces.nsIMsgAccountManager).accounts;
for each (let thisAccount in fixIterator(accounts, Components.interfaces.nsIMsgAccount)) {
for each (let thisIdentity in fixIterator(thisAccount.identities, Components.interfaces.nsIMsgIdentity)) {
Application.console.log(thisIdentity.email);
}
/* old way:
for (var j = 0; j < thisAccount.identities.length; j++) {
var thisIdentity = thisAccount.identities.queryElementAt(j, Components.interfaces.nsIMsgIdentity);
Application.console.log(thisIdentity.email);
}
*/
}
Quellen: