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