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