* src/procmsg.c
[claws.git] / src / send.c
index bb764a6d022ddaf233140da8d1132dc0f85ffc24..645be80bacb6b920a1d854551887d25ee6f0852f 100644 (file)
@@ -31,6 +31,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <sys/time.h>
+#include <signal.h>
 #include <unistd.h>
 
 #include "intl.h"
@@ -86,21 +87,30 @@ gint send_message(const gchar *file, PrefsAccount *ac_prefs, GSList *to_list)
        g_return_val_if_fail(ac_prefs != NULL, -1);
        g_return_val_if_fail(to_list != NULL, -1);
 
-       if ((fp = fopen(file, "r")) == NULL) {
+       if ((fp = fopen(file, "rb")) == NULL) {
                FILE_OP_ERROR(file, "fopen");
                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
@@ -111,6 +121,7 @@ enum
        Q_ACCOUNT_ID = 3
 };
 
+#if 0
 gint send_message_queue(const gchar *file)
 {
        static HeaderEntry qentry[] = {{"S:",   NULL, FALSE},
@@ -129,7 +140,7 @@ gint send_message_queue(const gchar *file)
 
        g_return_val_if_fail(file != NULL, -1);
 
-       if ((fp = fopen(file, "r")) == NULL) {
+       if ((fp = fopen(file, "rb")) == NULL) {
                FILE_OP_ERROR(file, "fopen");
                return -1;
        }
@@ -159,6 +170,9 @@ gint send_message_queue(const gchar *file)
        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 {
@@ -194,11 +208,14 @@ 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;
+       sigset_t osig, mask;
 
        g_return_val_if_fail(command != NULL, -1);
        g_return_val_if_fail(fp != NULL, -1);
@@ -218,7 +235,21 @@ gint send_message_local(const gchar *command, FILE *fp)
                fputc('\n', pipefp);
        }
 
-       pclose(pipefp);
+       /* we need to block SIGCHLD, otherwise pspell's handler will wait()
+        * the pipecommand away and pclose will return -1 because of its
+        * failed wait4().
+        */
+       sigemptyset(&mask);
+       sigaddset(&mask, SIGCHLD);
+       sigprocmask(SIG_BLOCK, &mask, &osig);
+       
+       r = pclose(pipefp);
+
+       sigprocmask(SIG_SETMASK, &osig, NULL);
+       if (r != 0) {
+               g_warning(_("external command `%s' failed with code `%i'\n"), command, r);
+               return -1;
+       }
 
        return 0;
 }