2005-12-21 [colin] 1.9.100cvs101
[claws.git] / src / send_message.c
index 969ffbc7d84e2b16eaca23b0a6236c4387073462..0e0ef04f34562c588b47317544229eea7631ade5 100644 (file)
@@ -14,7 +14,7 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
 #ifdef HAVE_CONFIG_H
@@ -32,7 +32,9 @@
 #include <string.h>
 #include <signal.h>
 #include <sys/types.h>
+#ifndef G_OS_WIN32
 #include <sys/wait.h>
+#endif
 
 #include "send_message.h"
 #include "session.h"
@@ -96,15 +98,18 @@ gint send_message(const gchar *file, PrefsAccount *ac_prefs, GSList *to_list)
                return -1;
        }
 
+       inc_lock();
        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);
+               inc_unlock();
                return val;
        } else {
                val = send_message_smtp(ac_prefs, to_list, fp);
                
                fclose(fp);
+               inc_unlock();
                return val;
        }
 }
@@ -134,7 +139,12 @@ gint send_message_local(const gchar *command, FILE *fp)
        argv = strsplit_with_quote(command, " ", 0);
 
        if (g_spawn_async_with_pipes(NULL, argv, NULL,
-                                    G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL,
+#ifdef G_OS_WIN32
+                                     0,
+#else
+                                    G_SPAWN_DO_NOT_REAP_CHILD,
+#endif
+                                     NULL, NULL,
                                     &pid, &child_stdin, NULL, NULL,
                                     NULL) == FALSE) {
                g_snprintf(buf, sizeof(buf),
@@ -163,9 +173,11 @@ gint send_message_local(const gchar *command, FILE *fp)
 
        fd_close(child_stdin);
 
+#ifndef G_OS_WIN32
        waitpid(pid, &status, 0);
        if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
                err = TRUE;
+#endif
 
        g_spawn_close_pid(pid);
 
@@ -220,8 +232,10 @@ gint send_message_smtp_full(PrefsAccount *ac_prefs, GSList *to_list, FILE *fp, g
                                                input_dialog_query_password
                                                        (ac_prefs->smtp_server,
                                                         smtp_session->user);
-                                       if (!smtp_session->pass)
-                                               smtp_session->pass = g_strdup("");
+                                       if (!smtp_session->pass) {
+                                               session_destroy(session);
+                                               return -1;
+                                       }
                                        ac_prefs->tmp_smtp_pass =
                                                g_strdup(smtp_session->pass);
                                }
@@ -237,8 +251,10 @@ gint send_message_smtp_full(PrefsAccount *ac_prefs, GSList *to_list, FILE *fp, g
                                                input_dialog_query_password
                                                        (ac_prefs->smtp_server,
                                                         smtp_session->user);
-                                       if (!smtp_session->pass)
-                                               smtp_session->pass = g_strdup("");
+                                       if (!smtp_session->pass) {
+                                               session_destroy(session);
+                                               return -1;
+                                       }
                                        ac_prefs->tmp_pass =
                                                g_strdup(smtp_session->pass);
                                }
@@ -263,11 +279,13 @@ gint send_message_smtp_full(PrefsAccount *ac_prefs, GSList *to_list, FILE *fp, g
                                  "Do you want to continue connecting to this "
                                  "server? The communication would not be "
                                  "secure."),
-                                 _("Continue connecting"), 
+                                 _("Con_tinue connecting"), 
                                  GTK_STOCK_CANCEL, NULL,
                                  FALSE, NULL, ALERT_WARNING,
-                                 G_ALERTALTERNATE) != G_ALERTDEFAULT)
+                                 G_ALERTALTERNATE) != G_ALERTDEFAULT) {
+                               session_destroy(session);
                                return -1;
+                       }
                }
                port = ac_prefs->set_smtpport ? ac_prefs->smtpport : SMTP_PORT;
        #endif
@@ -324,6 +342,7 @@ gint send_message_smtp_full(PrefsAccount *ac_prefs, GSList *to_list, FILE *fp, g
        if (!was_inited && session_connect(session, ac_prefs->smtp_server, port) < 0) {
                session_destroy(session);
                send_progress_dialog_destroy(dialog);
+               ac_prefs->session = NULL;
                return -1;
        }
 
@@ -342,6 +361,9 @@ gint send_message_smtp_full(PrefsAccount *ac_prefs, GSList *to_list, FILE *fp, g
                if (ac_prefs->smtp_userid && ac_prefs->tmp_smtp_pass) {
                        g_free(ac_prefs->tmp_smtp_pass);
                        ac_prefs->tmp_smtp_pass = NULL;
+               } else if (ac_prefs->tmp_pass) {
+                       g_free(ac_prefs->tmp_pass);
+                       ac_prefs->tmp_pass = NULL;
                }
                ret = -1;
        } else if (SMTP_SESSION(session)->state == SMTP_MAIL_SENT_OK) {
@@ -374,7 +396,7 @@ gint send_message_smtp_full(PrefsAccount *ac_prefs, GSList *to_list, FILE *fp, g
        if (!keep_session || ret != 0) {
                if (session_is_connected(session))
                        smtp_quit(smtp_session);
-               while (session_is_connected(session))
+               while (session_is_connected(session) && !dialog->cancelled)
                        gtk_main_iteration();
                session_destroy(session);
                ac_prefs->session = NULL;