Beispiel #1
0
static int smtp_open (CONNECTION* conn)
{
        int rc;

        if (mutt_socket_open (conn))
                return -1;

/* get greeting string */
        if ((rc = smtp_get_resp (conn)))
                return rc;

        if ((rc = smtp_helo (conn)))
                return rc;

#ifdef USE_SSL
        if (conn->ssf)
                rc = M_NO;
        else if (option (OPTSSLFORCETLS))
                rc = M_YES;
        else if (mutt_bit_isset (Capabilities, STARTTLS) &&
                (rc = query_quadoption (OPT_SSLSTARTTLS,
                _("Secure connection with TLS?"))) == -1)
                return rc;

        if (rc == M_YES) {
                if (mutt_socket_write (conn, "STARTTLS\r\n") < 0)
                        return smtp_err_write;
                if ((rc = smtp_get_resp (conn)))
                        return rc;

                if (mutt_ssl_starttls (conn)) {
                        mutt_error (_("Could not negotiate TLS connection"));
                        mutt_sleep (1);
                        return -1;
                }

/* re-EHLO to get authentication mechanisms */
                if ((rc = smtp_helo (conn)))
                        return rc;
        }
#endif

        if (conn->account.flags & M_ACCT_USER) {
                if (!mutt_bit_isset (Capabilities, AUTH)) {
                        mutt_error (_("SMTP server does not support authentication"));
                        mutt_sleep (1);
                        return -1;
                }

#ifdef USE_SASL
                return smtp_auth (conn);
#else
                mutt_error (_("SMTP authentication requires SASL"));
                mutt_sleep (1);
                return -1;
#endif                            /* USE_SASL */
        }

        return 0;
}
Beispiel #2
0
/*
 * Open connection and authenticate
 *  0 - successful,
 * -1 - conection lost,
 * -2 - invalid command or execution error,
 * -3 - authentication canceled.
*/
int pop_open_connection (POP_DATA *pop_data)
{
  int ret;
  unsigned int n, size;
  char buf[LONG_STRING];

  ret = pop_connect (pop_data);
  if (ret < 0)
  {
    mutt_sleep (2);
    return ret;
  }

  ret = pop_capabilities (pop_data, 0);
  if (ret == -1)
    goto err_conn;
  if (ret == -2)
  {
    mutt_sleep (2);
    return -2;
  }

#if defined(USE_SSL)
  /* Attempt STLS if available and desired. */
  if (!pop_data->conn->ssf && (pop_data->cmd_stls || option(OPTSSLFORCETLS)))
  {
    if (option(OPTSSLFORCETLS))
      pop_data->use_stls = 2;
    if (pop_data->use_stls == 0)
    {
      ret = query_quadoption (OPT_SSLSTARTTLS,
	    _("Secure connection with TLS?"));
      if (ret == -1)
	return -2;
      pop_data->use_stls = 1;
      if (ret == M_YES)
	pop_data->use_stls = 2;
    }
    if (pop_data->use_stls == 2)
    {
      strfcpy (buf, "STLS\r\n", sizeof (buf));
      ret = pop_query (pop_data, buf, sizeof (buf));
      if (ret == -1)
	goto err_conn;
      if (ret != 0)
      {
	mutt_error ("%s", pop_data->err_msg);
	mutt_sleep (2);
      }
      else if (mutt_ssl_starttls (pop_data->conn))
      {
	mutt_error (_("Could not negotiate TLS connection"));
	mutt_sleep (2);
	return -2;
      }
      else
      {
	/* recheck capabilities after STLS completes */
	ret = pop_capabilities (pop_data, 1);
	if (ret == -1)
	  goto err_conn;
	if (ret == -2)
	{
	  mutt_sleep (2);
	  return -2;
	}
      }
    }
  }

  if (option(OPTSSLFORCETLS) && !pop_data->conn->ssf)
  {
    mutt_error _("Encrypted connection unavailable");
    mutt_sleep (1);
    return -2;
  }
#endif

  ret = pop_authenticate (pop_data);
  if (ret == -1)
    goto err_conn;
  if (ret == -3)
    mutt_clear_error ();
  if (ret != 0)
    return ret;

  /* recheck capabilities after authentication */
  ret = pop_capabilities (pop_data, 2);
  if (ret == -1)
    goto err_conn;
  if (ret == -2)
  {
    mutt_sleep (2);
    return -2;
  }

  /* get total size of mailbox */
  strfcpy (buf, "STAT\r\n", sizeof (buf));
  ret = pop_query (pop_data, buf, sizeof (buf));
  if (ret == -1)
    goto err_conn;
  if (ret == -2)
  {
    mutt_error ("%s", pop_data->err_msg);
    mutt_sleep (2);
    return ret;
  }

  sscanf (buf, "+OK %u %u", &n, &size);
  pop_data->size = size;
  return 0;

err_conn:
  pop_data->status = POP_DISCONNECTED;
  mutt_error _("Server closed connection!");
  mutt_sleep (2);
  return -1;
}