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