Use good m_ functions, because it smell like a flower, version 2.
[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 #include <lib-lib/lib-lib.h>
13
14 #include "mutt.h"
15 #include "imap_private.h"
16 #include "auth.h"
17
18 /* imap_auth_login: Plain LOGIN support */
19 imap_auth_res_t imap_auth_login(IMAP_DATA *idata, const char *method __attribute__ ((unused)))
20 {
21     char q_user[SHORT_STRING], q_pass[SHORT_STRING];
22     char buf[STRING];
23     int rc;
24
25     if (mutt_bit_isset (idata->capabilities, LOGINDISABLED)) {
26         mutt_message _("LOGIN disabled on this server.");
27
28         return IMAP_AUTH_UNAVAIL;
29     }
30
31     if (mutt_account_getlogin (&idata->conn->account))
32         return IMAP_AUTH_FAILURE;
33     if (mutt_account_getpass (&idata->conn->account))
34         return IMAP_AUTH_FAILURE;
35
36     mutt_message _("Logging in...");
37
38     imap_quote_string(q_user, sizeof(q_user), idata->conn->account.login);
39     imap_quote_string(q_pass, sizeof(q_pass), idata->conn->account.pass);
40
41     snprintf(buf, sizeof(buf), "LOGIN %s %s", q_user, q_pass);
42     rc = imap_exec(idata, buf, IMAP_CMD_FAIL_OK | IMAP_CMD_PASS);
43
44     if (!rc)
45         return IMAP_AUTH_SUCCESS;
46
47     mutt_error _("Login failed.");
48
49     mutt_sleep (2);
50     return IMAP_AUTH_FAILURE;
51 }