The account system consists of:
+- 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)
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
Identities are used in the compose window. If identities are shared between accounts, you will only see that identity once in the list.
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>)
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.
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.
To create accounts using the API, you should do the following:
Some sample code: (where accountManager is the account manager.
var identity = accountManager.createIdentity();
identity.email="fred@myisp.com";
var server = accountManager.createIncomingServer("pop3");
server.userName = "fred";
server.hostname = "pop.myisp.com";
var account = accountManager.createAccount();
account.incomingServer = server;
account.AddIdentity(identity);
That's it! Now you have a working account, identity, and server.
It is possible, through some tricks with server and identity keys, to share servers and identities between accounts. You can do this by referring to the same identity or server key in the preferences, or with clever calls to the account manager. (Left as an exercise for the reader.)This will work but it is not supported. The UI will act slighty strange when you share information between accounts. The current plans prevent sharing of information between accounts using the UI.
Relevant API calls:
SMTP Servers are kept separately from all the other account management stuff. A user's SMTP servers are not actually dependant on any of the account settings. The only thing that determines which SMTP server a user should use is their physical connection to the internet. For instance, if a user is connected to the internet through MyISP, Inc. then he or she must use MyISP's SMTP server, no matter what identity they will be sending mail with.
The SMTP server list is accessable through the SMTP Service. You can add (and eventually delete) servers and have a default server.
SMTP servers are stored in your preferences in a manner resembling the accounts:
user_pref("mail.smtpservers", "server1,server2"); user_pref("mail.smtpserver.server1.hostname", "smtp.myisp.com"); user_pref("mail.smtpserver.server2.hostname", "smtp.mywork.com");
You can add new SMTP servers using the SMTP service.
var server = smtpService.createSmtpServer(); server.hostname = "smtp.myisp.com";
The default SMTP server is the first server in the list in your preferences. Currently, you can set the default SMTP server to something else by setting the defaultServer property on the smtpService, but that will not be saved to disk. Eventually there will be the concept of a session default server, and a permenant default server.
Relevant API calls:(When brendan's idldoc comes along, I'll just link to that)
All preferences are strings, unless otherwise noted.
The following are specific to POP:
The following are specific to news: