bool OutlookSettings::DoImport(nsIMsgAccount **ppAccount) { HKEY hKey = FindAccountsKey(); if (hKey == nsnull) { IMPORT_LOG0("*** Error finding Outlook registry account keys\n"); return false; } nsresult rv; nsCOMPtr<nsIMsgAccountManager> accMgr = do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv); if (NS_FAILED(rv)) { IMPORT_LOG0("*** Failed to create a account manager!\n"); return false; } HKEY subKey = NULL; nsCString defMailName; if (::RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Microsoft\\Office\\Outlook\\OMI Account Manager", 0, KEY_QUERY_VALUE, &subKey) != ERROR_SUCCESS) if (::RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Microsoft\\Office\\8.0\\Outlook\\OMI Account Manager", 0, KEY_QUERY_VALUE, &subKey) != ERROR_SUCCESS) subKey = NULL; if (subKey != NULL) { // First let's get the default mail account key name BYTE * pBytes = nsOutlookRegUtil::GetValueBytes(subKey, "Default Mail Account"); ::RegCloseKey(subKey); if (pBytes) { defMailName = (const char *)pBytes; nsOutlookRegUtil::FreeValueBytes(pBytes); } } // Iterate the accounts looking for POP3 & IMAP accounts... // Ignore LDAP & NNTP for now! DWORD index = 0; DWORD numChars; TCHAR keyName[256]; FILETIME modTime; LONG result = ERROR_SUCCESS; BYTE * pBytes; int popCount = 0; int accounts = 0; nsCString keyComp; while (result == ERROR_SUCCESS) { numChars = 256; result = ::RegEnumKeyEx(hKey, index, keyName, &numChars, NULL, NULL, NULL, &modTime); index++; if (result == ERROR_SUCCESS) { if (::RegOpenKeyEx(hKey, keyName, 0, KEY_QUERY_VALUE, &subKey) == ERROR_SUCCESS) { // Get the values for this account. IMPORT_LOG1("Opened Outlook account: %s\n", (char *)keyName); nsIMsgAccount *anAccount = nsnull; pBytes = nsOutlookRegUtil::GetValueBytes(subKey, "IMAP Server"); if (pBytes) { if (DoIMAPServer(accMgr, subKey, (char *)pBytes, &anAccount)) accounts++; nsOutlookRegUtil::FreeValueBytes(pBytes); } pBytes = nsOutlookRegUtil::GetValueBytes(subKey, "POP3 Server"); if (pBytes) { if (popCount == 0) { if (DoPOP3Server(accMgr, subKey, (char *)pBytes, &anAccount)) { popCount++; accounts++; if (ppAccount && anAccount) { *ppAccount = anAccount; NS_ADDREF(anAccount); } } } else { if (DoPOP3Server(accMgr, subKey, (char *)pBytes, &anAccount)) { popCount++; accounts++; // If we created a mail account, get rid of it since // we have 2 POP accounts! if (ppAccount && *ppAccount) { NS_RELEASE(*ppAccount); *ppAccount = nsnull; } } } nsOutlookRegUtil::FreeValueBytes(pBytes); } if (anAccount) { // Is this the default account? keyComp = keyName; if (keyComp.Equals(defMailName)) { accMgr->SetDefaultAccount(anAccount); } NS_RELEASE(anAccount); } ::RegCloseKey(subKey); } } } // Now save the new acct info to pref file. rv = accMgr->SaveAccountInfo(); NS_ASSERTION(NS_SUCCEEDED(rv), "Can't save account info to pref file"); return accounts != 0; }
bool OESettings::DoImport(nsIMsgAccount **ppAccount) { HKEY hKey = FindAccountsKey(); if (hKey == nsnull) { IMPORT_LOG0("*** Error finding Outlook Express registry account keys\n"); return false; } nsresult rv; nsCOMPtr<nsIMsgAccountManager> accMgr = do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv); if (NS_FAILED(rv)) { IMPORT_LOG0("*** Failed to create a account manager!\n"); ::RegCloseKey(hKey); return false; } HKEY subKey; nsCString defMailName; // OE has default mail account here when it has been // set up by transfer or has multiple identities // look below for orig code that looked in new OE installs if (::RegOpenKeyEx(HKEY_CURRENT_USER, "Identities", 0, KEY_QUERY_VALUE, &subKey) == ERROR_SUCCESS) { BYTE * pBytes = nsOERegUtil::GetValueBytes(subKey, "Default User ID"); ::RegCloseKey(subKey); if (pBytes) { nsCString key("Identities\\"); key += (const char *)pBytes; nsOERegUtil::FreeValueBytes(pBytes); key += "\\Software\\Microsoft\\Internet Account Manager"; if (::RegOpenKeyEx(HKEY_CURRENT_USER, key.get(), 0, KEY_QUERY_VALUE , &subKey) == ERROR_SUCCESS) { BYTE * pBytes = nsOERegUtil::GetValueBytes(subKey, "Default Mail Account"); ::RegCloseKey(subKey); if (pBytes) { defMailName = (const char *)pBytes; nsOERegUtil::FreeValueBytes(pBytes); } } } } // else it must be here in original install location from orig code if (defMailName.IsEmpty()) { if (::RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Microsoft\\Outlook Express", 0, KEY_QUERY_VALUE, &subKey) == ERROR_SUCCESS) { BYTE * pBytes = nsOERegUtil::GetValueBytes(subKey, "Default Mail Account"); ::RegCloseKey(subKey); if (pBytes) { defMailName = (const char *)pBytes; nsOERegUtil::FreeValueBytes(pBytes); } } } // else defmailname will be "". No big deal. // 'poll for messages' setting in OE is a global setting // in OE options general tab and in following global OE // registry location. // for all accounts poll interval is a 32 bit value, 0 for // "don't poll", else milliseconds HKEY subSubKey; subKey = Find50Key(); if (!subKey) subKey = Find40Key(); // above key not critical checkNewMailTime = 30; checkNewMail = false; if (subKey){ if (::RegOpenKeyEx(subKey, "Mail", 0, KEY_QUERY_VALUE, &subSubKey) == ERROR_SUCCESS) { ::RegCloseKey(subKey); BYTE * pBytes = nsOERegUtil::GetValueBytes(subSubKey, "Poll For Mail"); ::RegCloseKey(subSubKey); if (pBytes) { if (*(PRInt32 *)pBytes != -1){ checkNewMail = true; checkNewMailTime = *(PRInt32 *)pBytes / 60000; } nsOERegUtil::FreeValueBytes(pBytes); } } } // Iterate the accounts looking for POP3 & IMAP accounts... // Ignore LDAP for now! DWORD index = 0; DWORD numChars; TCHAR keyName[256]; LONG result = ERROR_SUCCESS; BYTE * pBytes; int accounts = 0; nsCString keyComp; while (result == ERROR_SUCCESS) { numChars = 256; result = ::RegEnumKeyEx(hKey, index, keyName, &numChars, NULL, NULL, NULL, NULL); index++; if (result == ERROR_SUCCESS) { if (::RegOpenKeyEx(hKey, keyName, 0, KEY_QUERY_VALUE, &subKey) == ERROR_SUCCESS) { // Get the values for this account. IMPORT_LOG1("Opened Outlook Express account: %s\n", (char *)keyName); nsIMsgAccount *anAccount = nsnull; pBytes = nsOERegUtil::GetValueBytes(subKey, "IMAP Server"); if (pBytes) { if (DoIMAPServer(accMgr, subKey, (char *)pBytes, &anAccount)) accounts++; nsOERegUtil::FreeValueBytes(pBytes); } pBytes = nsOERegUtil::GetValueBytes(subKey, "NNTP Server"); if (pBytes) { if (DoNNTPServer(accMgr, subKey, (char *)pBytes, &anAccount)) accounts++; nsOERegUtil::FreeValueBytes(pBytes); } pBytes = nsOERegUtil::GetValueBytes(subKey, "POP3 Server"); if (pBytes) { if (DoPOP3Server(accMgr, subKey, (char *)pBytes, &anAccount)) { accounts++; } nsOERegUtil::FreeValueBytes(pBytes); } if (anAccount) { // Is this the default account? keyComp = keyName; if (keyComp.Equals(defMailName)) { accMgr->SetDefaultAccount(anAccount); } NS_RELEASE(anAccount); } ::RegCloseKey(subKey); } } } ::RegCloseKey(hKey); // Now save the new acct info to pref file. rv = accMgr->SaveAccountInfo(); NS_ASSERTION(NS_SUCCEEDED(rv), "Can't save account info to pref file"); return accounts != 0; }
bool OESettings::DoImport(nsIMsgAccount **aAccount) { nsCOMPtr<nsIWindowsRegKey> key; nsresult rv = FindAccountsKey(getter_AddRefs(key)); if (NS_FAILED(rv)) { IMPORT_LOG0( "*** Error finding Outlook Express registry account keys\n"); return false; } nsCOMPtr<nsIMsgAccountManager> accMgr = do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv); if (NS_FAILED(rv)) { IMPORT_LOG0("*** Failed to create a account manager!\n"); return false; } nsAutoString defMailName; rv = GetDefaultMailAccount(defMailName); checkNewMail = false; checkNewMailTime = 30; rv = GetCheckMailInterval(&checkNewMailTime); if (NS_SUCCEEDED(rv)) checkNewMail = true; // Iterate the accounts looking for POP3 & IMAP accounts... // Ignore LDAP for now! uint32_t accounts = 0; nsAutoString keyComp; uint32_t childCount = 0; key->GetChildCount(&childCount); for (uint32_t i = 0; i < childCount; i++) { nsAutoString keyName; key->GetChildName(i, keyName); nsCOMPtr<nsIWindowsRegKey> subKey; rv = key->OpenChild(keyName, nsIWindowsRegKey::ACCESS_QUERY_VALUE, getter_AddRefs(subKey)); if (NS_FAILED(rv)) continue; nsAutoCString nativeKeyName; NS_CopyUnicodeToNative(keyName, nativeKeyName); IMPORT_LOG1("Opened Outlook Express account: %s\n", nativeKeyName.get()); nsIMsgAccount *anAccount = nullptr; nsAutoString value; rv = subKey->ReadStringValue(NS_LITERAL_STRING("IMAP Server"), value); if (NS_SUCCEEDED(rv) && DoIMAPServer(accMgr, subKey, value, &anAccount)) accounts++; rv = subKey->ReadStringValue(NS_LITERAL_STRING("NNTP Server"), value); if (NS_SUCCEEDED(rv) && DoNNTPServer(accMgr, subKey, value, &anAccount)) accounts++; rv = subKey->ReadStringValue(NS_LITERAL_STRING("POP3 Server"), value); if (NS_SUCCEEDED(rv) && DoPOP3Server(accMgr, subKey, value, &anAccount)) accounts++; if (anAccount) { // Is this the default account? keyComp = keyName; if (keyComp.Equals(defMailName)) accMgr->SetDefaultAccount(anAccount); NS_RELEASE(anAccount); } } // Now save the new acct info to pref file. rv = accMgr->SaveAccountInfo(); NS_ASSERTION(NS_SUCCEEDED(rv), "Can't save account info to pref file"); return accounts != 0; }