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);
nsGetImapServer(const char* username, const char* hostname,                nsIMsgIncomingServer ** aResult){    nsresult rv = NS_OK; 	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;    nsCOMPtr<nsIMsgIncomingServer> server;    rv = accountManager->FindServer(username,                                    hostname,                                    "imap",                                    getter_AddRefs(server));    if (NS_FAILED(rv)) return rv;    *aResult = server;    NS_IF_ADDREF(*aResult);    return rv;}