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