fixed local account
[claws.git] / src / send.c
index d332ab8f3414de9adf39f6f6e68449f7f0bdab6e..a22afc434a0157b90696921298fee19f94905ad7 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2001 Hiroyuki Yamamoto
+ * Copyright (C) 1999-2002 Hiroyuki Yamamoto
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -76,8 +76,6 @@ static SendProgressDialog *send_progress_dialog_create(void);
 static void send_progress_dialog_destroy(SendProgressDialog *dialog);
 static void send_cancel(GtkWidget *widget, gpointer data);
 
-static gchar *send_query_password(const gchar *server, const gchar *user);
-
 
 gint send_message(const gchar *file, PrefsAccount *ac_prefs, GSList *to_list)
 {
@@ -93,16 +91,25 @@ gint send_message(const gchar *file, PrefsAccount *ac_prefs, GSList *to_list)
                return -1;
        }
 
-       if (prefs_common.use_extsend && prefs_common.extsend_cmd) {
+       printf("account: %p\n", ac_prefs);
+
+       if (ac_prefs->use_mail_command && ac_prefs->mail_command &&
+           (*ac_prefs->mail_command)) {
+               val = send_message_local(ac_prefs->mail_command, fp);
+               fclose(fp);
+               return val;
+       }
+       else if (prefs_common.use_extsend && prefs_common.extsend_cmd) {
                val = send_message_local(prefs_common.extsend_cmd, fp);
                fclose(fp);
                return val;
        }
-
-       val = send_message_smtp(ac_prefs, to_list, fp);
-
-       fclose(fp);
-       return val;
+       else {
+               val = send_message_smtp(ac_prefs, to_list, fp);
+               
+               fclose(fp);
+               return val;
+       }
 }
 
 enum
@@ -113,6 +120,7 @@ enum
        Q_ACCOUNT_ID = 3
 };
 
+#if 0
 gint send_message_queue(const gchar *file)
 {
        static HeaderEntry qentry[] = {{"S:",   NULL, FALSE},
@@ -154,12 +162,16 @@ gint send_message_queue(const gchar *file)
                        ac = account_find_from_id(atoi(p));
                        break;
                default:
+                       break;
                }
        }
 
        if (!to_list || !from) {
                g_warning(_("Queued message header is broken.\n"));
                val = -1;
+       } else if (ac && ac->use_mail_command && ac->mail_command &&
+                  (*ac->mail_command)) {
+               val = send_message_local(ac->mail_command, fp);
        } else if (prefs_common.use_extsend && prefs_common.extsend_cmd) {
                val = send_message_local(prefs_common.extsend_cmd, fp);
        } else {
@@ -195,11 +207,13 @@ gint send_message_queue(const gchar *file)
 
        return val;
 }
+#endif
 
 gint send_message_local(const gchar *command, FILE *fp)
 {
        FILE *pipefp;
        gchar buf[BUFFSIZE];
+       int r;
 
        g_return_val_if_fail(command != NULL, -1);
        g_return_val_if_fail(fp != NULL, -1);
@@ -219,7 +233,11 @@ gint send_message_local(const gchar *command, FILE *fp)
                fputc('\n', pipefp);
        }
 
-       pclose(pipefp);
+       r = pclose(pipefp);
+       if (r != 0) {
+               g_warning(_("external command failed: %s\n"), command);
+               return -1;
+       }
 
        return 0;
 }
@@ -257,6 +275,10 @@ gint send_message_local(const gchar *command, FILE *fp)
                                g_free(ac_prefs->tmp_pass); \
                                ac_prefs->tmp_pass = NULL; \
                        } \
+                       if (ac_prefs->tmp_smtp_pass) { \
+                               g_free(ac_prefs->tmp_smtp_pass); \
+                               ac_prefs->tmp_smtp_pass = NULL; \
+                       } \
                } \
                if (smtp_quit(smtp_sock) != SM_OK) \
                        log_warning("Error occurred while sending QUIT\n"); \
@@ -276,6 +298,7 @@ gint send_message_smtp(PrefsAccount *ac_prefs, GSList *to_list,
        gchar buf[BUFFSIZE];
        gushort port;
        gchar *domain;
+       gchar *user = NULL;
        gchar *pass = NULL;
        GSList *cur;
        gint size;
@@ -298,15 +321,30 @@ gint send_message_smtp(PrefsAccount *ac_prefs, GSList *to_list,
        domain = ac_prefs->set_domain ? ac_prefs->domain : NULL;
 
        if (ac_prefs->use_smtp_auth) {
-               if (ac_prefs->passwd)
-                       pass = ac_prefs->passwd;
-               else if (ac_prefs->tmp_pass)
-                       pass = ac_prefs->tmp_pass;
-               else {
-                       pass = send_query_password(ac_prefs->smtp_server,
-                                                  ac_prefs->userid);
-                       if (!pass) pass = g_strdup("");
-                       ac_prefs->tmp_pass = pass;
+               if (ac_prefs->smtp_userid) {
+                       user = ac_prefs->smtp_userid;
+                       if (ac_prefs->smtp_passwd)
+                               pass = ac_prefs->smtp_passwd;
+                       else if (ac_prefs->tmp_smtp_pass)
+                               pass = ac_prefs->tmp_smtp_pass;
+                       else {
+                               pass = input_dialog_query_password
+                                       (ac_prefs->smtp_server, user);
+                               if (!pass) pass = g_strdup("");
+                               ac_prefs->tmp_smtp_pass = pass;
+                       }
+               } else {
+                       user = ac_prefs->userid;
+                       if (ac_prefs->passwd)
+                               pass = ac_prefs->passwd;
+                       else if (ac_prefs->tmp_pass)
+                               pass = ac_prefs->tmp_pass;
+                       else {
+                               pass = input_dialog_query_password
+                                       (ac_prefs->smtp_server, user);
+                               if (!pass) pass = g_strdup("");
+                               ac_prefs->tmp_pass = pass;
+                       }
                }
        }
 
@@ -342,8 +380,8 @@ gint send_message_smtp(PrefsAccount *ac_prefs, GSList *to_list,
        GTK_EVENTS_FLUSH();
 
        SEND_EXIT_IF_NOTOK
-               (smtp_from(smtp_sock, ac_prefs->address, ac_prefs->userid,
-                          pass, ac_prefs->use_smtp_auth),
+               (smtp_from(smtp_sock, ac_prefs->address, user, pass,
+                          ac_prefs->use_smtp_auth),
                 "sending MAIL FROM");
 
        progress_dialog_set_label(dialog->dialog, _("Sending RCPT TO..."));
@@ -589,16 +627,3 @@ static void send_cancel(GtkWidget *widget, gpointer data)
 
        dialog->cancelled = TRUE;
 }
-
-static gchar *send_query_password(const gchar *server, const gchar *user)
-{
-       gchar *message;
-       gchar *pass;
-
-       message = g_strdup_printf(_("Input password for %s on %s:"),
-                                 user, server);
-       pass = input_dialog_with_invisible(_("Input password"), message, NULL);
-       g_free(message);
-
-       return pass;
-}