finish the "read" of charset.c
[apps/madmutt.git] / imap / auth_login.c
1 /*
2  * Copyright notice from original mutt:
3  * Copyright (C) 1999-2001 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 /* plain LOGIN support */
11
12 #if HAVE_CONFIG_H
13 # include "config.h"
14 #endif
15
16 #include <lib-lib/macros.h>
17
18 #include "mutt.h"
19 #include "imap_private.h"
20 #include "auth.h"
21
22 /* imap_auth_login: Plain LOGIN support */
23 imap_auth_res_t imap_auth_login(IMAP_DATA *idata, const char *method __attribute__ ((unused)))
24 {
25     char q_user[SHORT_STRING], q_pass[SHORT_STRING];
26     char buf[STRING];
27     int rc;
28
29     if (mutt_bit_isset (idata->capabilities, LOGINDISABLED)) {
30         mutt_message _("LOGIN disabled on this server.");
31
32         return IMAP_AUTH_UNAVAIL;
33     }
34
35     if (mutt_account_getlogin (&idata->conn->account))
36         return IMAP_AUTH_FAILURE;
37     if (mutt_account_getpass (&idata->conn->account))
38         return IMAP_AUTH_FAILURE;
39
40     mutt_message _("Logging in...");
41
42     imap_quote_string(q_user, sizeof(q_user), idata->conn->account.login);
43     imap_quote_string(q_pass, sizeof(q_pass), idata->conn->account.pass);
44
45     snprintf(buf, sizeof(buf), "LOGIN %s %s", q_user, q_pass);
46     rc = imap_exec(idata, buf, IMAP_CMD_FAIL_OK | IMAP_CMD_PASS);
47
48     if (!rc)
49         return IMAP_AUTH_SUCCESS;
50
51     mutt_error _("Login failed.");
52
53     mutt_sleep (2);
54     return IMAP_AUTH_FAILURE;
55 }