nsresult OESettings::GetCheckMailInterval(uint32_t *aInterval)
{
  nsCOMPtr<nsIWindowsRegKey> key;
  // '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
  nsresult rv = Find50Key(getter_AddRefs(key));
  if (NS_FAILED(rv))
    rv = Find40Key(getter_AddRefs(key));

  if (NS_FAILED(rv))
    return rv;

  nsCOMPtr<nsIWindowsRegKey> subKey;
  rv = key->OpenChild(NS_LITERAL_STRING("Mail"),
                      nsIWindowsRegKey::ACCESS_QUERY_VALUE,
                      getter_AddRefs(subKey));
  if (NS_FAILED(rv))
    return rv;

  uint32_t intValue;
  rv = subKey->ReadIntValue(NS_LITERAL_STRING("Poll For Mail"), &intValue);
  if (NS_SUCCEEDED(rv) && intValue != PR_UINT32_MAX)
    *aInterval = intValue / 60000;

  return rv;
}
Example #2
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;
}