#include "procheader.h"
#include "prefs_account.h"
#include "codeconv.h"
+#include "md5.h"
+#include "base64.h"
#include "utils.h"
#include "inputdialog.h"
#include "log.h"
static IMAPSession *imap_session_get (Folder *folder);
+static gint imap_auth (IMAPSession *session,
+ const gchar *user,
+ const gchar *pass,
+ IMAPAuthType type);
+
static gint imap_scan_tree_recursive (IMAPSession *session,
FolderItem *item);
static GSList *imap_parse_list (IMAPFolder *folder,
(MsgNumberList *list);
/* low-level IMAP4rev1 commands */
+static gint imap_cmd_authenticate
+ (IMAPSession *session,
+ const gchar *user,
+ const gchar *pass,
+ IMAPAuthType type);
static gint imap_cmd_login (IMAPSession *sock,
const gchar *user,
const gchar *pass);
g_node_traverse(folder->node, G_IN_ORDER, G_TRAVERSE_ALL, -1, imap_reset_uid_lists_func, NULL);
}
+static gint imap_auth(IMAPSession *session, const gchar *user, const gchar *pass,
+ IMAPAuthType type)
+{
+ if (type == 0 || type == IMAP_AUTH_LOGIN)
+ return imap_cmd_login(session, user, pass);
+ else
+ return imap_cmd_authenticate(session, user, pass, type);
+}
+
static IMAPSession *imap_session_get(Folder *folder)
{
RemoteFolder *rfolder = REMOTE_FOLDER(folder);
IMAPSession *session = NULL;
- gushort port;
g_return_val_if_fail(folder != NULL, NULL);
g_return_val_if_fail(FOLDER_CLASS(folder) == &imap_class, NULL);
g_return_val_if_fail(folder->account != NULL, NULL);
-#if USE_OPENSSL
- port = folder->account->set_imapport ? folder->account->imapport
- : folder->account->ssl_imap == SSL_TUNNEL
- ? IMAPS_PORT : IMAP4_PORT;
-#else
- port = folder->account->set_imapport ? folder->account->imapport
- : IMAP4_PORT;
-#endif
-
/* Make sure we have a session */
if (rfolder->session != NULL) {
session = IMAP_SESSION(rfolder->session);
/* Check if this is the first try to establish a
connection, if yes we don't try to reconnect */
if (rfolder->session == NULL) {
- log_warning(_("Connecting %s:%d failed"),
- folder->account->recv_server, port);
+ log_warning(_("Connecting %s failed"),
+ folder->account->recv_server);
session_destroy(SESSION(session));
session = NULL;
} else {
- log_warning(_("IMAP4 connection to %s:%d has been"
+ log_warning(_("IMAP4 connection to %s has been"
" disconnected. Reconnecting...\n"),
- folder->account->recv_server, port);
+ folder->account->recv_server);
session_destroy(SESSION(session));
/* Clear folders session to make imap_session_get create
a new session, because of rfolder->session == NULL
g_free(tmp_pass);
}
- if (imap_cmd_login(session, account->userid, pass) != IMAP_SUCCESS) {
+ if (imap_auth(session, account->userid, pass, account->imap_auth_type) != IMAP_SUCCESS) {
imap_cmd_logout(session);
return;
}
/* low-level IMAP4rev1 commands */
+static gint imap_cmd_authenticate(IMAPSession *session, const gchar *user,
+ const gchar *pass, IMAPAuthType type)
+{
+ gchar *auth_type;
+ gint ok;
+ gchar *buf;
+ gchar *challenge;
+ gint challenge_len;
+ gchar hexdigest[33];
+ gchar *response;
+ gchar *response64;
+
+ auth_type = "CRAM-MD5";
+
+ imap_gen_send(session, "AUTHENTICATE %s", auth_type);
+ ok = imap_gen_recv(session, &buf);
+ if (ok != IMAP_SUCCESS || buf[0] != '+' || buf[1] != ' ') {
+ g_free(buf);
+ return IMAP_ERROR;
+ }
+
+ challenge = g_malloc(strlen(buf + 2) + 1);
+ challenge_len = base64_decode(challenge, buf + 2, -1);
+ challenge[challenge_len] = '\0';
+ log_print("IMAP< [Decoded: %s]\n", challenge);
+ g_free(buf);
+
+ md5_hex_hmac(hexdigest, challenge, challenge_len, pass, strlen(pass));
+ g_free(challenge);
+
+ response = g_strdup_printf("%s %s", user, hexdigest);
+ log_print("IMAP> [Encoded: %s]\n", response);
+ response64 = g_malloc((strlen(response) + 3) * 2 + 1);
+ base64_encode(response64, response, strlen(response));
+ g_free(response);
+
+ log_print("IMAP> %s\n", response64);
+ sock_puts(SESSION(session)->sock, response64);
+ ok = imap_cmd_ok(session, NULL);
+ if (ok != IMAP_SUCCESS)
+ log_warning(_("IMAP4 authentication failed.\n"));
+
+ return ok;
+}
+
static gint imap_cmd_login(IMAPSession *session,
const gchar *user, const gchar *pass)
{
#include "utils.h"
#include "alertpanel.h"
#include "colorlabel.h"
+#include "smtp.h"
+#include "imap.h"
static gboolean cancelled;
GtkWidget *filter_on_recv_chkbtn;
GtkWidget *recvatgetall_chkbtn;
+
+ GtkWidget *imap_frame;
+ GtkWidget *imap_auth_type_optmenu;
GtkWidget *frame_maxarticle;
GtkWidget *label_maxarticle;
static void prefs_account_protocol_set_optmenu (PrefParam *pparam);
static void prefs_account_protocol_activated (GtkMenuItem *menuitem);
+static void prefs_account_imap_auth_type_set_data_from_optmenu
+ (PrefParam *pparam);
+static void prefs_account_imap_auth_type_set_optmenu (PrefParam *pparam);
static void prefs_account_smtp_auth_type_set_data_from_optmenu
(PrefParam *pparam);
static void prefs_account_smtp_auth_type_set_optmenu (PrefParam *pparam);
&receive.filter_on_recv_chkbtn,
prefs_set_data_from_toggle, prefs_set_toggle},
+ {"imap_auth_method", "0", &tmp_ac_prefs.imap_auth_type, P_ENUM,
+ &receive.imap_auth_type_optmenu,
+ prefs_account_imap_auth_type_set_data_from_optmenu,
+ prefs_account_imap_auth_type_set_optmenu},
+
{"receive_at_get_all", "TRUE", &tmp_ac_prefs.recv_at_getall, P_BOOL,
&receive.recvatgetall_chkbtn,
prefs_set_data_from_toggle, prefs_set_toggle},
GtkWidget *inbox_label;
GtkWidget *inbox_entry;
GtkWidget *inbox_btn;
+ GtkWidget *imap_frame;
+ GtkWidget *optmenu;
+ GtkWidget *optmenu_menu;
+ GtkWidget *menuitem;
GtkWidget *recvatgetall_chkbtn;
GtkWidget *hbox2;
gtk_box_pack_start (GTK_BOX (hbox2), label_maxarticle, FALSE, FALSE, 0);
gtk_label_set_justify (GTK_LABEL (label_maxarticle), GTK_JUSTIFY_LEFT);
+ PACK_FRAME (vbox1, imap_frame, _("IMAP4"));
+
+ vbox2 = gtk_vbox_new (FALSE, 0);
+ gtk_widget_show (vbox2);
+ gtk_container_add (GTK_CONTAINER (imap_frame), vbox2);
+ gtk_container_set_border_width (GTK_CONTAINER (vbox2), 8);
+
+ hbox1 = gtk_hbox_new (FALSE, 8);
+ gtk_widget_show (hbox1);
+ gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, FALSE, 0);
+
+ label = gtk_label_new (_("Authentication method"));
+ gtk_widget_show (label);
+ gtk_box_pack_start (GTK_BOX (hbox1), label, FALSE, FALSE, 0);
+
+ optmenu = gtk_option_menu_new ();
+ gtk_widget_show (optmenu);
+ gtk_box_pack_start (GTK_BOX (hbox1), optmenu, FALSE, FALSE, 0);
+
+ optmenu_menu = gtk_menu_new ();
+
+ MENUITEM_ADD (optmenu_menu, menuitem, _("Automatic"), 0);
+ MENUITEM_ADD (optmenu_menu, menuitem, "LOGIN", IMAP_AUTH_LOGIN);
+ MENUITEM_ADD (optmenu_menu, menuitem, "CRAM-MD5", IMAP_AUTH_CRAM_MD5);
+
+ gtk_option_menu_set_menu (GTK_OPTION_MENU (optmenu), optmenu_menu);
+
PACK_CHECK_BUTTON (vbox1, filter_on_recv_chkbtn,
_("Filter messages on receiving"));
receive.inbox_entry = inbox_entry;
receive.inbox_btn = inbox_btn;
+ receive.imap_frame = imap_frame;
+ receive.imap_auth_type_optmenu = optmenu;
+
receive.recvatgetall_chkbtn = recvatgetall_chkbtn;
receive.frame_maxarticle = frame2;
gtk_menu_item_activate(GTK_MENU_ITEM(menuitem));
}
+static void prefs_account_imap_auth_type_set_data_from_optmenu(PrefParam *pparam)
+{
+ GtkWidget *menu;
+ GtkWidget *menuitem;
+
+ menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(*pparam->widget));
+ menuitem = gtk_menu_get_active(GTK_MENU(menu));
+ *((RecvProtocol *)pparam->data) = GPOINTER_TO_INT
+ (gtk_object_get_user_data(GTK_OBJECT(menuitem)));
+}
+
+static void prefs_account_imap_auth_type_set_optmenu(PrefParam *pparam)
+{
+ IMAPAuthType type = *((IMAPAuthType *)pparam->data);
+ GtkOptionMenu *optmenu = GTK_OPTION_MENU(*pparam->widget);
+ GtkWidget *menu;
+ GtkWidget *menuitem;
+
+ switch (type) {
+ case IMAP_AUTH_LOGIN:
+ gtk_option_menu_set_history(optmenu, 1);
+ break;
+ case IMAP_AUTH_CRAM_MD5:
+ gtk_option_menu_set_history(optmenu, 2);
+ break;
+ case 0:
+ default:
+ gtk_option_menu_set_history(optmenu, 0);
+ }
+
+ menu = gtk_option_menu_get_menu(optmenu);
+ menuitem = gtk_menu_get_active(GTK_MENU(menu));
+ gtk_menu_item_activate(GTK_MENU_ITEM(menuitem));
+}
+
static void prefs_account_smtp_auth_type_set_data_from_optmenu(PrefParam *pparam)
{
GtkWidget *menu;
prefs_account_nntpauth_toggled
(GTK_TOGGLE_BUTTON(basic.nntpauth_chkbtn), NULL);
gtk_widget_hide(receive.pop3_frame);
+ gtk_widget_hide(receive.imap_frame);
gtk_widget_show(receive.frame_maxarticle);
gtk_widget_set_sensitive(receive.recvatgetall_chkbtn, TRUE);
/* update pop_before_smtp sensitivity */
gtk_widget_set_sensitive(basic.uid_entry, TRUE);
gtk_widget_set_sensitive(basic.pass_entry, TRUE);
gtk_widget_hide(receive.pop3_frame);
+ gtk_widget_hide(receive.imap_frame);
gtk_widget_hide(receive.frame_maxarticle);
gtk_widget_set_sensitive(receive.recvatgetall_chkbtn, TRUE);
prefs_account_mailcmd_toggled
gtk_widget_set_sensitive(basic.uid_entry, TRUE);
gtk_widget_set_sensitive(basic.pass_entry, TRUE);
gtk_widget_hide(receive.pop3_frame);
+ gtk_widget_show(receive.imap_frame);
gtk_widget_hide(receive.frame_maxarticle);
gtk_widget_set_sensitive(receive.recvatgetall_chkbtn, TRUE);
gtk_widget_set_sensitive(basic.smtpserv_entry, TRUE);
gtk_widget_set_sensitive(basic.pass_entry, TRUE);
gtk_widget_set_sensitive(receive.pop3_frame, TRUE);
gtk_widget_show(receive.pop3_frame);
+ gtk_widget_hide(receive.imap_frame);
gtk_widget_hide(receive.frame_maxarticle);
gtk_widget_set_sensitive(receive.recvatgetall_chkbtn, TRUE);