move url.[hc] into the lib-lib.
[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 #include <lib-lib/debug.h>
22
23 /* this is basically a stripped-down version of the cram-md5 method. */
24 imap_auth_res_t imap_auth_anon (IMAP_DATA * idata, const char *method)
25 {
26   int rc;
27
28   if (!mutt_bit_isset (idata->capabilities, AUTH_ANON))
29     return IMAP_AUTH_UNAVAIL;
30
31   if (mutt_account_getuser (&idata->conn->account))
32     return IMAP_AUTH_FAILURE;
33
34   if (idata->conn->account.user[0] != '\0')
35     return IMAP_AUTH_UNAVAIL;
36
37   mutt_message _("Authenticating (anonymous)...");
38
39   imap_cmd_start (idata, "AUTHENTICATE ANONYMOUS");
40
41   do
42     rc = imap_cmd_step (idata);
43   while (rc == IMAP_CMD_CONTINUE);
44
45   if (rc != IMAP_CMD_RESPOND) {
46     debug_print (1, ("Invalid response from server.\n"));
47     goto bail;
48   }
49
50   mutt_socket_write (idata->conn, "ZHVtbXkK\r\n");      /* base64 ("dummy") */
51
52   do
53     rc = imap_cmd_step (idata);
54   while (rc == IMAP_CMD_CONTINUE);
55
56   if (rc != IMAP_CMD_OK) {
57     debug_print (1, ("Error receiving server response.\n"));
58     goto bail;
59   }
60
61   if (imap_code (idata->cmd.buf))
62     return IMAP_AUTH_SUCCESS;
63
64 bail:
65   mutt_error _("Anonymous authentication failed.");
66   mutt_sleep (2);
67   return IMAP_AUTH_FAILURE;
68 }