/*
- * Copyright (C) 2000 Brendan Cully <brendan@kublai.com>
+ * Copyright (C) 2000-3 Brendan Cully <brendan@kublai.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
void mutt_account_tourl (ACCOUNT* account, ciss_url_t* url);
int mutt_account_getuser (ACCOUNT* account);
int mutt_account_getpass (ACCOUNT* account);
+void mutt_account_unsetpass (ACCOUNT* account);
#endif /* _MUTT_ACCOUNT_H_ */
/*
- * Copyright (C) 2000-2 Brendan Cully <brendan@kublai.com>
+ * Copyright (C) 2000-3 Brendan Cully <brendan@kublai.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
return IMAP_AUTH_UNAVAIL;
}
- mutt_message _("Authenticating (SASL)...");
+ mutt_message (_("Authenticating (%s)..."), mech);
snprintf (buf, sizeof (buf), "AUTHENTICATE %s", mech);
imap_cmd_start (idata, buf);
client_start = 0;
/* send out response, or line break if none needed */
- if (pc)
+ if (olen)
{
if (sasl_encode64 (pc, olen, buf, sizeof (buf), &olen) != SASL_OK)
{
#endif
}
- if (olen || rc == SASL_CONTINUE)
+ if (irc == IMAP_CMD_RESPOND)
{
strfcpy (buf + olen, "\r\n", sizeof (buf) - olen);
mutt_socket_write (idata->conn, buf);
/* don't open a new connection if one isn't wanted */
if (flags & M_IMAP_CONN_NONEW)
- if (!idata || idata->state == IMAP_DISCONNECTED)
- goto err_conn;
+ {
+ if (!idata)
+ {
+ mutt_socket_free (conn);
+ return NULL;
+ }
+ if (idata->state < IMAP_AUTHENTICATED)
+ return NULL;
+ }
if (!idata)
{
/* The current connection is a new connection */
if (! (idata = imap_new_idata ()))
- goto err_conn;
+ {
+ mutt_socket_free (conn);
+ return NULL;
+ }
conn->data = idata;
idata->conn = conn;
}
+
if (idata->state == IMAP_DISCONNECTED)
- if (imap_open_connection (idata) != 0)
- goto err_idata;
+ imap_open_connection (idata);
+ if (idata->state == IMAP_CONNECTED)
+ {
+ if (!imap_authenticate (idata))
+ {
+ idata->state = IMAP_AUTHENTICATED;
+ if (idata->conn->ssf)
+ dprint (2, (debugfile, "Communication encrypted at %d bits\n",
+ idata->conn->ssf));
+ imap_get_delim (idata);
+ }
+ else
+ mutt_account_unsetpass (&idata->conn->account);
+
+ FREE (&idata->capstr);
+ }
return idata;
-
- err_idata:
- imap_free_idata (&idata);
- err_conn:
- mutt_socket_free (conn);
-
- return NULL;
}
int imap_open_connection (IMAP_DATA* idata)
idata->state = IMAP_CONNECTED;
- if (imap_cmd_step (idata) != IMAP_CMD_CONTINUE)
- goto bail;
+ if (imap_cmd_step (idata) != IMAP_CMD_CONTINUE) {
+ mutt_error (_("Unexpected response received from server: %s"), idata->cmd.buf);
+ mutt_sleep (1);
+
+ mutt_socket_close (idata->conn);
+ idata->state = IMAP_DISCONNECTED;
+ return -1;
+ }
if (ascii_strncasecmp ("* OK", idata->cmd.buf, 4) == 0)
{
}
}
#endif
- if (imap_authenticate (idata))
- goto bail;
- if (idata->conn->ssf)
- dprint (2, (debugfile, "Communication encrypted at %d bits\n",
- idata->conn->ssf));
}
else if (ascii_strncasecmp ("* PREAUTH", idata->cmd.buf, 9) == 0)
{
+ idata->state = IMAP_AUTHENTICATED;
if (imap_check_capabilities (idata) != 0)
goto bail;
+ FREE (&idata->capstr);
}
else
{
goto bail;
}
- FREE (&idata->capstr);
- idata->state = IMAP_AUTHENTICATED;
-
- imap_get_delim (idata);
return 0;
err_close_conn:
mutt_socket_close (idata->conn);
bail:
FREE (&idata->capstr);
- idata->state = IMAP_DISCONNECTED;
return -1;
}
/* we require a connection which isn't currently in IMAP_SELECTED state */
if (!(idata = imap_conn_find (&(mx.account), M_IMAP_CONN_NOSELECT)))
goto fail_noidata;
+ if (idata->state < IMAP_AUTHENTICATED)
+ goto fail;
+
conn = idata->conn;
/* once again the context is new */