separate username/password for SMTP Auth
authorPaul Mangan <paul@claws-mail.org>
Sat, 13 Oct 2001 17:00:28 +0000 (17:00 +0000)
committerPaul Mangan <paul@claws-mail.org>
Sat, 13 Oct 2001 17:00:28 +0000 (17:00 +0000)
ChangeLog.claws
configure.in
src/prefs_account.c
src/prefs_account.h
src/send.c
src/smtp.c
src/smtp.h

index cc1115d..83da651 100644 (file)
@@ -1,3 +1,10 @@
+2001-10-13 [paul]      0.6.3claws14
+
+       * src/prefs_account.[ch], src/send.c, src/smtp.[ch]
+               add Sergey's smtpcred.patch
+               adds separate username/password setting for SMTP Auth
+               needed by some servers
+
 2001-10-13 [paul]      0.6.3claws13
 
        * src/pgptext.[ch] **NEW FILES**
index 5ab2174..9863786 100644 (file)
@@ -8,7 +8,7 @@ MINOR_VERSION=6
 MICRO_VERSION=3
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=claws13
+EXTRA_VERSION=claws14
 VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION$EXTRA_VERSION
 
 dnl
index 2eac6ab..e332d8e 100644 (file)
@@ -108,6 +108,8 @@ static struct Send {
        GtkWidget *autoreplyto_entry;
 
        GtkWidget *smtp_auth_chkbtn;
+       GtkWidget *smtp_userid_entry;
+       GtkWidget *smtp_passwd_entry;
        GtkWidget *pop_bfr_smtp_chkbtn;
 } send;
 
@@ -283,6 +285,12 @@ static PrefParam param[] = {
         &send.smtp_auth_chkbtn,
         prefs_set_data_from_toggle, prefs_set_toggle},
 
+       {"smtp_user_id", "ENV_USER", &tmp_ac_prefs.smtp_userid, P_STRING,
+        &send.smtp_userid_entry, prefs_set_data_from_entry, prefs_set_entry},
+
+       {"smtp_password", NULL, &tmp_ac_prefs.smtp_passwd, P_STRING,
+        &send.smtp_passwd_entry, prefs_set_data_from_entry, prefs_set_entry},
+
        {"pop_before_smtp", "FALSE", &tmp_ac_prefs.pop_before_smtp, P_BOOL,
         &send.pop_bfr_smtp_chkbtn,
         prefs_set_data_from_toggle, prefs_set_toggle},
@@ -1007,6 +1015,12 @@ static void prefs_account_send_create(void)
        GtkWidget *frame3;
        GtkWidget *vbox3;
        GtkWidget *smtp_auth_chkbtn;
+       GtkWidget *smtp_auth_hbox;
+       GtkWidget *label;
+       GtkWidget *uid_label;
+       GtkWidget *smtp_userid_entry;
+       GtkWidget *pass_label;
+       GtkWidget *smtp_passwd_entry;
        GtkWidget *pop_bfr_smtp_chkbtn;
 
        vbox1 = gtk_vbox_new (FALSE, VSPACING);
@@ -1098,6 +1112,44 @@ static void prefs_account_send_create(void)
 
        PACK_CHECK_BUTTON (vbox3, smtp_auth_chkbtn,
                _("SMTP Authentication (SMTP AUTH)"));
+
+       smtp_auth_hbox = gtk_hbox_new (FALSE, 8);
+       gtk_widget_show (smtp_auth_hbox);
+       gtk_box_pack_start (GTK_BOX (vbox3), smtp_auth_hbox, FALSE, FALSE, 0);
+
+       label = gtk_label_new ("");
+       gtk_widget_show (label);
+       gtk_box_pack_start (GTK_BOX (smtp_auth_hbox), label, FALSE, FALSE, 0);
+       gtk_widget_set_usize (label, 16, -1);
+
+       uid_label = gtk_label_new (_("User ID"));
+       gtk_widget_show (uid_label);
+       gtk_box_pack_start (GTK_BOX (smtp_auth_hbox), uid_label,
+                           FALSE, FALSE, 0);
+       gtk_misc_set_alignment (GTK_MISC (uid_label), 1, 0.5);
+       SET_TOGGLE_SENSITIVITY (smtp_auth_chkbtn, uid_label);
+
+       smtp_userid_entry = gtk_entry_new ();
+       gtk_widget_show (smtp_userid_entry);
+       gtk_widget_set_usize (smtp_userid_entry, DEFAULT_ENTRY_WIDTH, -1);
+       gtk_box_pack_start (GTK_BOX (smtp_auth_hbox), smtp_userid_entry,
+                           TRUE, TRUE, 0);
+       SET_TOGGLE_SENSITIVITY (smtp_auth_chkbtn, smtp_userid_entry);
+
+       pass_label = gtk_label_new (_("Password"));
+       gtk_widget_show (pass_label);
+       gtk_box_pack_start (GTK_BOX (smtp_auth_hbox), pass_label,
+                           FALSE, FALSE, 0);
+       SET_TOGGLE_SENSITIVITY (smtp_auth_chkbtn, pass_label);
+
+       smtp_passwd_entry = gtk_entry_new ();
+       gtk_widget_show (smtp_passwd_entry);
+       gtk_widget_set_usize (smtp_passwd_entry, DEFAULT_ENTRY_WIDTH, -1);
+       gtk_box_pack_start (GTK_BOX (smtp_auth_hbox), smtp_passwd_entry,
+                           TRUE, TRUE, 0);
+       gtk_entry_set_visibility (GTK_ENTRY (smtp_passwd_entry), FALSE);
+       SET_TOGGLE_SENSITIVITY (smtp_auth_chkbtn, smtp_passwd_entry);
+
        PACK_CHECK_BUTTON (vbox3, pop_bfr_smtp_chkbtn,
                _("Authenticate with POP3 before sending"));
        gtk_widget_set_sensitive(pop_bfr_smtp_chkbtn, FALSE);
@@ -1114,6 +1166,8 @@ static void prefs_account_send_create(void)
        send.autoreplyto_entry  = autoreplyto_entry;
 
        send.smtp_auth_chkbtn    = smtp_auth_chkbtn;
+       send.smtp_userid_entry   = smtp_userid_entry;
+       send.smtp_passwd_entry   = smtp_passwd_entry;
        send.pop_bfr_smtp_chkbtn = pop_bfr_smtp_chkbtn;
 }
 
index a60e093..341174b 100644 (file)
@@ -88,6 +88,7 @@ struct _PrefsAccount
 
        /* Temporarily preserved password */
        gchar *tmp_pass;
+       gchar *tmp_smtp_passwd;
 
        /* Receive */
        gboolean rmmail;
@@ -108,6 +109,8 @@ struct _PrefsAccount
        gboolean  set_autoreplyto;
        gchar    *auto_replyto;
        gboolean use_smtp_auth;
+       gchar    *smtp_userid;
+       gchar    *smtp_passwd;
        gboolean pop_before_smtp;
 
        GSList *customhdr_list;
index b43a203..cc4dfb0 100644 (file)
@@ -49,6 +49,7 @@
 #include "procheader.h"
 #include "utils.h"
 #include "gtkutils.h"
+#include "inputdialog.h"
 
 #define SMTP_PORT      25
 #if USE_SSL
@@ -66,21 +67,14 @@ struct _SendProgressDialog
 
 static gint send_message_local (const gchar *command, FILE *fp);
 
-#if USE_SSL
 static gint send_message_smtp  (GSList *to_list, const gchar *from,
-                                const gchar *server, gushort port,
-                                const gchar *domain, const gchar *userid,
-                                const gchar *passwd, gboolean use_smtp_auth,
-                                SSLSMTPType ssl_type, FILE *fp);
+                                const gchar *server, PrefsAccount *ac,
+                                FILE *fp);
+#if USE_SSL
 static SockInfo *send_smtp_open        (const gchar *server, gushort port,
                                 const gchar *domain, gboolean use_smtp_auth,
                                 SSLSMTPType ssl_type);
 #else
-static gint send_message_smtp  (GSList *to_list, const gchar *from,
-                                const gchar *server, gushort port,
-                                const gchar *domain, const gchar *userid,
-                                const gchar *passwd, gboolean use_smtp_auth,
-                                FILE *fp);
 static SockInfo *send_smtp_open        (const gchar *server, gushort port,
                                 const gchar *domain, gboolean use_smtp_auth);
 #endif
@@ -96,8 +90,6 @@ gint send_message(const gchar *file, PrefsAccount *ac_prefs, GSList *to_list)
 {
        FILE *fp;
        gint val;
-       gushort port;
-       gchar *domain;
 
        g_return_val_if_fail(file != NULL, -1);
        g_return_val_if_fail(ac_prefs != NULL, -1);
@@ -114,26 +106,7 @@ gint send_message(const gchar *file, PrefsAccount *ac_prefs, GSList *to_list)
                return val;
        }
 
-#if USE_SSL
-       port = ac_prefs->set_smtpport ? ac_prefs->smtpport :
-               ac_prefs->ssl_smtp == SSL_SMTP_TUNNEL ? SSMTP_PORT : SMTP_PORT;
-#else
-       port = ac_prefs->set_smtpport ? ac_prefs->smtpport : SMTP_PORT;
-#endif
-       domain = ac_prefs->set_domain ? ac_prefs->domain : NULL;
-
-#if USE_SSL
-       val = send_message_smtp(to_list, ac_prefs->address,
-                               ac_prefs->smtp_server, port, domain,
-                               ac_prefs->userid, ac_prefs->passwd,
-                               ac_prefs->use_smtp_auth, ac_prefs->ssl_smtp,
-                               fp);
-#else
-       val = send_message_smtp(to_list, ac_prefs->address,
-                               ac_prefs->smtp_server, port, domain,
-                               ac_prefs->userid, ac_prefs->passwd,
-                               ac_prefs->use_smtp_auth, fp);
-#endif
+       val = send_message_smtp(to_list, NULL, NULL, ac_prefs, fp);
 
        fclose(fp);
        return val;
@@ -197,9 +170,6 @@ gint send_message_queue(const gchar *file)
        } else if (prefs_common.use_extsend && prefs_common.extsend_cmd) {
                val = send_message_local(prefs_common.extsend_cmd, fp);
        } else {
-               gushort port;
-               gchar *domain;
-
                if (!ac) {
                        ac = account_find_from_smtp_server(from, server);
                        if (!ac) {
@@ -210,35 +180,11 @@ gint send_message_queue(const gchar *file)
                }
 
                if (ac) {
-#if USE_SSL
-                       port = ac->set_smtpport ? ac->smtpport :
-                               ac->ssl_smtp == SSL_SMTP_TUNNEL ?
-                               SSMTP_PORT : SMTP_PORT;
-#else
-                       port = ac->set_smtpport ? ac->smtpport : SMTP_PORT;
-#endif
-                       domain = ac->set_domain ? ac->domain : NULL;
-#if USE_SSL
-                       val = send_message_smtp
-                               (to_list, from, ac->smtp_server, port, domain,
-                                ac->userid, ac->passwd, ac->use_smtp_auth,
-                                ac->ssl_smtp, fp);
-#else
-                       val = send_message_smtp
-                               (to_list, from, ac->smtp_server, port, domain,
-                                ac->userid, ac->passwd, ac->use_smtp_auth, fp);
-#endif
+                       val = send_message_smtp(to_list, from, NULL, ac, fp);
                } else {
                        g_warning(_("Account not found.\n"));
-#if USE_SSL
-                       val = send_message_smtp
-                               (to_list, from, server, SMTP_PORT, NULL,
-                                NULL, NULL, FALSE, FALSE, fp);
-#else
-                       val = send_message_smtp
-                               (to_list, from, server, SMTP_PORT, NULL,
-                                NULL, NULL, FALSE, fp);
-#endif
+                       val = send_message_smtp(to_list, from, server, NULL,
+                                               fp);
                }
        }
 
@@ -284,6 +230,7 @@ static gint send_message_local(const gchar *command, FILE *fp)
        if (dialog->cancelled) { \
                sock_close(smtp_sock); \
                send_progress_dialog_destroy(dialog); \
+               g_free(passwd); \
                return -1; \
        } \
 }
@@ -295,37 +242,44 @@ static gint send_message_local(const gchar *command, FILE *fp)
                log_warning("Error occurred while %s\n", s); \
                sock_close(smtp_sock); \
                send_progress_dialog_destroy(dialog); \
+               g_free(passwd); \
                return -1; \
        } \
 }
 
 #define SEND_EXIT_IF_NOTOK(f, s) \
 { \
+       gint ok; \
        EXIT_IF_CANCELLED(); \
-       if ((f) != SM_OK) { \
+       if ((ok = (f)) != SM_OK) { \
                log_warning("Error occurred while %s\n", s); \
+               if (ok == SM_AUTHFAIL) { \
+                       if (ac && ac->tmp_smtp_passwd) { \
+                               g_free(ac->tmp_smtp_passwd); \
+                               ac->tmp_smtp_passwd = NULL; \
+                       } \
+               } \
                if (smtp_quit(smtp_sock) != SM_OK) \
                        log_warning("Error occurred while sending QUIT\n"); \
                sock_close(smtp_sock); \
                send_progress_dialog_destroy(dialog); \
+               g_free(passwd); \
                return -1; \
        } \
 }
 
-#if USE_SSL
 static gint send_message_smtp(GSList *to_list, const gchar *from,
-                             const gchar *server, gushort port,
-                             const gchar *domain, const gchar *userid,
-                             const gchar *passwd, gboolean use_smtp_auth,
-                             SSLSMTPType ssl_type, FILE *fp)
-#else
-static gint send_message_smtp(GSList *to_list, const gchar *from,
-                             const gchar *server, gushort port,
-                             const gchar *domain, const gchar *userid,
-                             const gchar *passwd, gboolean use_smtp_auth,
+                             const gchar *server, PrefsAccount *ac,
                              FILE *fp)
-#endif
 {
+       gushort port;
+       const gchar *domain;
+       const gchar *userid;
+       gchar *passwd = NULL;
+       gboolean use_smtp_auth;
+#if USE_SSL
+       SSLSMTPType ssl_type;
+#endif
        SockInfo *smtp_sock = NULL;
        SendProgressDialog *dialog;
        GtkCList *clist;
@@ -335,10 +289,61 @@ static gint send_message_smtp(GSList *to_list, const gchar *from,
        gint size;
 
        g_return_val_if_fail(to_list != NULL, -1);
-       g_return_val_if_fail(from != NULL, -1);
-       g_return_val_if_fail(server != NULL, -1);
        g_return_val_if_fail(fp != NULL, -1);
 
+       if (ac == NULL) {
+               g_return_val_if_fail(from != NULL, -1);
+               g_return_val_if_fail(server != NULL, -1);
+               port = SMTP_PORT;
+               domain = userid = passwd = NULL;
+               use_smtp_auth = FALSE;
+#if USE_SSL
+               ssl_type = FALSE;
+#endif
+       } else {
+               if (from == NULL)
+                       from = ac->address;
+               if (server == NULL)
+                       server = ac->smtp_server;
+               g_return_val_if_fail(from != NULL, -1);
+               g_return_val_if_fail(server != NULL, -1);
+
+#if USE_SSL
+               port = ac->set_smtpport ? ac->smtpport :
+                       ac->ssl_smtp == SSL_SMTP_TUNNEL ?
+                       SSMTP_PORT : SMTP_PORT;
+               ssl_type = ac->ssl_smtp;
+#else
+               port = ac->set_smtpport ? ac->smtpport : SMTP_PORT;
+#endif
+               domain = ac->set_domain ? ac->domain : NULL;
+               userid = ac->smtp_userid;
+               use_smtp_auth = ac->use_smtp_auth;
+               if (ac->smtp_passwd)
+                       passwd = g_strdup(ac->smtp_passwd);
+               else if (ac->tmp_smtp_passwd)
+                       passwd = g_strdup(ac->tmp_smtp_passwd);
+               else if (use_smtp_auth && userid) {
+                       gchar *pass;
+                       gchar *message;
+
+                       message = g_strdup_printf
+                               (_("Input password for %s on %s:"),
+                                userid, server);
+
+                       pass = input_dialog_with_invisible(_("Input password"),
+                                                          message, NULL);
+                       g_free(message);
+                       if (pass) {
+                               ac->tmp_smtp_passwd = g_strdup(pass);
+                               passwd = pass;
+                       }
+               }
+       }
+
+       if (use_smtp_auth && (!userid || !passwd))
+               use_smtp_auth = FALSE;
+
        size = get_left_file_size(fp);
        if (size < 0) return -1;
 
@@ -399,6 +404,7 @@ static gint send_message_smtp(GSList *to_list, const gchar *from,
 
        sock_close(smtp_sock);
        send_progress_dialog_destroy(dialog);
+       g_free(passwd);
 
        return 0;
 }
index fa6d9fa..cbcc8f7 100644 (file)
@@ -62,7 +62,8 @@ gint smtp_from(SockInfo *sock, const gchar *from,
                } else
                        authtype = SMTPAUTH_CRAM_MD5;
 
-               esmtp_auth(sock, authtype, userid, passwd);
+               if (esmtp_auth(sock, authtype, userid, passwd) != SM_OK)
+                       return SM_AUTHFAIL;
        }
 
        if (strchr(from, '<'))
index cd989ca..4004292 100644 (file)
@@ -29,6 +29,7 @@
 #define        SM_OK                   0
 #define        SM_ERROR                128
 #define        SM_UNRECOVERABLE        129
+#define        SM_AUTHFAIL             130
 
 #define        ESMTP_8BITMIME          0x01
 #define        ESMTP_SIZE              0x02