Andreas Krennmair:
[apps/madmutt.git] / imap / auth_anon.c
1 /*
2  * Copyright (C) 1999-2000 Brendan Cully <brendan@kublai.com>
3  * 
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.
8  * 
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.
13  * 
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., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
17  */
18
19 /* IMAP login/authentication code */
20
21 #if HAVE_CONFIG_H
22 # include "config.h"
23 #endif
24
25 #include "mutt.h"
26 #include "imap_private.h"
27 #include "auth.h"
28
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)
31 {
32   int rc;
33
34   if (!mutt_bit_isset (idata->capabilities, AUTH_ANON))
35     return IMAP_AUTH_UNAVAIL;
36
37   if (mutt_account_getuser (&idata->conn->account))
38     return IMAP_AUTH_FAILURE;
39
40   if (idata->conn->account.user[0] != '\0')
41     return IMAP_AUTH_UNAVAIL;
42
43   mutt_message _("Authenticating (anonymous)...");
44
45   imap_cmd_start (idata, "AUTHENTICATE ANONYMOUS");
46
47   do
48     rc = imap_cmd_step (idata);
49   while (rc == IMAP_CMD_CONTINUE);
50
51   if (rc != IMAP_CMD_RESPOND) {
52     dprint (1, (debugfile, "Invalid response from server.\n"));
53     goto bail;
54   }
55
56   mutt_socket_write (idata->conn, "ZHVtbXkK\r\n");      /* base64 ("dummy") */
57
58   do
59     rc = imap_cmd_step (idata);
60   while (rc == IMAP_CMD_CONTINUE);
61
62   if (rc != IMAP_CMD_OK) {
63     dprint (1, (debugfile, "Error receiving server response.\n"));
64     goto bail;
65   }
66
67   if (imap_code (idata->cmd.buf))
68     return IMAP_AUTH_SUCCESS;
69
70 bail:
71   mutt_error _("Anonymous authentication failed.");
72   mutt_sleep (2);
73   return IMAP_AUTH_FAILURE;
74 }