2 * Copyright (C) 1999-2001,2005 Brendan Cully <brendan@kublai.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 /* IMAP login/authentication code */
26 #include "imap_private.h"
29 /* this is basically a stripped-down version of the cram-md5 method. */
30 imap_auth_res_t imap_auth_anon (IMAP_DATA* idata, const char* method)
34 if (!mutt_bit_isset (idata->capabilities, AUTH_ANON))
35 return IMAP_AUTH_UNAVAIL;
37 if (mutt_account_getuser (&idata->conn->account))
38 return IMAP_AUTH_FAILURE;
40 if (idata->conn->account.user[0] != '\0')
41 return IMAP_AUTH_UNAVAIL;
43 mutt_message _("Authenticating (anonymous)...");
45 imap_cmd_start (idata, "AUTHENTICATE ANONYMOUS");
48 rc = imap_cmd_step (idata);
49 while (rc == IMAP_CMD_CONTINUE);
51 if (rc != IMAP_CMD_RESPOND)
53 dprint (1, (debugfile, "Invalid response from server.\n"));
57 mutt_socket_write (idata->conn, "ZHVtbXkK\r\n"); /* base64 ("dummy") */
60 rc = imap_cmd_step (idata);
61 while (rc == IMAP_CMD_CONTINUE);
63 if (rc != IMAP_CMD_OK)
65 dprint (1, (debugfile, "Error receiving server response.\n"));
69 if (imap_code (idata->buf))
70 return IMAP_AUTH_SUCCESS;
73 mutt_error _("Anonymous authentication failed.");
75 return IMAP_AUTH_FAILURE;