Пример #1
0
bool OutlookSettings::DoIMAPServer(nsIMsgAccountManager *aMgr,
                                   nsIWindowsRegKey *aKey,
                                   const nsString &aServerName,
                                   nsIMsgAccount **aAccount)
{
  nsAutoString userName;
  nsresult rv;
  rv = aKey->ReadStringValue(NS_LITERAL_STRING("IMAP User Name"), userName);
  if (NS_FAILED(rv))
    return false;

  bool result = false;

  // I now have a user name/server name pair, find out if it already exists?
  nsCAutoString nativeUserName;
  NS_CopyUnicodeToNative(userName, nativeUserName);
  nsCAutoString nativeServerName;
  NS_CopyUnicodeToNative(aServerName, nativeServerName);
  nsCOMPtr<nsIMsgIncomingServer> in;
  rv = aMgr->FindServer(nativeUserName,
                        nativeServerName,
                        NS_LITERAL_CSTRING("imap"),
                        getter_AddRefs(in));
  if (NS_FAILED(rv) || (in == nsnull)) {
    // Create the incoming server and an account for it?
    rv = aMgr->CreateIncomingServer(nativeUserName,
                                    nativeServerName,
                                    NS_LITERAL_CSTRING("imap"),
                                    getter_AddRefs(in));
    if (NS_SUCCEEDED(rv) && in) {
      rv = in->SetType(NS_LITERAL_CSTRING("imap"));
      // TODO SSL, auth method

      IMPORT_LOG2("Created IMAP server named: %s, userName: %s\n",
                  nativeServerName.get(), nativeUserName.get());

      nsAutoString prettyName;
      if (NS_SUCCEEDED(GetAccountName(aKey, aServerName, prettyName)))
        rv = in->SetPrettyName(prettyName);
      // We have a server, create an account.
      nsCOMPtr<nsIMsgAccount>  account;
      rv = aMgr->CreateAccount(getter_AddRefs(account));
      if (NS_SUCCEEDED(rv) && account) {
        rv = account->SetIncomingServer(in);

        IMPORT_LOG0("Created an account and set the IMAP server as the incoming server\n");

        // Fiddle with the identities
        SetIdentities(aMgr, account, aKey);
        result = true;
        if (aAccount)
          account.forget(aAccount);
      }
    }
  }
  else
    result = true;

  return result;
}
//----------------------------------------------------------------------------------------
static char* MakeUpperCase(char* aPath)
//----------------------------------------------------------------------------------------
{
  // windows does not care about case.  push to uppercase:
  nsAutoString widePath;
  nsDependentCString path(aPath);
  nsresult rv = NS_CopyNativeToUnicode(path, widePath);
  if (NS_FAILED(rv)) {
      NS_ERROR("failed to convert a path to Unicode");
      return aPath;
  }

  PRUnichar *start = widePath.BeginWriting();
  PRUnichar *end = widePath.EndWriting();

  while (start != end) {
      // XXX this doesn't change any non-ASCII character 
      *start = towupper(*start);
      ++start;
  }

  nsCAutoString newCPath;
  NS_CopyUnicodeToNative(widePath, newCPath); 
  NS_ASSERTION(path.Length() >= newCPath.Length(), 
               "uppercased string is longer than original");
  ::strcpy(aPath, newCPath.get());

  return aPath;
}
Пример #3
0
//--------------------------------------------------------
// Create a child window "control"
static HWND CreateControl(LPCTSTR          aType,
                          DWORD            aStyle,
                          HINSTANCE        aHInst, 
                          HWND             aHdlg, 
                          int              aId, 
                          const nsAString& aStr, 
                          const nsIntRect& aRect)
{
  nsAutoCString str;
  if (NS_FAILED(NS_CopyUnicodeToNative(aStr, str)))
    return nullptr;

  HWND hWnd = ::CreateWindow (aType, str.get(),
                              WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE | aStyle,
                              aRect.x, aRect.y, aRect.width, aRect.height,
                              (HWND)aHdlg, (HMENU)(intptr_t)aId,
                              aHInst, nullptr);
  if (hWnd == nullptr) return nullptr;

  // get the native font for the dialog and 
  // set it into the new control
  HFONT hFont = (HFONT)::SendMessage(aHdlg, WM_GETFONT, (WPARAM)0, (LPARAM)0);
  if (hFont != nullptr) {
    ::SendMessage(hWnd, WM_SETFONT, (WPARAM) hFont, (LPARAM)0);
  }
  return hWnd;
}
Пример #4
0
//--------------------------------------------------------
// Set a multi-byte string in the control
static void SetTextOnWnd(HWND aControl, const nsString& aStr)
{
  nsAutoCString text;
  if (NS_SUCCEEDED(NS_CopyUnicodeToNative(aStr, text))) {
    ::SetWindowText(aControl, text.get());
  }
}
Пример #5
0
nsresult OutlookSettings::SetSmtpServer(nsIMsgAccountManager *aMgr,
                                        nsIMsgAccount *aAcc,
                                        nsIMsgIdentity *aId,
                                        const nsString &aServer,
                                        const nsString &aUser)
{
  nsresult rv;
  nsCOMPtr<nsISmtpService> smtpService(do_GetService(NS_SMTPSERVICE_CONTRACTID, &rv));
  NS_ENSURE_SUCCESS(rv, rv);

  nsCAutoString nativeUserName;
  NS_CopyUnicodeToNative(aUser, nativeUserName);
  nsCAutoString nativeServerName;
  NS_CopyUnicodeToNative(aServer, nativeServerName);
  nsCOMPtr<nsISmtpServer> foundServer;
  rv = smtpService->FindServer(nativeUserName.get(),
                               nativeServerName.get(),
                               getter_AddRefs(foundServer));
  if (NS_SUCCEEDED(rv) && foundServer) {
    if (aId)
      SetSmtpServerKey(aId, foundServer);
    IMPORT_LOG1("SMTP server already exists: %s\n",
                nativeServerName.get());
    return rv;
  }

  nsCOMPtr<nsISmtpServer> smtpServer;
  rv = smtpService->CreateSmtpServer(getter_AddRefs(smtpServer));
  NS_ENSURE_SUCCESS(rv, rv);

  smtpServer->SetHostname(nativeServerName);
  if (!aUser.IsEmpty())
    smtpServer->SetUsername(nativeUserName);

  if (aId)
    SetSmtpServerKey(aId, smtpServer);

  // TODO SSL, auth method
  IMPORT_LOG1("Ceated new SMTP server: %s\n",
              nativeServerName.get());
  return NS_OK;
}
Пример #6
0
static char*
UnicodeToNative(JSContext *cx, const jschar *source, size_t slen)
{
  nsCAutoString native;
  nsDependentString unicode(source, slen);
  nsresult rv = NS_CopyUnicodeToNative(unicode, native);
  if (NS_FAILED(rv)) {
    JS_ReportError(cx, "could not convert string to native charset");
    return NULL;
  }

  char* result = static_cast<char*>(JS_malloc(cx, native.Length() + 1));
  if (!result)
    return NULL;

  memcpy(result, native.get(), native.Length() + 1);
  return result;
}
Пример #7
0
NS_UTF16ToCString(const nsAString& aSrc,
                  nsCStringEncoding aDestEncoding,
                  nsACString& aDest)
{
  switch (aDestEncoding) {
    case NS_CSTRING_ENCODING_ASCII:
      LossyCopyUTF16toASCII(aSrc, aDest);
      break;
    case NS_CSTRING_ENCODING_UTF8:
      CopyUTF16toUTF8(aSrc, aDest);
      break;
    case NS_CSTRING_ENCODING_NATIVE_FILESYSTEM:
      NS_CopyUnicodeToNative(aSrc, aDest);
      break;
    default:
      return NS_ERROR_NOT_IMPLEMENTED;
  }

  return NS_OK; // XXX report errors
}
Пример #8
0
// Add a new PKCS11 module to the user's profile.
NS_IMETHODIMP
nsPkcs11::AddModule(const nsAString& aModuleName,
                    const nsAString& aLibraryFullPath,
                    int32_t aCryptoMechanismFlags,
                    int32_t aCipherFlags)
{
  nsNSSShutDownPreventionLock locker;
  if (isAlreadyShutDown()) {
    return NS_ERROR_NOT_AVAILABLE;
  }

  if (aModuleName.IsEmpty()) {
    return NS_ERROR_INVALID_ARG;
  }

  NS_ConvertUTF16toUTF8 moduleName(aModuleName);
  nsCString fullPath;
  // NSS doesn't support Unicode path.  Use native charset
  NS_CopyUnicodeToNative(aLibraryFullPath, fullPath);
  uint32_t mechFlags = SECMOD_PubMechFlagstoInternal(aCryptoMechanismFlags);
  uint32_t cipherFlags = SECMOD_PubCipherFlagstoInternal(aCipherFlags);
  SECStatus srv = SECMOD_AddNewModule(moduleName.get(), fullPath.get(),
                                      mechFlags, cipherFlags);
  if (srv != SECSuccess) {
    return NS_ERROR_FAILURE;
  }

#ifndef MOZ_NO_SMART_CARDS
  mozilla::UniqueSECMODModule module(SECMOD_FindModule(moduleName.get()));
  if (!module) {
    return NS_ERROR_FAILURE;
  }
  nsCOMPtr<nsINSSComponent> nssComponent(
    do_GetService(PSM_COMPONENT_CONTRACTID));
  nssComponent->LaunchSmartCardThread(module.get());
#endif

  return NS_OK;
}
Пример #9
0
nsresult 
net_GetURLSpecFromActualFile(nsIFile *aFile, nsACString &result)
{
    nsresult rv;
    nsAutoCString nativePath, ePath;
    nsAutoString path;

    rv = aFile->GetNativePath(nativePath);
    if (NS_FAILED(rv)) return rv;

    // Convert to unicode and back to check correct conversion to native charset
    NS_CopyNativeToUnicode(nativePath, path);
    NS_CopyUnicodeToNative(path, ePath);

    // Use UTF8 version if conversion was successful
    if (nativePath == ePath)
        CopyUTF16toUTF8(path, ePath);
    else
        ePath = nativePath;
    
    nsAutoCString escPath;
    NS_NAMED_LITERAL_CSTRING(prefix, "file://");
        
    // Escape the path with the directory mask
    if (NS_EscapeURL(ePath.get(), -1, esc_Directory+esc_Forced, escPath))
        escPath.Insert(prefix, 0);
    else
        escPath.Assign(prefix + ePath);

    // esc_Directory does not escape the semicolons, so if a filename 
    // contains semicolons we need to manually escape them.
    // This replacement should be removed in bug #473280
    escPath.ReplaceSubstring(";", "%3b");
    result = escPath;
    return NS_OK;
}
Пример #10
0
void OutlookSettings::SetIdentities(nsIMsgAccountManager *aMgr,
                                    nsIMsgAccount *aAcc,
                                    nsIWindowsRegKey *aKey)
{
  // Get the relevant information for an identity
  nsAutoString name;
  aKey->ReadStringValue(NS_LITERAL_STRING("SMTP Display Name"), name);

  nsAutoString server;
  aKey->ReadStringValue(NS_LITERAL_STRING("SMTP Server"), server);

  nsAutoString email;
  aKey->ReadStringValue(NS_LITERAL_STRING("SMTP Email Address"), email);

  nsAutoString reply;
  aKey->ReadStringValue(NS_LITERAL_STRING("SMTP Reply To Email Address"), reply);

  nsAutoString userName;
  aKey->ReadStringValue(NS_LITERAL_STRING("SMTP User Name"), userName);

  nsAutoString orgName;
  aKey->ReadStringValue(NS_LITERAL_STRING("SMTP Organization Name"), orgName);

  nsresult rv;
  nsCOMPtr<nsIMsgIdentity>  id;
  if (!email.IsEmpty() && !name.IsEmpty() && !server.IsEmpty()) {
    // The default identity, nor any other identities matched,
    // create a new one and add it to the account.
    rv = aMgr->CreateIdentity(getter_AddRefs(id));
    if (id) {
      id->SetFullName(name);
      id->SetIdentityName(name);
      id->SetOrganization(orgName);

      nsCAutoString nativeEmail;
      NS_CopyUnicodeToNative(email, nativeEmail);
      id->SetEmail(nativeEmail);
      if (!reply.IsEmpty()) {
        nsCAutoString nativeReply;
        NS_CopyUnicodeToNative(reply, nativeReply);
        id->SetReplyTo(nativeReply);
      }
      aAcc->AddIdentity(id);

      nsCAutoString nativeName;
      NS_CopyUnicodeToNative(name, nativeName);
      IMPORT_LOG0("Created identity and added to the account\n");
      IMPORT_LOG1("\tname: %s\n", nativeName.get());
      IMPORT_LOG1("\temail: %s\n", nativeEmail.get());
    }
  }

  if (userName.IsEmpty()) {
    nsCOMPtr<nsIMsgIncomingServer>  incomingServer;
    rv = aAcc->GetIncomingServer(getter_AddRefs(incomingServer));
    if (NS_SUCCEEDED(rv) && incomingServer) {
      nsCAutoString nativeUserName;
      rv = incomingServer->GetUsername(nativeUserName);
      NS_ASSERTION(NS_SUCCEEDED(rv), "Unable to get UserName from incomingServer");
      NS_CopyNativeToUnicode(nativeUserName, userName);
    }
  }

  SetSmtpServer(aMgr, aAcc, id, server, userName);
}
Пример #11
0
bool OutlookSettings::DoPOP3Server(nsIMsgAccountManager *aMgr,
                                   nsIWindowsRegKey *aKey,
                                   const nsString &aServerName,
                                   nsIMsgAccount **aAccount)
{
  nsAutoString userName;
  nsresult rv;
  rv = aKey->ReadStringValue(NS_LITERAL_STRING("POP3 User Name"), userName);
  if (NS_FAILED(rv))
    return false;

  // I now have a user name/server name pair, find out if it already exists?
  nsCAutoString nativeUserName;
  NS_CopyUnicodeToNative(userName, nativeUserName);
  nsCAutoString nativeServerName;
  NS_CopyUnicodeToNative(aServerName, nativeServerName);
  nsCOMPtr<nsIMsgIncomingServer> in;
  rv = aMgr->FindServer(nativeUserName,
                        nativeServerName,
                        NS_LITERAL_CSTRING("pop3"),
                        getter_AddRefs(in));
  if (NS_SUCCEEDED(rv))
    return true;

  // Create the incoming server and an account for it?
  rv = aMgr->CreateIncomingServer(nativeUserName,
                                  nativeServerName,
                                  NS_LITERAL_CSTRING("pop3"),
                                  getter_AddRefs(in));
  rv = in->SetType(NS_LITERAL_CSTRING("pop3"));

  // TODO SSL, auth method

  nsCOMPtr<nsIPop3IncomingServer> pop3Server = do_QueryInterface(in);
  NS_ENSURE_SUCCESS(rv, false);

  // set local folders as the Inbox to use for this POP3 server
  nsCOMPtr<nsIMsgIncomingServer> localFoldersServer;
  aMgr->GetLocalFoldersServer(getter_AddRefs(localFoldersServer));

  if (!localFoldersServer) {
    // XXX: We may need to move this local folder creation code to the generic nsImportSettings code
    // if the other import modules end up needing to do this too.
    // if Local Folders does not exist already, create it
    rv = aMgr->CreateLocalMailAccount();
    if (NS_FAILED(rv)) {
      IMPORT_LOG0("*** Failed to create Local Folders!\n");
      return false;
    }
    aMgr->GetLocalFoldersServer(getter_AddRefs(localFoldersServer));
  }

  // now get the account for this server
  nsCOMPtr<nsIMsgAccount> localFoldersAccount;
  aMgr->FindAccountForServer(localFoldersServer, getter_AddRefs(localFoldersAccount));
  if (localFoldersAccount) {
    nsCString localFoldersAcctKey;
    localFoldersAccount->GetKey(localFoldersAcctKey);
    pop3Server->SetDeferredToAccount(localFoldersAcctKey);
    pop3Server->SetDeferGetNewMail(true);
  }

  IMPORT_LOG2("Created POP3 server named: %s, userName: %s\n",
              nativeServerName.get(),
              nativeUserName.get());

  nsString prettyName;
  rv = GetAccountName(aKey, aServerName, prettyName);
  if (NS_FAILED(rv))
    return false;

  rv = in->SetPrettyName(prettyName);
  // We have a server, create an account.
  nsCOMPtr<nsIMsgAccount>  account;
  rv = aMgr->CreateAccount(getter_AddRefs(account));
  if (NS_FAILED(rv))
    return false;

  rv = account->SetIncomingServer(in);

  IMPORT_LOG0("Created a new account and set the incoming server to the POP3 server.\n");

  PRUint32 leaveOnServer;
  rv = aKey->ReadIntValue(NS_LITERAL_STRING("Leave Mail On Server"), &leaveOnServer);
  if (NS_SUCCEEDED(rv))
    pop3Server->SetLeaveMessagesOnServer(leaveOnServer == 1 ? true : false);

  // Fiddle with the identities
  SetIdentities(aMgr, account, aKey);

  if (aAccount)
    account.forget(aAccount);

  return true;
}
bool OESettings::DoIMAPServer(nsIMsgAccountManager *aMgr,
                              nsIWindowsRegKey *aKey,
                              const nsString &aServerName,
                              nsIMsgAccount **ppAccount)
{
  if (ppAccount)
    *ppAccount = nullptr;

  nsAutoString userName;
  nsresult rv;
  rv = aKey->ReadStringValue(NS_LITERAL_STRING("IMAP User Name"), userName);
  if (NS_FAILED(rv))
    return false;

  nsAutoCString nativeUserName;
  NS_CopyUnicodeToNative(userName, nativeUserName);
  nsAutoCString nativeServerName;
  NS_CopyUnicodeToNative(aServerName, nativeServerName);
  // I now have a user name/server name pair, find out if it already exists?
  nsCOMPtr<nsIMsgIncomingServer> in;
  rv = aMgr->FindServer(nativeUserName,
                        nativeServerName,
                        NS_LITERAL_CSTRING("imap"),
                        getter_AddRefs(in));
  if (NS_SUCCEEDED(rv)) {
    // for an existing server we create another identity,
    //  TB lists under 'manage identities'
    nsCOMPtr<nsIMsgAccount> account;
    rv = aMgr->FindAccountForServer(in, getter_AddRefs(account));
    if (NS_FAILED(rv))
      return false;

    IMPORT_LOG0("Created an identity and added to existing IMAP incoming server\n");
    // Fiddle with the identities
    int32_t authMethod;
    in->GetAuthMethod(&authMethod);
    SetIdentities(aMgr, account, aKey, userName, authMethod, false);
    if (ppAccount)
      account->QueryInterface(NS_GET_IID(nsIMsgAccount),
                              (void **)ppAccount);
    return true;
  }

  // Create the incoming server and an account for it?
  rv = aMgr->CreateIncomingServer(nativeUserName,
                                  nativeServerName,
                                  NS_LITERAL_CSTRING("imap"),
                                  getter_AddRefs(in));
  NS_ENSURE_SUCCESS(rv, false);

  nsAutoString rootFolder;
  rv = aKey->ReadStringValue(NS_LITERAL_STRING("IMAP Root Folder"), rootFolder);
  if (NS_SUCCEEDED(rv) && !rootFolder.IsEmpty()) {
    nsCOMPtr<nsIImapIncomingServer> imapServer = do_QueryInterface(in);
    nsAutoCString nativeRootFolder;
    NS_CopyUnicodeToNative(rootFolder, nativeRootFolder);
    imapServer->SetServerDirectory(nativeRootFolder);
  }

  SetIncomingServerProperties(in, aKey, NS_LITERAL_STRING("IMAP "));

  IMPORT_LOG2("Created IMAP server named: %s, userName: %s\n",
              nativeServerName.get(), nativeUserName.get());

  nsAutoString prettyName;
  if (NS_SUCCEEDED(GetAccountName(aKey, aServerName, prettyName)))
    rv = in->SetPrettyName(prettyName);

  // We have a server, create an account.
  nsCOMPtr<nsIMsgAccount> account;
  rv = aMgr->CreateAccount(getter_AddRefs(account));
  if (NS_SUCCEEDED(rv) && account) {
    rv = account->SetIncomingServer(in);

    IMPORT_LOG0("Created an account and set the IMAP server as the incoming server\n");

    // Fiddle with the identities
    int32_t authMethod;
    in->GetAuthMethod(&authMethod);
    SetIdentities(aMgr, account, aKey, userName, authMethod, false);
    if (ppAccount)
      account->QueryInterface(NS_GET_IID(nsIMsgAccount), (void **)ppAccount);
    return true;
  }

  return false;
}
Пример #13
0
bool OutlookSettings::DoImport(nsIMsgAccount **aAccount)
{
  nsCOMPtr<nsIWindowsRegKey> key;
  nsresult rv = OutlookSettings::FindAccountsKey(getter_AddRefs(key));
  if (NS_FAILED(rv)) {
    IMPORT_LOG0("*** Error finding Outlook 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 = GetDefaultMailAccountName(defMailName);

  PRUint32 childCount;
  key->GetChildCount(&childCount);

  PRUint32 accounts = 0;
  PRUint32 popCount = 0;
  for (PRUint32 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;

    // Get the values for this account.
    nsCAutoString nativeKeyName;
    NS_CopyUnicodeToNative(keyName, nativeKeyName);
    IMPORT_LOG1("Opened Outlook account: %s\n", nativeKeyName.get());

    nsCOMPtr<nsIMsgAccount> account;
    nsAutoString value;
    rv = subKey->ReadStringValue(NS_LITERAL_STRING("IMAP Server"), value);
    if (NS_SUCCEEDED(rv) &&
        DoIMAPServer(accMgr, subKey, value, getter_AddRefs(account)))
      accounts++;

    rv = subKey->ReadStringValue(NS_LITERAL_STRING("POP3 Server"), value);
    if (NS_SUCCEEDED(rv) &&
        DoPOP3Server(accMgr, subKey, value, getter_AddRefs(account))) {
      popCount++;
      accounts++;
      if (aAccount && account) {
        // If we created a mail account, get rid of it since
        // we have 2 POP accounts!
        if (popCount > 1)
          NS_RELEASE(*aAccount);
        else
          NS_ADDREF(*aAccount = account);
      }
    }

    // Is this the default account?
    if (account && keyName.Equals(defMailName))
      accMgr->SetDefaultAccount(account);
  }

  // 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::DoPOP3Server(nsIMsgAccountManager *aMgr,
                              nsIWindowsRegKey *aKey,
                              const nsString &aServerName,
                              nsIMsgAccount **ppAccount)
{
  if (ppAccount)
    *ppAccount = nullptr;

  nsAutoString userName;
  nsresult rv;
  rv = aKey->ReadStringValue(NS_LITERAL_STRING("POP3 User Name"), userName);
  if (NS_FAILED(rv))
    return false;

  nsAutoCString nativeUserName;
  NS_CopyUnicodeToNative(userName, nativeUserName);
  nsAutoCString nativeServerName;
  NS_CopyUnicodeToNative(aServerName, nativeServerName);

  // I now have a user name/server name pair, find out if it already exists?
  nsCOMPtr<nsIMsgIncomingServer> in;
  rv = aMgr->FindServer(nativeUserName,
                        nativeServerName,
                        NS_LITERAL_CSTRING("pop3"),
                        getter_AddRefs(in));
  if (NS_SUCCEEDED(rv)) {
    IMPORT_LOG2("Existing POP3 server named: %s, userName: %s\n",
                nativeUserName.get(), nativeServerName.get());
    // for an existing server we create another identity,
    // TB listed under 'manage identities'
    nsCOMPtr<nsIMsgAccount>  account;
    rv = aMgr->FindAccountForServer(in, getter_AddRefs(account));
    if (NS_SUCCEEDED(rv) && account) {
      IMPORT_LOG0("Created identity and added to existing POP3 incoming server.\n");
      // Fiddle with the identities
      int32_t authMethod;
      in->GetAuthMethod(&authMethod);
      SetIdentities(aMgr, account, aKey, userName, authMethod, false);
      if (ppAccount)
        account->QueryInterface(NS_GET_IID(nsIMsgAccount), (void **)ppAccount);
      return true;
    }
    return false;
  }

  // Create the incoming server and an account for it?
  rv = aMgr->CreateIncomingServer(nativeUserName,
                                  nativeServerName,
                                  NS_LITERAL_CSTRING("pop3"),
                                  getter_AddRefs( in));
  if (NS_FAILED(rv))
    return false;

  SetIncomingServerProperties(in, aKey, NS_LITERAL_STRING("POP3 "));

  nsCOMPtr<nsIPop3IncomingServer> pop3Server = do_QueryInterface(in);
  if (pop3Server) {
    // set local folders as the Inbox to use for this POP3 server
    nsCOMPtr<nsIMsgIncomingServer> localFoldersServer;
    aMgr->GetLocalFoldersServer(getter_AddRefs(localFoldersServer));

    if (!localFoldersServer)
    {
      // If Local Folders does not exist already, create it

      if (NS_FAILED(aMgr->CreateLocalMailAccount())) {
        IMPORT_LOG0("*** Failed to create Local Folders!\n");
        return false;
      }

      aMgr->GetLocalFoldersServer(getter_AddRefs(localFoldersServer));
    }

    // now get the account for this server
    nsCOMPtr<nsIMsgAccount> localFoldersAccount;
    aMgr->FindAccountForServer(localFoldersServer, getter_AddRefs(localFoldersAccount));
    if (localFoldersAccount)
    {
      nsCString localFoldersAcctKey;
      localFoldersAccount->GetKey(localFoldersAcctKey);
      pop3Server->SetDeferredToAccount(localFoldersAcctKey);
    }

    uint32_t intValue;
    rv = aKey->ReadIntValue(NS_LITERAL_STRING("POP3 Skip Account"), &intValue);
    // OE:0=='Include this account when receiving mail or synchronizing'==
    // TB:1==AM:Server:advanced:Include this server when getting new mail
    pop3Server->SetDeferGetNewMail(NS_SUCCEEDED(rv) && intValue == 0);

    rv = aKey->ReadIntValue(NS_LITERAL_STRING("Leave Mail On Server"),
                            &intValue);
    pop3Server->SetLeaveMessagesOnServer(NS_SUCCEEDED(rv) && intValue == 1);

    rv = aKey->ReadIntValue(NS_LITERAL_STRING("Remove When Deleted"),
                            &intValue);
    pop3Server->SetDeleteMailLeftOnServer(NS_SUCCEEDED(rv) && intValue == 1);

    rv = aKey->ReadIntValue(NS_LITERAL_STRING("Remove When Expired"),
                            &intValue);
    pop3Server->SetDeleteByAgeFromServer(NS_SUCCEEDED(rv) && intValue == 1);

    rv = aKey->ReadIntValue(NS_LITERAL_STRING("Expire Days"),
                            &intValue);
    if (NS_SUCCEEDED(rv))
      pop3Server->SetNumDaysToLeaveOnServer(static_cast<int32_t>(intValue));
  }
  IMPORT_LOG2("Created POP3 server named: %s, userName: %s\n",
              nativeServerName.get(), nativeUserName.get());
  nsString prettyName;
  if (NS_SUCCEEDED(GetAccountName(aKey, aServerName, prettyName)))
    rv = in->SetPrettyName(prettyName);

  // We have a server, create an account.
  nsCOMPtr<nsIMsgAccount>  account;
  rv = aMgr->CreateAccount(getter_AddRefs( account));
  if (NS_SUCCEEDED( rv) && account) {
    rv = account->SetIncomingServer(in);
    IMPORT_LOG0("Created a new account and set the incoming server to the POP3 server.\n");

    int32_t authMethod;
    in->GetAuthMethod(&authMethod);
    // Fiddle with the identities
    SetIdentities(aMgr, account, aKey, userName, authMethod, false);
    if (ppAccount)
      account->QueryInterface(NS_GET_IID(nsIMsgAccount),
                               (void **)ppAccount);
    return true;
  }

  return false;
}
Пример #15
0
NS_IMETHODIMP
nsAuthSASL::GetNextToken(const void *inToken,
                         PRUint32    inTokenLen,
                         void      **outToken,
                         PRUint32   *outTokenLen)
{
    nsresult rv;
    void *unwrappedToken;
    char *message;
    PRUint32 unwrappedTokenLen, messageLen;
    nsCAutoString userbuf;
    
    if (!mInnerModule) 
        return NS_ERROR_NOT_INITIALIZED;

    if (mSASLReady) {
        // If the server COMPLETEs with an empty token, Cyrus sends us that token.
        // I don't think this is correct, but we need to handle that behaviour.
        // Cyrus ignores the contents of our reply token.
        if (inTokenLen == 0) {
            *outToken = NULL;
            *outTokenLen = 0;
            return NS_OK;
        }
        // We've completed the GSSAPI portion of the handshake, and are
        // now ready to do the SASL security layer and authzid negotiation

        // Input packet from the server needs to be unwrapped.
        rv = mInnerModule->Unwrap(inToken, inTokenLen, &unwrappedToken, 
                                  &unwrappedTokenLen);
        if (NS_FAILED(rv)) {
            Reset();
            return rv;
        }
        
        // If we were doing security layers then we'd care what the
        // server had sent us. We're not, so all we had to do was make
        // sure that the signature was correct with the above unwrap()
        nsMemory::Free(unwrappedToken);
        
        NS_CopyUnicodeToNative(mUsername, userbuf);
        messageLen = userbuf.Length() + 4 + 1;
        message = (char *)nsMemory::Alloc(messageLen);
        if (!message) {
          Reset();
          return NS_ERROR_OUT_OF_MEMORY;
        }
        message[0] = 0x01; // No security layer
        message[1] = 0x00;
        message[2] = 0x00;
        message[3] = 0x00; // Maxbuf must be zero if we've got no sec layer
        strcpy(message+4, userbuf.get());
        // Userbuf should not be NULL terminated, so trim the trailing NULL
        // when wrapping the message
        rv = mInnerModule->Wrap((void *) message, messageLen-1, PR_FALSE, 
                                outToken, outTokenLen);
        nsMemory::Free(message);
        Reset(); // All done
        return NS_SUCCEEDED(rv) ? NS_SUCCESS_AUTH_FINISHED : rv;
    }
    rv = mInnerModule->GetNextToken(inToken, inTokenLen, outToken, 
                                    outTokenLen);
    if (rv == NS_SUCCESS_AUTH_FINISHED) {
        mSASLReady = true;
        rv = NS_OK;
    }
    return rv;
}
bool OESettings::DoNNTPServer(nsIMsgAccountManager *aMgr,
                              nsIWindowsRegKey *aKey,
                              const nsString &aServerName,
                              nsIMsgAccount **ppAccount)
{
  if (ppAccount)
    *ppAccount = nullptr;

  nsAutoString userName;
  nsresult rv;
  // this only exists if NNTP server requires it or not anon login
  rv = aKey->ReadStringValue(NS_LITERAL_STRING("NNTP User Name"), userName);

  bool result = false;

  nsAutoCString nativeServerName;
  NS_CopyUnicodeToNative(aServerName, nativeServerName);
  // I now have a user name/server name pair, find out if it already exists?
  // NNTP can have empty user name.  This is wild card in findserver
  nsCOMPtr<nsIMsgIncomingServer> in;
  rv = aMgr->FindServer(EmptyCString(),
                        nativeServerName,
                        NS_LITERAL_CSTRING("nntp"),
                        getter_AddRefs(in));
  if (NS_FAILED(rv) || (in == nullptr)) {
    // Create the incoming server and an account for it?
    rv = aMgr->CreateIncomingServer(EmptyCString(),
                                    nativeServerName,
                                    NS_LITERAL_CSTRING("nntp"),
                                    getter_AddRefs(in));
    if (NS_SUCCEEDED(rv) && in) {
      uint32_t port = 0;
      rv = aKey->ReadIntValue(NS_LITERAL_STRING("NNTP Port"),
                              &port);
      if (NS_SUCCEEDED(rv) && port && port != 119)
        in->SetPort(static_cast<int32_t>(port));

      nsAutoCString nativeUserName;
      NS_CopyUnicodeToNative(userName, nativeUserName);
      // do nntpincomingserver stuff
      nsCOMPtr<nsINntpIncomingServer> nntpServer = do_QueryInterface(in);
      if (nntpServer && !userName.IsEmpty()) {
        nntpServer->SetPushAuth(true);
        in->SetUsername(nativeUserName);
      }

      IMPORT_LOG2("Created NNTP server named: %s, userName: %s\n",
                  nativeServerName.get(), nativeUserName.get());

      nsString prettyName;
      if (NS_SUCCEEDED(GetAccountName(aKey, aServerName, prettyName)))
        rv = in->SetPrettyName(prettyName);

      // We have a server, create an account.
      nsCOMPtr<nsIMsgAccount> account;
      rv = aMgr->CreateAccount(getter_AddRefs(account));
      if (NS_SUCCEEDED(rv) && account) {
        rv = account->SetIncomingServer(in);

        IMPORT_LOG0("Created an account and set the NNTP server as the incoming server\n");

        // Fiddle with the identities
        SetIdentities(aMgr, account, aKey, userName, 0, true);
        result = true;
        if (ppAccount)
          account->QueryInterface(NS_GET_IID(nsIMsgAccount), (void **)ppAccount);
      }
    }
  }
  else if (NS_SUCCEEDED(rv) && in) {
    // for the existing server...
    nsCOMPtr<nsIMsgAccount> account;
    rv = aMgr->FindAccountForServer(in, getter_AddRefs(account));
    if (NS_SUCCEEDED(rv) && account) {
      IMPORT_LOG0("Using existing account and set the NNTP server as the incoming server\n");
      // Fiddle with the identities
      SetIdentities(aMgr, account, aKey, userName, 0, true);
      if (ppAccount)
        account->QueryInterface(NS_GET_IID(nsIMsgAccount),
                                 (void **)ppAccount);
      return true;
    }
  }
  else
    result = true;

  return result;
}
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;
}
Пример #18
0
NS_IMETHODIMP
nsCommandLine::ResolveFile(const nsAString& aArgument, nsIFile* *aResult)
{
  NS_ENSURE_TRUE(mWorkingDir, NS_ERROR_NOT_INITIALIZED);

  // This is some seriously screwed-up code. nsIFile.appendRelativeNativePath
  // explicitly does not accept .. or . path parts, but that is exactly what we
  // need here. So we hack around it.

  nsresult rv;

#if defined(MOZ_WIDGET_COCOA)
  nsCOMPtr<nsILocalFileMac> lfm (do_QueryInterface(mWorkingDir));
  NS_ENSURE_TRUE(lfm, NS_ERROR_NO_INTERFACE);

  nsCOMPtr<nsILocalFileMac> newfile (do_CreateInstance(NS_LOCAL_FILE_CONTRACTID));
  NS_ENSURE_TRUE(newfile, NS_ERROR_OUT_OF_MEMORY);

  CFURLRef baseurl;
  rv = lfm->GetCFURL(&baseurl);
  NS_ENSURE_SUCCESS(rv, rv);

  nsAutoCString path;
  NS_CopyUnicodeToNative(aArgument, path);

  CFURLRef newurl =
    CFURLCreateFromFileSystemRepresentationRelativeToBase(nullptr, (const UInt8*) path.get(),
                                                          path.Length(),
                                                          true, baseurl);

  CFRelease(baseurl);

  rv = newfile->InitWithCFURL(newurl);
  CFRelease(newurl);
  if (NS_FAILED(rv)) return rv;

  newfile.forget(aResult);
  return NS_OK;

#elif defined(XP_UNIX)
  nsCOMPtr<nsIFile> lf (do_CreateInstance(NS_LOCAL_FILE_CONTRACTID));
  NS_ENSURE_TRUE(lf, NS_ERROR_OUT_OF_MEMORY);

  if (aArgument.First() == '/') {
    // absolute path
    rv = lf->InitWithPath(aArgument);
    if (NS_FAILED(rv)) return rv;

    NS_ADDREF(*aResult = lf);
    return NS_OK;
  }

  nsAutoCString nativeArg;
  NS_CopyUnicodeToNative(aArgument, nativeArg);

  nsAutoCString newpath;
  mWorkingDir->GetNativePath(newpath);

  newpath.Append('/');
  newpath.Append(nativeArg);

  rv = lf->InitWithNativePath(newpath);
  if (NS_FAILED(rv)) return rv;

  rv = lf->Normalize();
  if (NS_FAILED(rv)) return rv;

  lf.forget(aResult);
  return NS_OK;

#elif defined(XP_WIN32)
  nsCOMPtr<nsIFile> lf (do_CreateInstance(NS_LOCAL_FILE_CONTRACTID));
  NS_ENSURE_TRUE(lf, NS_ERROR_OUT_OF_MEMORY);

  rv = lf->InitWithPath(aArgument);
  if (NS_FAILED(rv)) {
    // If it's a relative path, the Init is *going* to fail. We use string magic and
    // win32 _fullpath. Note that paths of the form "\Relative\To\CurDrive" are
    // going to fail, and I haven't figured out a way to work around this without
    // the PathCombine() function, which is not available in plain win95/nt4

    nsAutoString fullPath;
    mWorkingDir->GetPath(fullPath);

    fullPath.Append('\\');
    fullPath.Append(aArgument);

    WCHAR pathBuf[MAX_PATH];
    if (!_wfullpath(pathBuf, fullPath.get(), MAX_PATH))
      return NS_ERROR_FAILURE;

    rv = lf->InitWithPath(nsDependentString(pathBuf));
    if (NS_FAILED(rv)) return rv;
  }
  lf.forget(aResult);
  return NS_OK;

#else
#error Need platform-specific logic here.
#endif
}
Пример #19
0
void
WriteConsoleLog()
{
  nsresult rv;

  nsCOMPtr<nsILocalFile> lfile;

  char* logFileEnv = PR_GetEnv("XRE_CONSOLE_LOG");
  if (logFileEnv && *logFileEnv) {
    rv = XRE_GetFileFromPath(logFileEnv, getter_AddRefs(lfile));
    if (NS_FAILED(rv))
      return;
  }
  else {
    if (!gLogConsoleErrors)
      return;

    rv = gDirServiceProvider->GetUserAppDataDirectory(getter_AddRefs(lfile));
    if (NS_FAILED(rv))
      return;

    lfile->AppendNative(NS_LITERAL_CSTRING("console.log"));
  }

  PRFileDesc *file;
  rv = lfile->OpenNSPRFileDesc(PR_WRONLY | PR_APPEND | PR_CREATE_FILE,
                               0660, &file);
  if (NS_FAILED(rv))
    return;

  nsCOMPtr<nsIConsoleService> csrv
    (do_GetService(NS_CONSOLESERVICE_CONTRACTID));
  if (!csrv) {
    PR_Close(file);
    return;
  }

  nsIConsoleMessage** messages;
  PRUint32 mcount;

  rv = csrv->GetMessageArray(&messages, &mcount);
  if (NS_FAILED(rv)) {
    PR_Close(file);
    return;
  }

  if (mcount) {
    PRExplodedTime etime;
    PR_ExplodeTime(PR_Now(), PR_LocalTimeParameters, &etime);
    char datetime[512];
    PR_FormatTimeUSEnglish(datetime, sizeof(datetime),
                           "%Y-%m-%d %H:%M:%S", &etime);

    PR_fprintf(file, NS_LINEBREAK
                     "*** Console log: %s ***" NS_LINEBREAK,
               datetime);
  }

  // From this point on, we have to release all the messages, and free
  // the memory allocated for the messages array. XPCOM arrays suck.

  nsXPIDLString msg;
  nsCAutoString nativemsg;

  for (PRUint32 i = 0; i < mcount; ++i) {
    rv = messages[i]->GetMessage(getter_Copies(msg));
    if (NS_SUCCEEDED(rv)) {
      NS_CopyUnicodeToNative(msg, nativemsg);
      PR_fprintf(file, "%s" NS_LINEBREAK, nativemsg.get());
    }
    NS_IF_RELEASE(messages[i]);
  }

  PR_Close(file);
  NS_Free(messages);
}
void OESettings::SetSmtpServer(const nsString &aSmtpServer,
                               nsIWindowsRegKey *aKey,
                               nsIMsgIdentity *aId,
                               const nsString &aIncomgUserName,
                               int32_t authMethodIncoming)
{
  // set the id.smtpserver accordingly
  // first we have to calculate the smtp user name which is based on sicily
  if (!aKey || !aId || aIncomgUserName.IsEmpty() || aSmtpServer.IsEmpty())
    return;
  nsCString smtpServerKey;
  // smtp user name depends on sicily which may or not exist
  uint32_t useSicily = 0;
  nsresult rv = aKey->ReadIntValue(NS_LITERAL_STRING("SMTP Use Sicily"),
                                   &useSicily);
  nsAutoString userName;
  switch (useSicily) {
    case 1:
    case 3:
      // has to go in whether empty or no
      // shouldn't be empty but better safe than sorry
      aKey->ReadStringValue(NS_LITERAL_STRING("SMTP User Name"), userName);
      break;
    case 2:
      userName = aIncomgUserName;
      break;
    default:
      break; // initial userName == ""
  }

  nsCOMPtr<nsISmtpService> smtpService(do_GetService(NS_SMTPSERVICE_CONTRACTID, &rv));
  if (NS_SUCCEEDED(rv) && smtpService) {
    nsCOMPtr<nsISmtpServer> foundServer;
    // don't try to make another server
    // regardless if username doesn't match
    nsAutoCString nativeUserName;
    NS_CopyUnicodeToNative(userName, nativeUserName);
    nsAutoCString nativeSmtpServer;
    NS_CopyUnicodeToNative(aSmtpServer, nativeSmtpServer);
    rv = smtpService->FindServer(nativeUserName.get(),
                                 nativeSmtpServer.get(),
                                 getter_AddRefs(foundServer));
    if (NS_SUCCEEDED(rv) && foundServer) {
      // set our account keyed to this smptserver key
      foundServer->GetKey(getter_Copies(smtpServerKey));
      aId->SetSmtpServerKey(smtpServerKey);

      IMPORT_LOG1("SMTP server already exists: %s\n",
                  nativeSmtpServer.get());
    }
    else {
      nsCOMPtr<nsISmtpServer> smtpServer;
      rv = smtpService->CreateServer(getter_AddRefs(smtpServer));
      if (NS_SUCCEEDED(rv) && smtpServer) {
        uint32_t port = 0;
        rv = aKey->ReadIntValue(NS_LITERAL_STRING("SMTP Port"),
                                &port);
        if (NS_SUCCEEDED(rv) && port)
          smtpServer->SetPort(static_cast<int32_t>(port));

        int32_t socketType = nsMsgSocketType::plain;
        uint32_t secureConnection = 0;
        rv = aKey->ReadIntValue(NS_LITERAL_STRING("SMTP Secure Connection"),
                                &secureConnection);
        if (NS_SUCCEEDED(rv) && secureConnection == 1) {
          // Outlook Express does not support STARTTLS without KB933612 fix.
          if (IsKB933612Applied() && port != 465)
            socketType = nsMsgSocketType::alwaysSTARTTLS;
          else
            socketType = nsMsgSocketType::SSL;
        }
        smtpServer->SetSocketType(socketType);
        smtpServer->SetUsername(nativeUserName);
        switch (useSicily) {
          case 1 :
            smtpServer->SetAuthMethod(nsMsgAuthMethod::secure);
            break;
          case 2 : // requires SMTP authentication to use the incoming server settings
            smtpServer->SetAuthMethod(authMethodIncoming);
            break;
          case 3 :
            smtpServer->SetAuthMethod(nsMsgAuthMethod::passwordCleartext);
            break;
          default:
            smtpServer->SetAuthMethod(nsMsgAuthMethod::none);
        }

        smtpServer->SetHostname(nativeSmtpServer);

        smtpServer->GetKey(getter_Copies(smtpServerKey));
        aId->SetSmtpServerKey(smtpServerKey);

        IMPORT_LOG1("Created new SMTP server: %s\n",
                    nativeSmtpServer.get());
      }
    }
  }
}
void OESettings::SetIdentities(nsIMsgAccountManager *aMgr,
                               nsIMsgAccount *pAcc,
                               nsIWindowsRegKey *aKey,
                               const nsString &aIncomgUserName,
                               int32_t authMethodIncoming,
                               bool isNNTP)
{
  // Get the relevant information for an identity
  nsresult rv;
  nsAutoString name;
  rv = aKey->ReadStringValue(isNNTP ?
                             NS_LITERAL_STRING("NNTP Display Name") :
                             NS_LITERAL_STRING("SMTP Display Name"),
                             name);
  nsAutoString email;
  rv = aKey->ReadStringValue(isNNTP ?
                             NS_LITERAL_STRING("NNTP Email Address") :
                             NS_LITERAL_STRING("SMTP Email Address"),
                             email);
  nsAutoString reply;
  rv = aKey->ReadStringValue(isNNTP ?
                             NS_LITERAL_STRING("NNTP Reply To Email Address") :
                             NS_LITERAL_STRING("SMTP Reply To Email Address"),
                             reply);
  nsAutoString orgName;
  rv = aKey->ReadStringValue(isNNTP ?
                             NS_LITERAL_STRING("NNTP Organization Name") :
                             NS_LITERAL_STRING("SMTP Organization Name"),
                             orgName);

  nsCOMPtr<nsIMsgIdentity> id;
  rv = aMgr->CreateIdentity(getter_AddRefs(id));
  if (NS_FAILED(rv))
    return;

  id->SetFullName(name);
  //BUG 470587. Don't set this: id->SetIdentityName(fullName);

  id->SetOrganization(orgName);

  nsAutoCString nativeEmail;
  NS_CopyUnicodeToNative(email, nativeEmail);
  id->SetEmail(nativeEmail);
  if (!reply.IsEmpty()) {
    nsAutoCString nativeReply;
    NS_CopyUnicodeToNative(reply, nativeReply);
    id->SetReplyTo(nativeReply);
  }

  // Outlook Express users are used to top style quoting.
  id->SetReplyOnTop(isNNTP ? 0 : 1);
  pAcc->AddIdentity(id);

  nsAutoCString nativeName;
  NS_CopyUnicodeToNative(name, nativeName);
  IMPORT_LOG0("Created identity and added to the account\n");
  IMPORT_LOG1("\tname: %s\n", nativeName.get());
  IMPORT_LOG1("\temail: %s\n", nativeEmail.get());

  if (isNNTP)  // NNTP does not use SMTP in OE or TB
    return;
  nsAutoString smtpServer;
  rv = aKey->ReadStringValue(NS_LITERAL_STRING("SMTP Server"), smtpServer);
  SetSmtpServer(smtpServer, aKey, id, aIncomgUserName, authMethodIncoming);
}