remove most of the debug code: often makes the code unreadable, for little
[apps/madmutt.git] / imap / auth_anon.c
1 /*
2  * Copyright notice from original mutt:
3  * Copyright (C) 1999-2000 Brendan Cully <brendan@kublai.com>
4  *
5  * This file is part of mutt-ng, see http://www.muttng.org/.
6  * It's licensed under the GNU General Public License,
7  * please see the file GPL in the top level source directory.
8  */
9
10 /* IMAP login/authentication code */
11
12 #if HAVE_CONFIG_H
13 # include "config.h"
14 #endif
15
16 #include "mutt.h"
17 #include "imap_private.h"
18 #include "auth.h"
19
20 #include <lib-lib/macros.h>
21
22 /* this is basically a stripped-down version of the cram-md5 method. */
23 imap_auth_res_t imap_auth_anon (IMAP_DATA * idata, const char *method __attribute__ ((unused)))
24 {
25   int rc;
26
27   if (!mutt_bit_isset (idata->capabilities, AUTH_ANON))
28     return IMAP_AUTH_UNAVAIL;
29
30   if (mutt_account_getuser (&idata->conn->account))
31     return IMAP_AUTH_FAILURE;
32
33   if (idata->conn->account.user[0] != '\0')
34     return IMAP_AUTH_UNAVAIL;
35
36   mutt_message _("Authenticating (anonymous)...");
37
38   imap_cmd_start (idata, "AUTHENTICATE ANONYMOUS");
39
40   do
41     rc = imap_cmd_step (idata);
42   while (rc == IMAP_CMD_CONTINUE);
43
44   if (rc != IMAP_CMD_RESPOND) {
45     goto bail;
46   }
47
48   mutt_socket_write (idata->conn, "ZHVtbXkK\r\n");      /* base64 ("dummy") */
49
50   do
51     rc = imap_cmd_step (idata);
52   while (rc == IMAP_CMD_CONTINUE);
53
54   if (rc != IMAP_CMD_OK) {
55     goto bail;
56   }
57
58   if (imap_code (idata->cmd.buf))
59     return IMAP_AUTH_SUCCESS;
60
61 bail:
62   mutt_error _("Anonymous authentication failed.");
63   mutt_sleep (2);
64   return IMAP_AUTH_FAILURE;
65 }