root / src / send_message.c @ 206
History | View | Annotate | Download (15.4 kB)
| 1 | 1 | hiro | /*
|
|---|---|---|---|
| 2 | 1 | hiro | * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client |
| 3 | 1 | hiro | * Copyright (C) 1999-2003 Hiroyuki Yamamoto |
| 4 | 1 | hiro | * |
| 5 | 1 | hiro | * This program is free software; you can redistribute it and/or modify |
| 6 | 1 | hiro | * it under the terms of the GNU General Public License as published by |
| 7 | 1 | hiro | * the Free Software Foundation; either version 2 of the License, or |
| 8 | 1 | hiro | * (at your option) any later version. |
| 9 | 1 | hiro | * |
| 10 | 1 | hiro | * This program is distributed in the hope that it will be useful, |
| 11 | 1 | hiro | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | 1 | hiro | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | 1 | hiro | * GNU General Public License for more details. |
| 14 | 1 | hiro | * |
| 15 | 1 | hiro | * You should have received a copy of the GNU General Public License |
| 16 | 1 | hiro | * along with this program; if not, write to the Free Software |
| 17 | 1 | hiro | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 18 | 1 | hiro | */ |
| 19 | 1 | hiro | |
| 20 | 1 | hiro | #ifdef HAVE_CONFIG_H
|
| 21 | 1 | hiro | # include "config.h" |
| 22 | 1 | hiro | #endif
|
| 23 | 1 | hiro | |
| 24 | 1 | hiro | #include "defs.h" |
| 25 | 1 | hiro | |
| 26 | 1 | hiro | #include <glib.h> |
| 27 | 92 | hiro | #include <glib/gi18n.h> |
| 28 | 1 | hiro | #include <gtk/gtkmain.h> |
| 29 | 1 | hiro | #include <gtk/gtksignal.h> |
| 30 | 1 | hiro | #include <gtk/gtkwindow.h> |
| 31 | 1 | hiro | #include <gtk/gtkclist.h> |
| 32 | 1 | hiro | #include <stdio.h> |
| 33 | 1 | hiro | #include <string.h> |
| 34 | 1 | hiro | |
| 35 | 1 | hiro | #include "send_message.h" |
| 36 | 1 | hiro | #include "session.h" |
| 37 | 1 | hiro | #include "ssl.h" |
| 38 | 1 | hiro | #include "smtp.h" |
| 39 | 1 | hiro | #include "news.h" |
| 40 | 1 | hiro | #include "prefs_common.h" |
| 41 | 1 | hiro | #include "prefs_account.h" |
| 42 | 1 | hiro | #include "procheader.h" |
| 43 | 1 | hiro | #include "account.h" |
| 44 | 1 | hiro | #include "progressdialog.h" |
| 45 | 1 | hiro | #include "statusbar.h" |
| 46 | 1 | hiro | #include "inputdialog.h" |
| 47 | 1 | hiro | #include "alertpanel.h" |
| 48 | 1 | hiro | #include "manage_window.h" |
| 49 | 1 | hiro | #include "utils.h" |
| 50 | 1 | hiro | |
| 51 | 1 | hiro | #define SMTP_PORT 25 |
| 52 | 1 | hiro | #if USE_SSL
|
| 53 | 1 | hiro | #define SSMTP_PORT 465 |
| 54 | 1 | hiro | #endif
|
| 55 | 1 | hiro | |
| 56 | 1 | hiro | typedef struct _SendProgressDialog SendProgressDialog; |
| 57 | 1 | hiro | |
| 58 | 1 | hiro | struct _SendProgressDialog
|
| 59 | 1 | hiro | {
|
| 60 | 1 | hiro | ProgressDialog *dialog; |
| 61 | 1 | hiro | Session *session; |
| 62 | 1 | hiro | gboolean cancelled; |
| 63 | 1 | hiro | }; |
| 64 | 1 | hiro | |
| 65 | 1 | hiro | static gint send_message_local (const gchar *command, |
| 66 | 1 | hiro | FILE *fp); |
| 67 | 1 | hiro | static gint send_message_smtp (PrefsAccount *ac_prefs,
|
| 68 | 1 | hiro | GSList *to_list, |
| 69 | 1 | hiro | FILE *fp); |
| 70 | 1 | hiro | |
| 71 | 1 | hiro | static gint send_recv_message (Session *session,
|
| 72 | 1 | hiro | const gchar *msg,
|
| 73 | 1 | hiro | gpointer data); |
| 74 | 1 | hiro | static gint send_send_data_progressive (Session *session,
|
| 75 | 1 | hiro | guint cur_len, |
| 76 | 1 | hiro | guint total_len, |
| 77 | 1 | hiro | gpointer data); |
| 78 | 1 | hiro | static gint send_send_data_finished (Session *session,
|
| 79 | 1 | hiro | guint len, |
| 80 | 1 | hiro | gpointer data); |
| 81 | 1 | hiro | |
| 82 | 1 | hiro | static SendProgressDialog *send_progress_dialog_create(void); |
| 83 | 1 | hiro | static void send_progress_dialog_destroy(SendProgressDialog *dialog); |
| 84 | 1 | hiro | |
| 85 | 1 | hiro | static void send_cancel_button_cb (GtkWidget *widget, |
| 86 | 1 | hiro | gpointer data); |
| 87 | 1 | hiro | |
| 88 | 1 | hiro | static void send_put_error (Session *session); |
| 89 | 1 | hiro | |
| 90 | 1 | hiro | |
| 91 | 1 | hiro | gint send_message(const gchar *file, PrefsAccount *ac_prefs, GSList *to_list)
|
| 92 | 1 | hiro | {
|
| 93 | 1 | hiro | FILE *fp; |
| 94 | 1 | hiro | gint val; |
| 95 | 1 | hiro | |
| 96 | 1 | hiro | g_return_val_if_fail(file != NULL, -1); |
| 97 | 1 | hiro | g_return_val_if_fail(ac_prefs != NULL, -1); |
| 98 | 1 | hiro | g_return_val_if_fail(to_list != NULL, -1); |
| 99 | 1 | hiro | |
| 100 | 1 | hiro | if ((fp = fopen(file, "rb")) == NULL) { |
| 101 | 1 | hiro | FILE_OP_ERROR(file, "fopen");
|
| 102 | 1 | hiro | return -1; |
| 103 | 1 | hiro | } |
| 104 | 1 | hiro | |
| 105 | 1 | hiro | if (prefs_common.use_extsend && prefs_common.extsend_cmd) {
|
| 106 | 1 | hiro | val = send_message_local(prefs_common.extsend_cmd, fp); |
| 107 | 1 | hiro | fclose(fp); |
| 108 | 1 | hiro | return val;
|
| 109 | 1 | hiro | } |
| 110 | 1 | hiro | |
| 111 | 1 | hiro | val = send_message_smtp(ac_prefs, to_list, fp); |
| 112 | 1 | hiro | |
| 113 | 1 | hiro | fclose(fp); |
| 114 | 1 | hiro | return val;
|
| 115 | 1 | hiro | } |
| 116 | 1 | hiro | |
| 117 | 1 | hiro | enum
|
| 118 | 1 | hiro | {
|
| 119 | 1 | hiro | Q_SENDER = 0,
|
| 120 | 1 | hiro | Q_SMTPSERVER = 1,
|
| 121 | 1 | hiro | Q_RECIPIENTS = 2,
|
| 122 | 1 | hiro | Q_ACCOUNT_ID = 3
|
| 123 | 1 | hiro | }; |
| 124 | 1 | hiro | |
| 125 | 1 | hiro | QueueInfo *send_get_queue_info(const gchar *file)
|
| 126 | 1 | hiro | {
|
| 127 | 1 | hiro | static HeaderEntry qentry[] = {{"S:", NULL, FALSE}, |
| 128 | 1 | hiro | {"SSV:", NULL, FALSE},
|
| 129 | 1 | hiro | {"R:", NULL, FALSE},
|
| 130 | 1 | hiro | {"AID:", NULL, FALSE},
|
| 131 | 1 | hiro | {NULL, NULL, FALSE}};
|
| 132 | 1 | hiro | FILE *fp; |
| 133 | 1 | hiro | gchar buf[BUFFSIZE]; |
| 134 | 1 | hiro | gint hnum; |
| 135 | 1 | hiro | QueueInfo *qinfo; |
| 136 | 1 | hiro | |
| 137 | 1 | hiro | g_return_val_if_fail(file != NULL, NULL); |
| 138 | 1 | hiro | |
| 139 | 1 | hiro | if ((fp = fopen(file, "rb")) == NULL) { |
| 140 | 1 | hiro | FILE_OP_ERROR(file, "fopen");
|
| 141 | 1 | hiro | return NULL; |
| 142 | 1 | hiro | } |
| 143 | 1 | hiro | |
| 144 | 1 | hiro | qinfo = g_new0(QueueInfo, 1);
|
| 145 | 1 | hiro | |
| 146 | 1 | hiro | while ((hnum = procheader_get_one_field(buf, sizeof(buf), fp, qentry)) |
| 147 | 1 | hiro | != -1) {
|
| 148 | 1 | hiro | gchar *p; |
| 149 | 1 | hiro | |
| 150 | 1 | hiro | p = buf + strlen(qentry[hnum].name); |
| 151 | 1 | hiro | |
| 152 | 1 | hiro | switch (hnum) {
|
| 153 | 1 | hiro | case Q_SENDER:
|
| 154 | 1 | hiro | if (!qinfo->from)
|
| 155 | 1 | hiro | qinfo->from = g_strdup(p); |
| 156 | 1 | hiro | break;
|
| 157 | 1 | hiro | case Q_SMTPSERVER:
|
| 158 | 1 | hiro | if (!qinfo->server)
|
| 159 | 1 | hiro | qinfo->server = g_strdup(p); |
| 160 | 1 | hiro | break;
|
| 161 | 1 | hiro | case Q_RECIPIENTS:
|
| 162 | 1 | hiro | qinfo->to_list = |
| 163 | 1 | hiro | address_list_append(qinfo->to_list, p); |
| 164 | 1 | hiro | break;
|
| 165 | 1 | hiro | case Q_ACCOUNT_ID:
|
| 166 | 1 | hiro | qinfo->ac = account_find_from_id(atoi(p)); |
| 167 | 1 | hiro | break;
|
| 168 | 1 | hiro | default:
|
| 169 | 1 | hiro | break;
|
| 170 | 1 | hiro | } |
| 171 | 1 | hiro | } |
| 172 | 1 | hiro | |
| 173 | 1 | hiro | qinfo->fp = fp; |
| 174 | 1 | hiro | |
| 175 | 1 | hiro | if (((!qinfo->ac || (qinfo->ac && qinfo->ac->protocol != A_NNTP)) &&
|
| 176 | 1 | hiro | !qinfo->to_list) || !qinfo->from) {
|
| 177 | 1 | hiro | g_warning(_("Queued message header is broken.\n"));
|
| 178 | 1 | hiro | send_queue_info_free(qinfo); |
| 179 | 1 | hiro | return NULL; |
| 180 | 1 | hiro | } |
| 181 | 1 | hiro | |
| 182 | 1 | hiro | if (!qinfo->ac) {
|
| 183 | 1 | hiro | qinfo->ac = account_find_from_smtp_server(qinfo->from, |
| 184 | 1 | hiro | qinfo->server); |
| 185 | 1 | hiro | if (!qinfo->ac) {
|
| 186 | 1 | hiro | g_warning("Account not found. "
|
| 187 | 1 | hiro | "Using current account...\n");
|
| 188 | 1 | hiro | qinfo->ac = cur_account; |
| 189 | 1 | hiro | } |
| 190 | 1 | hiro | } |
| 191 | 1 | hiro | |
| 192 | 1 | hiro | return qinfo;
|
| 193 | 1 | hiro | } |
| 194 | 1 | hiro | |
| 195 | 1 | hiro | void send_queue_info_free(QueueInfo *qinfo)
|
| 196 | 1 | hiro | {
|
| 197 | 1 | hiro | if (qinfo == NULL) return; |
| 198 | 1 | hiro | |
| 199 | 1 | hiro | slist_free_strings(qinfo->to_list); |
| 200 | 1 | hiro | g_slist_free(qinfo->to_list); |
| 201 | 1 | hiro | g_free(qinfo->from); |
| 202 | 1 | hiro | g_free(qinfo->server); |
| 203 | 1 | hiro | if (qinfo->fp)
|
| 204 | 1 | hiro | fclose(qinfo->fp); |
| 205 | 1 | hiro | g_free(qinfo); |
| 206 | 1 | hiro | } |
| 207 | 1 | hiro | |
| 208 | 1 | hiro | gint send_message_queue(QueueInfo *qinfo) |
| 209 | 1 | hiro | {
|
| 210 | 1 | hiro | gint val = 0;
|
| 211 | 1 | hiro | glong fpos; |
| 212 | 1 | hiro | PrefsAccount *mailac = NULL, *newsac = NULL; |
| 213 | 1 | hiro | |
| 214 | 1 | hiro | g_return_val_if_fail(qinfo != NULL, -1); |
| 215 | 1 | hiro | |
| 216 | 1 | hiro | if (prefs_common.use_extsend && prefs_common.extsend_cmd) {
|
| 217 | 1 | hiro | val = send_message_local(prefs_common.extsend_cmd, qinfo->fp); |
| 218 | 1 | hiro | } else {
|
| 219 | 1 | hiro | if (qinfo->ac && qinfo->ac->protocol == A_NNTP) {
|
| 220 | 1 | hiro | newsac = qinfo->ac; |
| 221 | 1 | hiro | |
| 222 | 1 | hiro | /* search mail account */
|
| 223 | 1 | hiro | mailac = account_find_from_address(qinfo->from); |
| 224 | 1 | hiro | if (!mailac) {
|
| 225 | 1 | hiro | if (cur_account &&
|
| 226 | 1 | hiro | cur_account->protocol != A_NNTP) |
| 227 | 1 | hiro | mailac = cur_account; |
| 228 | 1 | hiro | else {
|
| 229 | 1 | hiro | mailac = account_get_default(); |
| 230 | 1 | hiro | if (mailac->protocol == A_NNTP)
|
| 231 | 1 | hiro | mailac = NULL;
|
| 232 | 1 | hiro | } |
| 233 | 1 | hiro | } |
| 234 | 1 | hiro | } else
|
| 235 | 1 | hiro | mailac = qinfo->ac; |
| 236 | 1 | hiro | |
| 237 | 1 | hiro | fpos = ftell(qinfo->fp); |
| 238 | 1 | hiro | if (qinfo->to_list) {
|
| 239 | 1 | hiro | if (mailac)
|
| 240 | 1 | hiro | val = send_message_smtp(mailac, qinfo->to_list, |
| 241 | 1 | hiro | qinfo->fp); |
| 242 | 1 | hiro | else {
|
| 243 | 1 | hiro | PrefsAccount tmp_ac; |
| 244 | 1 | hiro | |
| 245 | 1 | hiro | g_warning("Account not found.\n");
|
| 246 | 1 | hiro | |
| 247 | 1 | hiro | memset(&tmp_ac, 0, sizeof(PrefsAccount)); |
| 248 | 1 | hiro | tmp_ac.address = qinfo->from; |
| 249 | 1 | hiro | tmp_ac.smtp_server = qinfo->server; |
| 250 | 1 | hiro | tmp_ac.smtpport = SMTP_PORT; |
| 251 | 1 | hiro | val = send_message_smtp(&tmp_ac, qinfo->to_list, |
| 252 | 1 | hiro | qinfo->fp); |
| 253 | 1 | hiro | } |
| 254 | 1 | hiro | } |
| 255 | 1 | hiro | |
| 256 | 1 | hiro | if (val == 0 && newsac) { |
| 257 | 1 | hiro | fseek(qinfo->fp, fpos, SEEK_SET); |
| 258 | 1 | hiro | val = news_post_stream(FOLDER(newsac->folder), |
| 259 | 1 | hiro | qinfo->fp); |
| 260 | 1 | hiro | if (val < 0) |
| 261 | 1 | hiro | alertpanel_error(_("Error occurred while posting the message to %s ."),
|
| 262 | 1 | hiro | newsac->nntp_server); |
| 263 | 1 | hiro | } |
| 264 | 1 | hiro | } |
| 265 | 1 | hiro | |
| 266 | 1 | hiro | return val;
|
| 267 | 1 | hiro | } |
| 268 | 1 | hiro | |
| 269 | 1 | hiro | static gint send_message_local(const gchar *command, FILE *fp) |
| 270 | 1 | hiro | {
|
| 271 | 1 | hiro | FILE *pipefp; |
| 272 | 1 | hiro | gchar buf[BUFFSIZE]; |
| 273 | 1 | hiro | |
| 274 | 1 | hiro | g_return_val_if_fail(command != NULL, -1); |
| 275 | 1 | hiro | g_return_val_if_fail(fp != NULL, -1); |
| 276 | 1 | hiro | |
| 277 | 1 | hiro | pipefp = popen(command, "w");
|
| 278 | 1 | hiro | if (!pipefp) {
|
| 279 | 1 | hiro | g_warning("Can't execute external command: %s\n", command);
|
| 280 | 1 | hiro | return -1; |
| 281 | 1 | hiro | } |
| 282 | 1 | hiro | |
| 283 | 1 | hiro | while (fgets(buf, sizeof(buf), fp) != NULL) { |
| 284 | 1 | hiro | strretchomp(buf); |
| 285 | 1 | hiro | if (buf[0] == '.' && buf[1] == '\0') |
| 286 | 1 | hiro | fputc('.', pipefp);
|
| 287 | 1 | hiro | fputs(buf, pipefp); |
| 288 | 1 | hiro | fputc('\n', pipefp);
|
| 289 | 1 | hiro | } |
| 290 | 1 | hiro | |
| 291 | 1 | hiro | pclose(pipefp); |
| 292 | 1 | hiro | |
| 293 | 1 | hiro | return 0; |
| 294 | 1 | hiro | } |
| 295 | 1 | hiro | |
| 296 | 1 | hiro | static gint send_message_smtp(PrefsAccount *ac_prefs, GSList *to_list, FILE *fp)
|
| 297 | 1 | hiro | {
|
| 298 | 1 | hiro | Session *session; |
| 299 | 1 | hiro | SMTPSession *smtp_session; |
| 300 | 1 | hiro | gushort port; |
| 301 | 1 | hiro | SendProgressDialog *dialog; |
| 302 | 1 | hiro | GtkCList *clist; |
| 303 | 1 | hiro | const gchar *text[3]; |
| 304 | 1 | hiro | gchar buf[BUFFSIZE]; |
| 305 | 1 | hiro | gint ret = 0;
|
| 306 | 1 | hiro | |
| 307 | 1 | hiro | g_return_val_if_fail(ac_prefs != NULL, -1); |
| 308 | 1 | hiro | g_return_val_if_fail(ac_prefs->address != NULL, -1); |
| 309 | 1 | hiro | g_return_val_if_fail(ac_prefs->smtp_server != NULL, -1); |
| 310 | 1 | hiro | g_return_val_if_fail(to_list != NULL, -1); |
| 311 | 1 | hiro | g_return_val_if_fail(fp != NULL, -1); |
| 312 | 1 | hiro | |
| 313 | 1 | hiro | session = smtp_session_new(); |
| 314 | 1 | hiro | smtp_session = SMTP_SESSION(session); |
| 315 | 1 | hiro | |
| 316 | 1 | hiro | smtp_session->hostname = |
| 317 | 1 | hiro | ac_prefs->set_domain ? g_strdup(ac_prefs->domain) : NULL;
|
| 318 | 1 | hiro | |
| 319 | 1 | hiro | if (ac_prefs->use_smtp_auth) {
|
| 320 | 1 | hiro | smtp_session->forced_auth_type = ac_prefs->smtp_auth_type; |
| 321 | 1 | hiro | |
| 322 | 1 | hiro | if (ac_prefs->smtp_userid) {
|
| 323 | 1 | hiro | smtp_session->user = g_strdup(ac_prefs->smtp_userid); |
| 324 | 1 | hiro | if (ac_prefs->smtp_passwd)
|
| 325 | 1 | hiro | smtp_session->pass = |
| 326 | 1 | hiro | g_strdup(ac_prefs->smtp_passwd); |
| 327 | 1 | hiro | else if (ac_prefs->tmp_smtp_pass) |
| 328 | 1 | hiro | smtp_session->pass = |
| 329 | 1 | hiro | g_strdup(ac_prefs->tmp_smtp_pass); |
| 330 | 1 | hiro | else {
|
| 331 | 1 | hiro | smtp_session->pass = |
| 332 | 1 | hiro | input_dialog_query_password |
| 333 | 1 | hiro | (ac_prefs->smtp_server, |
| 334 | 1 | hiro | smtp_session->user); |
| 335 | 1 | hiro | if (!smtp_session->pass)
|
| 336 | 1 | hiro | smtp_session->pass = g_strdup("");
|
| 337 | 1 | hiro | ac_prefs->tmp_smtp_pass = |
| 338 | 1 | hiro | g_strdup(smtp_session->pass); |
| 339 | 1 | hiro | } |
| 340 | 1 | hiro | } else {
|
| 341 | 1 | hiro | smtp_session->user = g_strdup(ac_prefs->userid); |
| 342 | 1 | hiro | if (ac_prefs->passwd)
|
| 343 | 1 | hiro | smtp_session->pass = g_strdup(ac_prefs->passwd); |
| 344 | 1 | hiro | else if (ac_prefs->tmp_pass) |
| 345 | 1 | hiro | smtp_session->pass = |
| 346 | 1 | hiro | g_strdup(ac_prefs->tmp_pass); |
| 347 | 1 | hiro | else {
|
| 348 | 1 | hiro | smtp_session->pass = |
| 349 | 1 | hiro | input_dialog_query_password |
| 350 | 1 | hiro | (ac_prefs->smtp_server, |
| 351 | 1 | hiro | smtp_session->user); |
| 352 | 1 | hiro | if (!smtp_session->pass)
|
| 353 | 1 | hiro | smtp_session->pass = g_strdup("");
|
| 354 | 1 | hiro | ac_prefs->tmp_pass = |
| 355 | 1 | hiro | g_strdup(smtp_session->pass); |
| 356 | 1 | hiro | } |
| 357 | 1 | hiro | } |
| 358 | 1 | hiro | } else {
|
| 359 | 1 | hiro | smtp_session->user = NULL;
|
| 360 | 1 | hiro | smtp_session->pass = NULL;
|
| 361 | 1 | hiro | } |
| 362 | 1 | hiro | |
| 363 | 1 | hiro | smtp_session->from = g_strdup(ac_prefs->address); |
| 364 | 1 | hiro | smtp_session->to_list = to_list; |
| 365 | 1 | hiro | smtp_session->cur_to = to_list; |
| 366 | 1 | hiro | smtp_session->send_data = get_outgoing_rfc2822_str(fp); |
| 367 | 1 | hiro | smtp_session->send_data_len = strlen(smtp_session->send_data); |
| 368 | 1 | hiro | |
| 369 | 1 | hiro | #if USE_SSL
|
| 370 | 1 | hiro | port = ac_prefs->set_smtpport ? ac_prefs->smtpport : |
| 371 | 1 | hiro | ac_prefs->ssl_smtp == SSL_TUNNEL ? SSMTP_PORT : SMTP_PORT; |
| 372 | 1 | hiro | session->ssl_type = ac_prefs->ssl_smtp; |
| 373 | 1 | hiro | if (ac_prefs->ssl_smtp != SSL_NONE)
|
| 374 | 1 | hiro | session->nonblocking = ac_prefs->use_nonblocking_ssl; |
| 375 | 1 | hiro | #else
|
| 376 | 1 | hiro | port = ac_prefs->set_smtpport ? ac_prefs->smtpport : SMTP_PORT; |
| 377 | 1 | hiro | #endif
|
| 378 | 1 | hiro | |
| 379 | 1 | hiro | dialog = send_progress_dialog_create(); |
| 380 | 1 | hiro | dialog->session = session; |
| 381 | 1 | hiro | |
| 382 | 1 | hiro | text[0] = NULL; |
| 383 | 1 | hiro | text[1] = ac_prefs->smtp_server;
|
| 384 | 1 | hiro | text[2] = _("Connecting"); |
| 385 | 1 | hiro | clist = GTK_CLIST(dialog->dialog->clist); |
| 386 | 1 | hiro | gtk_clist_append(clist, (gchar **)text); |
| 387 | 1 | hiro | |
| 388 | 1 | hiro | g_snprintf(buf, sizeof(buf), _("Connecting to SMTP server: %s ..."), |
| 389 | 1 | hiro | ac_prefs->smtp_server); |
| 390 | 1 | hiro | progress_dialog_set_label(dialog->dialog, buf); |
| 391 | 1 | hiro | log_message("%s\n", buf);
|
| 392 | 1 | hiro | |
| 393 | 1 | hiro | session_set_recv_message_notify(session, send_recv_message, dialog); |
| 394 | 1 | hiro | session_set_send_data_progressive_notify |
| 395 | 1 | hiro | (session, send_send_data_progressive, dialog); |
| 396 | 1 | hiro | session_set_send_data_notify(session, send_send_data_finished, dialog); |
| 397 | 1 | hiro | |
| 398 | 1 | hiro | if (session_connect(session, ac_prefs->smtp_server, port) < 0) { |
| 399 | 1 | hiro | session_destroy(session); |
| 400 | 1 | hiro | send_progress_dialog_destroy(dialog); |
| 401 | 1 | hiro | return -1; |
| 402 | 1 | hiro | } |
| 403 | 1 | hiro | |
| 404 | 1 | hiro | debug_print("send_message_smtp(): begin event loop\n");
|
| 405 | 1 | hiro | |
| 406 | 1 | hiro | while (session_is_connected(session) && dialog->cancelled == FALSE)
|
| 407 | 1 | hiro | gtk_main_iteration(); |
| 408 | 1 | hiro | |
| 409 | 1 | hiro | if (SMTP_SESSION(session)->error_val == SM_AUTHFAIL) {
|
| 410 | 1 | hiro | if (ac_prefs->smtp_userid && ac_prefs->tmp_smtp_pass) {
|
| 411 | 1 | hiro | g_free(ac_prefs->tmp_smtp_pass); |
| 412 | 1 | hiro | ac_prefs->tmp_smtp_pass = NULL;
|
| 413 | 1 | hiro | } |
| 414 | 1 | hiro | ret = -1;
|
| 415 | 201 | hiro | } else if (session->state == SESSION_EOF && |
| 416 | 201 | hiro | SMTP_SESSION(session)->state == SMTP_QUIT) {
|
| 417 | 201 | hiro | /* consider EOF right after QUIT successful */
|
| 418 | 201 | hiro | log_warning("%s\n", _("Connection closed by the remote host.")); |
| 419 | 201 | hiro | ret = 0;
|
| 420 | 1 | hiro | } else if (session->state == SESSION_ERROR || |
| 421 | 1 | hiro | session->state == SESSION_EOF || |
| 422 | 1 | hiro | session->state == SESSION_TIMEOUT || |
| 423 | 1 | hiro | SMTP_SESSION(session)->state == SMTP_ERROR || |
| 424 | 1 | hiro | SMTP_SESSION(session)->error_val != SM_OK) |
| 425 | 1 | hiro | ret = -1;
|
| 426 | 1 | hiro | else if (dialog->cancelled == TRUE) |
| 427 | 1 | hiro | ret = -1;
|
| 428 | 1 | hiro | |
| 429 | 1 | hiro | if (ret == -1) { |
| 430 | 1 | hiro | manage_window_focus_in(dialog->dialog->window, NULL, NULL); |
| 431 | 1 | hiro | send_put_error(session); |
| 432 | 1 | hiro | manage_window_focus_out(dialog->dialog->window, NULL, NULL); |
| 433 | 1 | hiro | } |
| 434 | 1 | hiro | |
| 435 | 1 | hiro | session_destroy(session); |
| 436 | 1 | hiro | send_progress_dialog_destroy(dialog); |
| 437 | 1 | hiro | |
| 438 | 1 | hiro | return ret;
|
| 439 | 1 | hiro | } |
| 440 | 1 | hiro | |
| 441 | 1 | hiro | static gint send_recv_message(Session *session, const gchar *msg, gpointer data) |
| 442 | 1 | hiro | {
|
| 443 | 1 | hiro | gchar buf[BUFFSIZE]; |
| 444 | 1 | hiro | SMTPSession *smtp_session = SMTP_SESSION(session); |
| 445 | 1 | hiro | SendProgressDialog *dialog = (SendProgressDialog *)data; |
| 446 | 1 | hiro | gchar *state_str = NULL;
|
| 447 | 1 | hiro | |
| 448 | 1 | hiro | g_return_val_if_fail(dialog != NULL, -1); |
| 449 | 1 | hiro | |
| 450 | 1 | hiro | switch (smtp_session->state) {
|
| 451 | 1 | hiro | case SMTP_READY:
|
| 452 | 1 | hiro | case SMTP_CONNECTED:
|
| 453 | 1 | hiro | return 0; |
| 454 | 1 | hiro | case SMTP_HELO:
|
| 455 | 1 | hiro | g_snprintf(buf, sizeof(buf), _("Sending HELO...")); |
| 456 | 1 | hiro | state_str = _("Authenticating");
|
| 457 | 1 | hiro | statusbar_print_all(_("Sending message..."));
|
| 458 | 1 | hiro | break;
|
| 459 | 1 | hiro | case SMTP_EHLO:
|
| 460 | 1 | hiro | g_snprintf(buf, sizeof(buf), _("Sending EHLO...")); |
| 461 | 1 | hiro | state_str = _("Authenticating");
|
| 462 | 1 | hiro | statusbar_print_all(_("Sending message..."));
|
| 463 | 1 | hiro | break;
|
| 464 | 1 | hiro | case SMTP_AUTH:
|
| 465 | 1 | hiro | g_snprintf(buf, sizeof(buf), _("Authenticating...")); |
| 466 | 1 | hiro | state_str = _("Authenticating");
|
| 467 | 1 | hiro | break;
|
| 468 | 1 | hiro | case SMTP_FROM:
|
| 469 | 1 | hiro | g_snprintf(buf, sizeof(buf), _("Sending MAIL FROM...")); |
| 470 | 1 | hiro | state_str = _("Sending");
|
| 471 | 1 | hiro | break;
|
| 472 | 1 | hiro | case SMTP_RCPT:
|
| 473 | 1 | hiro | g_snprintf(buf, sizeof(buf), _("Sending RCPT TO...")); |
| 474 | 1 | hiro | state_str = _("Sending");
|
| 475 | 1 | hiro | break;
|
| 476 | 1 | hiro | case SMTP_DATA:
|
| 477 | 1 | hiro | case SMTP_EOM:
|
| 478 | 1 | hiro | g_snprintf(buf, sizeof(buf), _("Sending DATA...")); |
| 479 | 1 | hiro | state_str = _("Sending");
|
| 480 | 1 | hiro | break;
|
| 481 | 1 | hiro | case SMTP_QUIT:
|
| 482 | 1 | hiro | g_snprintf(buf, sizeof(buf), _("Quitting...")); |
| 483 | 1 | hiro | state_str = _("Quitting");
|
| 484 | 1 | hiro | break;
|
| 485 | 1 | hiro | case SMTP_ERROR:
|
| 486 | 1 | hiro | g_warning("send: error: %s\n", msg);
|
| 487 | 1 | hiro | return 0; |
| 488 | 1 | hiro | default:
|
| 489 | 1 | hiro | return 0; |
| 490 | 1 | hiro | } |
| 491 | 1 | hiro | |
| 492 | 1 | hiro | progress_dialog_set_label(dialog->dialog, buf); |
| 493 | 1 | hiro | gtk_clist_set_text(GTK_CLIST(dialog->dialog->clist), 0, 2, state_str); |
| 494 | 1 | hiro | |
| 495 | 1 | hiro | return 0; |
| 496 | 1 | hiro | } |
| 497 | 1 | hiro | |
| 498 | 1 | hiro | static gint send_send_data_progressive(Session *session, guint cur_len,
|
| 499 | 1 | hiro | guint total_len, gpointer data) |
| 500 | 1 | hiro | {
|
| 501 | 1 | hiro | gchar buf[BUFFSIZE]; |
| 502 | 1 | hiro | SendProgressDialog *dialog = (SendProgressDialog *)data; |
| 503 | 1 | hiro | |
| 504 | 1 | hiro | g_return_val_if_fail(dialog != NULL, -1); |
| 505 | 1 | hiro | |
| 506 | 1 | hiro | if (SMTP_SESSION(session)->state != SMTP_SEND_DATA &&
|
| 507 | 1 | hiro | SMTP_SESSION(session)->state != SMTP_EOM) |
| 508 | 1 | hiro | return 0; |
| 509 | 1 | hiro | |
| 510 | 1 | hiro | g_snprintf(buf, sizeof(buf), _("Sending message (%d / %d bytes)"), |
| 511 | 1 | hiro | cur_len, total_len); |
| 512 | 1 | hiro | progress_dialog_set_label(dialog->dialog, buf); |
| 513 | 1 | hiro | progress_dialog_set_percentage |
| 514 | 1 | hiro | (dialog->dialog, (gfloat)cur_len / (gfloat)total_len); |
| 515 | 1 | hiro | |
| 516 | 1 | hiro | return 0; |
| 517 | 1 | hiro | } |
| 518 | 1 | hiro | |
| 519 | 1 | hiro | static gint send_send_data_finished(Session *session, guint len, gpointer data)
|
| 520 | 1 | hiro | {
|
| 521 | 1 | hiro | SendProgressDialog *dialog = (SendProgressDialog *)data; |
| 522 | 1 | hiro | |
| 523 | 1 | hiro | g_return_val_if_fail(dialog != NULL, -1); |
| 524 | 1 | hiro | |
| 525 | 1 | hiro | send_send_data_progressive(session, len, len, dialog); |
| 526 | 1 | hiro | return 0; |
| 527 | 1 | hiro | } |
| 528 | 1 | hiro | |
| 529 | 1 | hiro | static SendProgressDialog *send_progress_dialog_create(void) |
| 530 | 1 | hiro | {
|
| 531 | 1 | hiro | SendProgressDialog *dialog; |
| 532 | 1 | hiro | ProgressDialog *progress; |
| 533 | 1 | hiro | |
| 534 | 1 | hiro | dialog = g_new0(SendProgressDialog, 1);
|
| 535 | 1 | hiro | |
| 536 | 1 | hiro | progress = progress_dialog_create(); |
| 537 | 1 | hiro | gtk_window_set_title(GTK_WINDOW(progress->window), |
| 538 | 1 | hiro | _("Sending message"));
|
| 539 | 1 | hiro | g_signal_connect(G_OBJECT(progress->cancel_btn), "clicked",
|
| 540 | 1 | hiro | G_CALLBACK(send_cancel_button_cb), dialog); |
| 541 | 1 | hiro | g_signal_connect(G_OBJECT(progress->window), "delete_event",
|
| 542 | 1 | hiro | G_CALLBACK(gtk_true), NULL);
|
| 543 | 1 | hiro | gtk_window_set_modal(GTK_WINDOW(progress->window), TRUE); |
| 544 | 1 | hiro | manage_window_set_transient(GTK_WINDOW(progress->window)); |
| 545 | 1 | hiro | |
| 546 | 1 | hiro | progress_dialog_set_value(progress, 0.0); |
| 547 | 1 | hiro | |
| 548 | 1 | hiro | gtk_widget_show_now(progress->window); |
| 549 | 1 | hiro | |
| 550 | 1 | hiro | dialog->dialog = progress; |
| 551 | 1 | hiro | |
| 552 | 1 | hiro | return dialog;
|
| 553 | 1 | hiro | } |
| 554 | 1 | hiro | |
| 555 | 1 | hiro | static void send_progress_dialog_destroy(SendProgressDialog *dialog) |
| 556 | 1 | hiro | {
|
| 557 | 1 | hiro | g_return_if_fail(dialog != NULL);
|
| 558 | 1 | hiro | |
| 559 | 1 | hiro | progress_dialog_destroy(dialog->dialog); |
| 560 | 1 | hiro | g_free(dialog); |
| 561 | 1 | hiro | } |
| 562 | 1 | hiro | |
| 563 | 1 | hiro | static void send_cancel_button_cb(GtkWidget *widget, gpointer data) |
| 564 | 1 | hiro | {
|
| 565 | 1 | hiro | SendProgressDialog *dialog = (SendProgressDialog *)data; |
| 566 | 1 | hiro | |
| 567 | 1 | hiro | dialog->cancelled = TRUE; |
| 568 | 1 | hiro | } |
| 569 | 1 | hiro | |
| 570 | 1 | hiro | static void send_put_error(Session *session) |
| 571 | 1 | hiro | {
|
| 572 | 1 | hiro | gchar *msg; |
| 573 | 1 | hiro | gchar *log_msg = NULL;
|
| 574 | 1 | hiro | gchar *err_msg = NULL;
|
| 575 | 1 | hiro | |
| 576 | 1 | hiro | msg = SMTP_SESSION(session)->error_msg; |
| 577 | 1 | hiro | |
| 578 | 1 | hiro | switch (SMTP_SESSION(session)->error_val) {
|
| 579 | 1 | hiro | case SM_ERROR:
|
| 580 | 1 | hiro | case SM_UNRECOVERABLE:
|
| 581 | 1 | hiro | log_msg = _("Error occurred while sending the message.");
|
| 582 | 1 | hiro | if (msg)
|
| 583 | 1 | hiro | err_msg = g_strdup_printf |
| 584 | 1 | hiro | (_("Error occurred while sending the message:\n%s"),
|
| 585 | 1 | hiro | msg); |
| 586 | 1 | hiro | else
|
| 587 | 1 | hiro | err_msg = g_strdup(log_msg); |
| 588 | 1 | hiro | break;
|
| 589 | 1 | hiro | case SM_AUTHFAIL:
|
| 590 | 1 | hiro | log_msg = _("Authentication failed.");
|
| 591 | 1 | hiro | if (msg)
|
| 592 | 1 | hiro | err_msg = g_strdup_printf |
| 593 | 1 | hiro | (_("Authentication failed:\n%s"), msg);
|
| 594 | 1 | hiro | else
|
| 595 | 1 | hiro | err_msg = g_strdup(log_msg); |
| 596 | 1 | hiro | break;
|
| 597 | 1 | hiro | default:
|
| 598 | 1 | hiro | switch (session->state) {
|
| 599 | 1 | hiro | case SESSION_ERROR:
|
| 600 | 1 | hiro | log_msg = |
| 601 | 1 | hiro | _("Error occurred while sending the message.");
|
| 602 | 1 | hiro | err_msg = g_strdup(log_msg); |
| 603 | 1 | hiro | break;
|
| 604 | 1 | hiro | case SESSION_EOF:
|
| 605 | 1 | hiro | log_msg = _("Connection closed by the remote host.");
|
| 606 | 1 | hiro | err_msg = g_strdup(log_msg); |
| 607 | 1 | hiro | break;
|
| 608 | 1 | hiro | case SESSION_TIMEOUT:
|
| 609 | 1 | hiro | log_msg = _("Session timed out.");
|
| 610 | 1 | hiro | err_msg = g_strdup(log_msg); |
| 611 | 1 | hiro | break;
|
| 612 | 1 | hiro | default:
|
| 613 | 1 | hiro | break;
|
| 614 | 1 | hiro | } |
| 615 | 1 | hiro | break;
|
| 616 | 1 | hiro | } |
| 617 | 1 | hiro | |
| 618 | 1 | hiro | if (log_msg)
|
| 619 | 1 | hiro | log_warning("%s\n", log_msg);
|
| 620 | 1 | hiro | if (err_msg) {
|
| 621 | 1 | hiro | alertpanel_error("%s", err_msg);
|
| 622 | 1 | hiro | g_free(err_msg); |
| 623 | 1 | hiro | } |
| 624 | 1 | hiro | } |