NS_WITH_SERVICE(nsIMsgMailSession, session, kMsgMailSessionCID, &rv); if (NS_FAILED(rv)) return rv; nsCOMPtr<nsIMsgAccountManager> accountManager; rv = session->GetAccountManager(getter_AddRefs(accountManager));
NS_WITH_SERVICE(nsIMsgAccountManager, accountManager, NS_MSGACCOUNTMANAGER_PROGID, &rv);
nsGetMailboxServer(const char *username, const char *hostname, nsIMsgIncomingServer** aResult){  nsresult rv = NS_OK;  nsUnescape(NS_CONST_CAST(char*,username));  nsUnescape(NS_CONST_CAST(char*,hostname));  // retrieve the AccountManager  NS_WITH_SERVICE(nsIMsgMailSession, session, kMsgMailSessionCID, &rv);  if (NS_FAILED(rv)) return rv;  nsCOMPtr<nsIMsgAccountManager> accountManager;  rv = session->GetAccountManager(getter_AddRefs(accountManager));  if (NS_FAILED(rv)) return rv;  // find all local mail "no servers" matching the given hostname  nsCOMPtr<nsIMsgIncomingServer> none_server;  rv = accountManager->FindServer(username,                                  hostname,                                  "none",                                  getter_AddRefs(none_server));  if (NS_SUCCEEDED(rv)) {	 *aResult = none_server;	  NS_ADDREF(*aResult);	  return rv;  }  // if that fails, look for the pop hosts matching the given hostname  nsCOMPtr<nsIMsgIncomingServer> pop3_server;  if (NS_FAILED(rv)) {	rv = accountManager->FindServer(username,                                  hostname,                                  "pop3",                                  getter_AddRefs(pop3_server));	if (NS_SUCCEEDED(rv)) {		*aResult = pop3_server;		NS_ADDREF(*aResult);		return rv;	}  }  // if you fail after looking at all "pop3" and all "none" servers, you fail.  return rv;}