The Mozilla
Organization
Our Mission
Who We Are
Getting Involved
Community
Editorials
What's New
Newsbot
Development
Roadmap
Module Owners
Blue Sky
Projects
Status
Tools
Products
Source Code
Binaries
Documentation
License Terms
Bug Reports
Quality
Search
Feedback
 

Using the Account Manager API

By Alec Flett alecf@netscape.com

Structure

The account system consists of:

  • The Account Manager (nsIMsgAccountManager): There is a single account manager in the the client, which maintains the list of accounts, servers, etc. It is also responsible for the creation of any new account-related objects. The account manager maintains the main list of Accounts.
  • Accounts (nsIMsgAccount): An account consists of a single incoming server, and one or more identities. An account is merely a container to bind incoming servers and identities together.
  • Incoming Servers (nsIMsgIncomingServer): An incoming server represents a remote message store such as a POP, IMAP, or NNTP server. It holds all the information necessary to retrieve mail from the remote server, such as hostname, user login name, and biff settings.
  • Identities (nsIMsgIdentity): An identity contains all the information necessary to compose and outgoing mail message. It includes a user's full name and e-mail address. Currently it also contains SMTP server settings, but this should go away by M11.
Here's an example of a common setup.
(You'll have to pardon the crude drawing for now)

Account Manager
  +- Account 1
  |    +- Incoming Server 1 (imap.mywork.com IMAP Server, my work account)
  |    +- Identity 1 (Alec Flett <alecf@mywork.com>)
  +- Account 2
  |    +- Incoming Server 2 (pop.myisp.com POP Server, my ISP account)
  |    +- Identity 2 (Alec Flett <alecf@myisp.com>)
  +- Account 3
  |    +- Incoming Server 3 (news.myisp.com NNTP server, my ISP's server)
  |    +- Identity 3 (Alec Flett <alecfNOSPAM@myisp.com>)
  +- Account 4
       +- Incoming Server 4 (news.mozilla.org NNTP server, mozilla devel)
       +- Identity 2 (Alec Flett <alecf@myisp.com>)
       +- Identity 3 (Alec Flett <alecfNOSPAM@myisp.com>)
    

This is the internal structure that the mail client maintains, but it is presented to the user in a few different ways.

(You may have noticed that Identities 2 and 3 are shared between a few accounts...more on that later)

Server view

This view is used in the folder pane, and in any place where the user must browse or choose folders, such as the new folder dialog, search, filters, etc. This view shows a flat, unified view of all the servers. The above example would look like this:
alecf on imap.mywork.com
  +- INBOX
  +- Trash
  +- (etc)
alecf on pop.myisp.com
  +- INBOX
  +- Trash
  +- (etc)
news.myisp.com
  +- comp.os.linux.announce
  +- etc..
news.mozilla.org
  +- netscape.public.mozilla.announce
  +- netscape.public.mozilla.mail-news
    
Relevant API calls:
  • nsIMsgAccount.incomingServer
  • nsIMsgAccountManager.allServers: a list of all servers held by all accounts.

Identity view

This view gives a unified, uniquified list of all identities. If identities are shared between accounts, you will only see that identity once in the list. This view is used any time an identity needs to be chosen, such as when you choose an identity for the From header in the compose window.
In the above example, the list of identities would be as follows:
Alec Flett <alecf@mywork.com>)
Alec Flett <alecf@myisp.com>)
Alec Flett <alecfNOSPAM@myisp.com>)
    
Relevant API calls:
  • nsIMsgAccount.identities
  • nsIMsgAccountManager.allServers: a list of all servers across all accounts

Storage

The accounts are stored in the preferences. The accounts, identities, and servers are all linked via keys. Keys are simply internal strings that uniquely identify each account, identity and server. The keys are also used to decide the name of each of the preferences that hold the object's data.

As an example, the above structure would be represented in your preferences like this:

user_pref("mail.accountmanager.accounts", "account1,account2,account3");
user_pref("mail.account.account1.server", "server1");
user_pref("mail.account.account1.identities", "id1");
user_pref("mail.account.account2.server", "server2");
user_pref("mail.account.account2.identities", "id3");
user_pref("mail.account.account3.server", "server3");
user_pref("mail.account.account3.identities", "id3");
user_pref("mail.account.account4.server", "server4");
user_pref("mail.account.account4.identities", "id2,id3");
user_pref("mail.server.server1.hostname", "imap.mywork.com");
user_pref("mail.server.server2.hostname", "pop.myisp.com");
user_pref("mail.server.server3.hostname", "news.myisp.com");
user_pref("mail.server.server4.hostname", "news.mozilla.org");
user_pref("mail.identity.id1.useremail", "alecf@mywork.com");
user_pref("mail.identity.id2.useremail", "alecf@myisp.com");
user_pref("mail.identity.id3.useremail", "alecfNOSPAM@myisp.com");
    

There is a lot of information missing here of course.

The keys used here are the account1, server1, id1, etc. These keys are listed in the value of some of these preferences, such as "mail.accountmanager.accounts", and are used to construct the preference names, such as "mail.account.account1.server". This the way accounts know which server and which identities they contain.

Account creation/deletion

It is possible to create and modify accounts through the account manager API. The account manager is responsible for the creation of all accounts, incoming servers, and identities. You should not use CreateInstance() to create any of the relevant objects because the account manager needs to keep track of all of these objects as they are created.

Relevant API calls:
  • nsIMsgAccount nsIMsgAccountManager.createAccount()
  • nsIMsgAccount nsIMsgAccountManager.getAccount(in string key)
  • nsIMsgIncomingServer nsIMsgAccountManager.createIncomingServer(in string type)
  • nsIMsgIncomingServer nsIMsgAccountManager.getIncomingServer(in string key)

Copyright © 1998-1999 The Mozilla Organization.