/*
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2005 Hiroyuki Yamamoto
+ * Copyright (C) 1999-2006 Hiroyuki Yamamoto and the Sylpheed-Claws team
*
* 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
#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"
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),
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);
gchar buf[BUFFSIZE];
gint ret = 0;
gboolean was_inited = FALSE;
+ MsgInfo *tmp_msginfo = NULL;
+ MsgFlags flags = {0, 0};
+ long fp_pos = 0;
+ gchar spec_from[BUFFSIZE];
g_return_val_if_fail(ac_prefs != NULL, -1);
g_return_val_if_fail(ac_prefs->address != NULL, -1);
g_return_val_if_fail(to_list != NULL, -1);
g_return_val_if_fail(fp != NULL, -1);
+ /* get the From address used, not necessarily the ac_prefs',
+ * because it's editable. */
+
+ fp_pos = ftell(fp);
+ tmp_msginfo = procheader_parse_stream(fp, flags, FALSE, FALSE);
+ fseek(fp, fp_pos, SEEK_SET);
+
+ if (tmp_msginfo && tmp_msginfo->from) {
+ strncpy2(spec_from, tmp_msginfo->from, BUFFSIZE-1);
+ extract_address(spec_from);
+ } else {
+ strncpy2(spec_from, ac_prefs->address, BUFFSIZE-1);
+ }
+ if (tmp_msginfo) {
+ procmsg_msginfo_free(tmp_msginfo);
+ }
+
if (!ac_prefs->session) {
/* we can't reuse a previously initialised session */
session = smtp_session_new();
smtp_session = SMTP_SESSION(session);
- smtp_session->hostname =
- ac_prefs->set_domain ? g_strdup(ac_prefs->domain) : NULL;
+ if (ac_prefs->set_domain && ac_prefs->domain && strlen(ac_prefs->domain)) {
+ smtp_session->hostname = g_strdup(ac_prefs->domain);
+ } else {
+ smtp_session->hostname = NULL;
+ }
if (ac_prefs->use_smtp_auth) {
smtp_session->forced_auth_type = ac_prefs->smtp_auth_type;
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);
}
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);
}
"Do you want to continue connecting to this "
"server? The communication would not be "
"secure."),
- _("Con_tinue connecting"),
- GTK_STOCK_CANCEL, NULL,
- FALSE, NULL, ALERT_WARNING,
- G_ALERTALTERNATE) != G_ALERTDEFAULT)
+ GTK_STOCK_CANCEL, _("Con_tinue connecting"),
+ NULL, FALSE, NULL, ALERT_WARNING,
+ G_ALERTDEFAULT) != G_ALERTALTERNATE) {
+ session_destroy(session);
return -1;
+ }
}
port = ac_prefs->set_smtpport ? ac_prefs->smtpport : SMTP_PORT;
#endif
(session, send_send_data_progressive, dialog);
session_set_send_data_notify(session, send_send_data_finished, dialog);
- ac_prefs->session = SMTP_SESSION(session);
} else {
/* everything is ready to start at MAIL FROM:, just
* reinit useful variables.
*/
session = SESSION(ac_prefs->session);
+ ac_prefs->session = NULL;
smtp_session = SMTP_SESSION(session);
smtp_session->state = SMTP_HELO;
dialog = (SendProgressDialog *)smtp_session->dialog;
}
/* This has to be initialised for every mail sent */
- smtp_session->from = g_strdup(ac_prefs->address);
+ smtp_session->from = g_strdup(spec_from);
smtp_session->to_list = to_list;
smtp_session->cur_to = to_list;
- smtp_session->send_data = get_outgoing_rfc2822_str(fp);
- smtp_session->send_data_len = strlen(smtp_session->send_data);
+ smtp_session->send_data = (guchar *)get_outgoing_rfc2822_str(fp);
+ smtp_session->send_data_len = strlen((gchar *)smtp_session->send_data);
+ session_set_timeout(session,
+ prefs_common.io_timeout_secs * 1000);
/* connect if necessary */
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;
}
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) {
g_free(smtp_session->send_data);
g_free(smtp_session->error_msg);
}
+ if (keep_session && ret == 0 && ac_prefs->session == NULL)
+ ac_prefs->session = SMTP_SESSION(session);
+
statusbar_pop_all();
statusbar_verbosity_set(FALSE);
cur_len, total_len);
progress_dialog_set_label(dialog->dialog, buf);
progress_dialog_set_fraction
- (dialog->dialog, (gfloat)cur_len / (gfloat)total_len);
+ (dialog->dialog, (total_len == 0) ? 0 : (gfloat)cur_len / (gfloat)total_len);
return 0;
}
if (log_msg)
log_warning("%s\n", log_msg);
if (err_msg) {
- alertpanel_error_log("%s", err_msg);
+ log_error("%s", err_msg);
g_free(err_msg);
}
}