Rocco Rutte:
[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/intl.h"
17 #include "lib/debug.h"
18
19 #include "mutt.h"
20 #include "imap_private.h"
21 #include "auth.h"
22
23 /* imap_auth_login: Plain LOGIN support */
24 imap_auth_res_t imap_auth_login (IMAP_DATA * idata, const char *method)
25 {
26   char q_user[SHORT_STRING], q_pass[SHORT_STRING];
27   char buf[STRING];
28   int rc;
29
30   if (mutt_bit_isset (idata->capabilities, LOGINDISABLED)) {
31     mutt_message _("LOGIN disabled on this server.");
32
33     return IMAP_AUTH_UNAVAIL;
34   }
35
36   if (mutt_account_getlogin (&idata->conn->account))
37     return IMAP_AUTH_FAILURE;
38   if (mutt_account_getpass (&idata->conn->account))
39     return IMAP_AUTH_FAILURE;
40
41   mutt_message _("Logging in...");
42
43   imap_quote_string (q_user, sizeof (q_user), idata->conn->account.user);
44   imap_quote_string (q_pass, sizeof (q_pass), idata->conn->account.pass);
45
46 #ifdef DEBUG
47   /* don't print the password unless we're at the ungodly debugging level
48    * of 5 or higher */
49
50   if (DebugLevel < IMAP_LOG_PASS)
51     debug_print (2, ("Sending LOGIN command for %s...\n",
52                 idata->conn->account.user));
53 #endif
54
55   snprintf (buf, sizeof (buf), "LOGIN %s %s", q_user, q_pass);
56   rc = imap_exec (idata, buf, IMAP_CMD_FAIL_OK | IMAP_CMD_PASS);
57
58   if (!rc)
59     return IMAP_AUTH_SUCCESS;
60
61   mutt_error _("Login failed.");
62
63   mutt_sleep (2);
64   return IMAP_AUTH_FAILURE;
65 }