コード例 #1
0
void nsEudoraWin32::SetSmtpServer( nsIMsgAccountManager *pMgr, nsIMsgAccount *pAcc, const char *pServer, const char *pUser)
{
  nsresult  rv;

  nsCOMPtr<nsISmtpService> smtpService(do_GetService(NS_SMTPSERVICE_CONTRACTID, &rv));
  if (NS_SUCCEEDED(rv) && smtpService)
  {
    nsCOMPtr<nsISmtpServer>    foundServer;

    rv = smtpService->FindServer( pUser, pServer, getter_AddRefs( foundServer));
    if (NS_SUCCEEDED( rv) && foundServer)
    {
      IMPORT_LOG1( "SMTP server already exists: %s\n", pServer);
      return;
    }
    nsCOMPtr<nsISmtpServer>    smtpServer;

    rv = smtpService->CreateSmtpServer( getter_AddRefs( smtpServer));
    if (NS_SUCCEEDED( rv) && smtpServer)
    {
      smtpServer->SetHostname( pServer);
      if (pUser)
        smtpServer->SetUsername( pUser);

      IMPORT_LOG1( "Created new SMTP server: %s\n", pServer);
    }
  }
}
コード例 #2
0
NS_IMETHODIMP
nsSmtpServer::VerifyLogon(nsIUrlListener *aUrlListener, nsIMsgWindow *aMsgWindow,
                          nsIURI **aURL)
{
  nsresult rv;
  nsCOMPtr<nsISmtpService> smtpService(do_GetService(NS_SMTPSERVICE_CONTRACTID, &rv));
  NS_ENSURE_SUCCESS(rv, rv);
  return smtpService->VerifyLogon(this, aUrlListener, aMsgWindow, aURL);
}
コード例 #3
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;
}
コード例 #4
0
void OutlookSettings::SetSmtpServer(nsIMsgAccountManager *pMgr, nsIMsgAccount *pAcc, char *pServer,
                                    const nsCString& user)
{
  nsresult rv;
  nsCOMPtr<nsISmtpService> smtpService(do_GetService(NS_SMTPSERVICE_CONTRACTID, &rv));
  if (NS_SUCCEEDED(rv) && smtpService) {
    nsCOMPtr<nsISmtpServer> foundServer;
    rv = smtpService->FindServer(user.get(), pServer, getter_AddRefs(foundServer));
    if (NS_SUCCEEDED(rv) && foundServer) {
      IMPORT_LOG1("SMTP server already exists: %s\n", pServer);
      return;
    }
    nsCOMPtr<nsISmtpServer> smtpServer;
    rv = smtpService->CreateSmtpServer(getter_AddRefs(smtpServer));
    if (NS_SUCCEEDED(rv) && smtpServer) {
      smtpServer->SetHostname(nsDependentCString(pServer));
      if (!user.IsEmpty())
        smtpServer->SetUsername(user);
      // TODO SSL, auth method
      IMPORT_LOG1("Ceated new SMTP server: %s\n", pServer);
    }
  }
}
コード例 #5
0
void OESettings::SetSmtpServer(char *pSmtpServer, HKEY hKey,
                               nsIMsgIdentity *id, char *pIncomgUserName,
                               PRInt32 authMethodIncoming)
{
  // set the id.smtpserver accordingly
  // first we have to calculate the smtp user name which is based on sicily
  if (!hKey || !id || !pIncomgUserName || !pSmtpServer)
    return;
  nsCString smtpServerKey, userName;
  BYTE *pBytes;
  // smtp user name depends on sicily which may or not exist
  PRInt32 useSicily = 0;
  if (pBytes = nsOERegUtil::GetValueBytes(hKey, "SMTP Use Sicily")){
    useSicily = *(PRInt32 *)pBytes;
    nsOERegUtil::FreeValueBytes(pBytes);
  }
  switch (useSicily) {
    case 1 : case 3 :
      // has to go in whether empty or no
      // shouldn't be empty but better safe than sorry
      if (pBytes = nsOERegUtil::GetValueBytes(hKey, "SMTP User Name")){
        userName = (char *)pBytes;  // this may be empty; shouldn't be non-existent
        nsOERegUtil::FreeValueBytes(pBytes);
      }
      break;
    case 2 :
      userName = pIncomgUserName;
      break;
    default :
      break; // initial userName == ""
  }

  nsresult rv;
  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
    rv = smtpService->FindServer(userName.get(), pSmtpServer,
                                 getter_AddRefs(foundServer));
    if (NS_SUCCEEDED(rv) && foundServer) {
      // set our account keyed to this smptserver key
      foundServer->GetKey(getter_Copies(smtpServerKey));
      id->SetSmtpServerKey(smtpServerKey);

      IMPORT_LOG1("SMTP server already exists: %s\n", pSmtpServer);
    }
    else {
      nsCOMPtr<nsISmtpServer> smtpServer;
      PRInt32 port;
      rv = smtpService->CreateSmtpServer(getter_AddRefs(smtpServer));
      if (NS_SUCCEEDED(rv) && smtpServer) {
        pBytes = nsOERegUtil::GetValueBytes(hKey, "SMTP Port");
        if (pBytes)
        {
          smtpServer->SetPort(*(PRInt32 *) pBytes);
          port = *(PRInt32 *) pBytes;
          nsOERegUtil::FreeValueBytes(pBytes);
        }
        pBytes = nsOERegUtil::GetValueBytes(hKey,"SMTP Secure Connection");
        if (pBytes)
        {
          if (*(PRInt32 *)pBytes == 1) {
            // Outlook Express does not support STARTTLS without KB933612 fix.
            if (IsKB933612Applied() && port != 465)
              smtpServer->SetSocketType(nsMsgSocketType::alwaysSTARTTLS);
            else
              smtpServer->SetSocketType(nsMsgSocketType::SSL);
          } else {
            smtpServer->SetSocketType(nsMsgSocketType::plain);
          }
          nsOERegUtil::FreeValueBytes(pBytes);
        }
        smtpServer->SetUsername(userName);
        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(nsDependentCString(pSmtpServer));

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

        IMPORT_LOG1("Created new SMTP server: %s\n", pSmtpServer);
      }
    }
  }
}
コード例 #6
0
NS_IMETHODIMP nsMsgMdnGenerator::OnStopRunningUrl(nsIURI *url,
                                                  nsresult aExitCode)
{
    nsresult rv;

    DEBUG_MDN("nsMsgMdnGenerator::OnStopRunningUrl");
    if (m_file)
      m_file->Remove(PR_FALSE);

    if (NS_SUCCEEDED(aExitCode))
      return NS_OK;

    switch (aExitCode)
    {    
      case NS_ERROR_UNKNOWN_HOST:
      case NS_ERROR_UNKNOWN_PROXY_HOST:
        aExitCode = NS_ERROR_SMTP_SEND_FAILED_UNKNOWN_SERVER;
        break;
      case NS_ERROR_CONNECTION_REFUSED:
      case NS_ERROR_PROXY_CONNECTION_REFUSED: 
        aExitCode = NS_ERROR_SMTP_SEND_FAILED_REFUSED;
        break;
      case NS_ERROR_NET_INTERRUPT:
        aExitCode = NS_ERROR_SMTP_SEND_FAILED_INTERRUPTED;
        break; 
      case NS_ERROR_NET_TIMEOUT:
      case NS_ERROR_NET_RESET:
        aExitCode = NS_ERROR_SMTP_SEND_FAILED_TIMEOUT;
        break;
      case NS_ERROR_SMTP_PASSWORD_UNDEFINED:
        // nothing to do, just keep the code
        break;
      default:
        if (aExitCode != NS_ERROR_ABORT && !NS_IS_MSG_ERROR(aExitCode))
          aExitCode = NS_ERROR_SMTP_SEND_FAILED_UNKNOWN_REASON;
      break;
    }    

    nsCOMPtr<nsISmtpService> smtpService(do_GetService(NS_SMTPSERVICE_CONTRACTID, &rv));
    NS_ENSURE_SUCCESS(rv,rv);

    // Get the smtp hostname and format the string.
    nsCString smtpHostName;
    nsCOMPtr<nsISmtpServer> smtpServer;
    rv = smtpService->GetSmtpServerByIdentity(m_identity, getter_AddRefs(smtpServer));
    if (NS_SUCCEEDED(rv)) 
      smtpServer->GetHostname(smtpHostName);
     
    nsAutoString hostStr;
    CopyASCIItoUTF16(smtpHostName, hostStr);
    const PRUnichar *params[] = { hostStr.get() };

    nsCOMPtr<nsIStringBundle> bundle;
    nsCOMPtr<nsIStringBundleService> bundleService(do_GetService("@mozilla.org/intl/stringbundle;1", &rv));
    NS_ENSURE_SUCCESS(rv, rv);

    rv = bundleService->CreateBundle("chrome://messenger/locale/messengercompose/composeMsgs.properties", getter_AddRefs(bundle));
    NS_ENSURE_SUCCESS(rv, rv);

    nsString failed_msg, dialogTitle;

    bundle->FormatStringFromID(NS_ERROR_GET_CODE(aExitCode), params, 1, getter_Copies(failed_msg));
    bundle->GetStringFromID(NS_MSG_SEND_ERROR_TITLE, getter_Copies(dialogTitle));

    nsCOMPtr<nsIPrompt> dialog;
    rv = m_window->GetPromptDialog(getter_AddRefs(dialog));
    if (NS_SUCCEEDED(rv))
      dialog->Alert(dialogTitle.get(),failed_msg.get());

    return NS_OK;
}
コード例 #7
0
void WMSettings::SetSmtpServer(nsIDOMDocument *xmlDoc, nsIMsgIdentity *id,
                               nsAutoString& inUserName, PRInt32 authMethodIncoming)
{
  PRInt32 errorCode;

  // set the id.smtpserver accordingly
  if (!id)
    return;
  nsCString smtpServerKey, userName;
  nsAutoString value, smtpName;
  if (NS_FAILED(GetValueForTag(xmlDoc, NS_LITERAL_STRING("SMTP_Server"), smtpName)))
    return;

  // first we have to calculate the smtp user name which is based on sicily
  // smtp user name depends on sicily which may or not exist
  PRInt32 useSicily = 0;
  GetValueForTag(xmlDoc, NS_LITERAL_STRING("SMTP_Use_Sicily"), value);
  useSicily = (PRInt32)value.ToInteger(&errorCode,16);

  switch (useSicily) {
    case 1 : case 3 :
      GetValueForTag(xmlDoc, NS_LITERAL_STRING("SMTP_User_Name"), value);
      CopyUTF16toUTF8(value, userName);
      break;
    case 2 :
      CopyUTF16toUTF8(inUserName, userName);
      break;
    default :
      break; // initial userName == ""
  }

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

      IMPORT_LOG1("SMTP server already exists: %S\n", smtpName);
    }
    else {
      nsCOMPtr<nsISmtpServer> smtpServer;
      rv = smtpService->CreateSmtpServer(getter_AddRefs(smtpServer));
      if (NS_SUCCEEDED(rv) && smtpServer) {
        GetValueForTag(xmlDoc, NS_LITERAL_STRING("SMTP_Port"), value);
        if (!value.IsEmpty()) {
          smtpServer->SetPort(value.ToInteger(&errorCode,16));
        }

        GetValueForTag(xmlDoc, NS_LITERAL_STRING("SMTP_Secure_Connection"),
                       value);
        if (!value.IsEmpty()) {
          if (value.ToInteger(&errorCode, 16) == 1)
            smtpServer->SetSocketType(nsMsgSocketType::SSL);
          else
            smtpServer->SetSocketType(nsMsgSocketType::plain);
        }
        smtpServer->SetUsername(userName);
        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(NS_ConvertUTF16toUTF8(smtpName));

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

        IMPORT_LOG1("Created new SMTP server: %S\n", smtpName);
      }
    }
  }
}
コード例 #8
0
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());
      }
    }
  }
}