Esempio n. 1
0
/*
 * Open connection
 *  0 - successful,
 * -1 - conection lost,
 * -2 - invalid response.
*/
int pop_connect (POP_DATA *pop_data)
{
  char buf[LONG_STRING];

  pop_data->status = POP_NONE;
  if (mutt_socket_open (pop_data->conn) < 0 ||
      mutt_socket_readln (buf, sizeof (buf), pop_data->conn) < 0)
  {
    mutt_error (_("Error connecting to server: %s"), pop_data->conn->account.host);
    return -1;
  }

  pop_data->status = POP_CONNECTED;

  if (mutt_strncmp (buf, "+OK", 3))
  {
    *pop_data->err_msg = '\0';
    pop_error (pop_data, buf);
    mutt_error ("%s", pop_data->err_msg);
    return -2;
  }

  pop_apop_timestamp (pop_data, buf);

  return 0;
}
Esempio n. 2
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;
}