Remove wrong initialization from max_message_size
[claws.git] / src / send_message.c
blob7c76e2b6d8a3837ec9339957954094e5d201c382
1 /*
2 * Claws Mail -- a GTK based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2022 the Claws Mail team and Hiroyuki Yamamoto
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #ifdef HAVE_CONFIG_H
21 # include "config.h"
22 #include "claws-features.h"
23 #endif
25 #include "defs.h"
27 #include <glib.h>
28 #include <glib/gi18n.h>
29 #include <gtk/gtk.h>
30 #include <stdio.h>
31 #include <string.h>
32 #include <signal.h>
33 #include <sys/types.h>
34 #ifndef G_OS_WIN32
35 #include <sys/wait.h>
36 #endif
38 #include "send_message.h"
39 #include "session.h"
40 #include "ssl.h"
41 #include "smtp.h"
42 #include "prefs_common.h"
43 #include "prefs_account.h"
44 #include "procheader.h"
45 #include "account.h"
46 #include "progressdialog.h"
47 #include "statusbar.h"
48 #include "inputdialog.h"
49 #include "alertpanel.h"
50 #include "manage_window.h"
51 #include "logwindow.h"
52 #include "proxy.h"
53 #include "socket.h"
54 #include "utils.h"
55 #include "gtkutils.h"
56 #include "inc.h"
57 #include "log.h"
58 #include "passwordstore.h"
59 #include "file-utils.h"
60 #ifdef USE_OAUTH2
61 #include "oauth2.h"
62 #endif
64 typedef struct _SendProgressDialog SendProgressDialog;
66 struct _SendProgressDialog
68 ProgressDialog *dialog;
69 Session *session;
70 gboolean cancelled;
73 static SendProgressDialog *send_dialog = NULL;
75 static gint send_recv_message (Session *session,
76 const gchar *msg,
77 gpointer data);
78 static gint send_send_data_progressive (Session *session,
79 guint cur_len,
80 guint total_len,
81 gpointer data);
82 static gint send_send_data_finished (Session *session,
83 guint len,
84 gpointer data);
86 static SendProgressDialog *send_progress_dialog_create(void);
87 static void send_progress_dialog_destroy(SendProgressDialog *dialog);
89 static void send_showlog_button_cb (GtkWidget *widget,
90 gpointer data);
91 static void send_cancel_button_cb (GtkWidget *widget,
92 gpointer data);
94 static void send_put_error (Session *session);
97 void send_cancel(void)
99 if (send_dialog)
100 send_cancel_button_cb(NULL, send_dialog);
103 gboolean send_is_active(void)
105 return (send_dialog != NULL);
108 gint send_message(const gchar *file, PrefsAccount *ac_prefs, GSList *to_list)
110 FILE *fp;
111 gint val;
113 cm_return_val_if_fail(file != NULL, -1);
114 cm_return_val_if_fail(ac_prefs != NULL, -1);
115 cm_return_val_if_fail(to_list != NULL, -1);
117 if ((fp = claws_fopen(file, "rb")) == NULL) {
118 FILE_OP_ERROR(file, "claws_fopen");
119 return -1;
122 inc_lock();
123 if (ac_prefs->use_mail_command && ac_prefs->mail_command &&
124 (*ac_prefs->mail_command)) {
125 val = send_message_local(ac_prefs->mail_command, fp);
126 claws_fclose(fp);
127 inc_unlock();
128 return val;
129 } else {
130 val = send_message_smtp(ac_prefs, to_list, fp);
132 claws_fclose(fp);
133 inc_unlock();
134 return val;
138 enum
140 Q_SENDER = 0,
141 Q_SMTPSERVER = 1,
142 Q_RECIPIENTS = 2,
143 Q_ACCOUNT_ID = 3
146 gint send_message_local(const gchar *command, FILE *fp)
148 gchar **argv;
149 GPid pid;
150 gint child_stdin;
151 gchar buf[BUFFSIZE];
152 gboolean err = FALSE;
154 cm_return_val_if_fail(command != NULL, -1);
155 cm_return_val_if_fail(fp != NULL, -1);
157 log_message(LOG_PROTOCOL, _("Sending message using command: %s\n"), command);
159 argv = strsplit_with_quote(command, " ", 0);
161 if (g_spawn_async_with_pipes(NULL, argv, NULL,
162 #ifdef G_OS_WIN32
164 #else
165 G_SPAWN_DO_NOT_REAP_CHILD,
166 #endif
167 NULL, NULL,
168 &pid, &child_stdin, NULL, NULL,
169 NULL) == FALSE) {
170 g_snprintf(buf, sizeof(buf),
171 _("Couldn't execute command: %s"), command);
172 log_warning(LOG_PROTOCOL, "%s\n", buf);
173 alertpanel_error("%s", buf);
174 g_strfreev(argv);
175 return -1;
177 g_strfreev(argv);
179 while (claws_fgets(buf, sizeof(buf), fp) != NULL) {
180 strretchomp(buf);
181 if (buf[0] == '.' && buf[1] == '\0') {
182 if (fd_write_all(child_stdin, ".", 1) < 0) {
183 err = TRUE;
184 break;
187 if (fd_write_all(child_stdin, buf, strlen(buf)) < 0 ||
188 fd_write_all(child_stdin, "\n", 1) < 0) {
189 err = TRUE;
190 break;
194 fd_close(child_stdin);
196 #ifndef G_OS_WIN32
197 gint status;
198 waitpid(pid, &status, 0);
199 if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
200 err = TRUE;
201 #endif
203 g_spawn_close_pid(pid);
205 if (err) {
206 g_snprintf(buf, sizeof(buf),
207 _("Error occurred while executing command: %s"),
208 command);
209 log_warning(LOG_PROTOCOL, "%s\n", buf);
210 alertpanel_error("%s", buf);
211 return -1;
214 return 0;
217 gint send_message_smtp_full(PrefsAccount *ac_prefs, GSList *to_list, FILE *fp, gboolean keep_session)
219 Session *session;
220 SMTPSession *smtp_session;
221 gushort port = 0;
222 gchar buf[BUFFSIZE];
223 gint ret = 0;
224 gboolean was_inited = FALSE;
225 MsgInfo *tmp_msginfo = NULL;
226 MsgFlags flags = {0, 0};
227 long fp_pos = 0;
228 gchar spec_from[BUFFSIZE];
229 ProxyInfo *proxy_info = NULL;
231 cm_return_val_if_fail(ac_prefs != NULL, -1);
232 cm_return_val_if_fail(ac_prefs->address != NULL, -1);
233 cm_return_val_if_fail(ac_prefs->smtp_server != NULL, -1);
234 cm_return_val_if_fail(to_list != NULL, -1);
235 cm_return_val_if_fail(fp != NULL, -1);
237 /* get the From address used, not necessarily the ac_prefs',
238 * because it's editable. */
240 fp_pos = ftell(fp);
241 if (fp_pos < 0) {
242 perror("ftell");
243 return -1;
245 tmp_msginfo = procheader_parse_stream(fp, flags, TRUE, FALSE);
246 if (fseek(fp, fp_pos, SEEK_SET) < 0) {
247 perror("fseek");
248 return -1;
251 if (tmp_msginfo && tmp_msginfo->extradata && tmp_msginfo->extradata->resent_from) {
252 strncpy2(spec_from, tmp_msginfo->extradata->resent_from, BUFFSIZE-1);
253 extract_address(spec_from);
254 } else if (tmp_msginfo && tmp_msginfo->from) {
255 strncpy2(spec_from, tmp_msginfo->from, BUFFSIZE-1);
256 extract_address(spec_from);
257 } else {
258 strncpy2(spec_from, ac_prefs->address, BUFFSIZE-1);
260 if (tmp_msginfo) {
261 procmsg_msginfo_free(&tmp_msginfo);
264 if (!ac_prefs->session) {
265 /* we can't reuse a previously initialised session */
266 session = smtp_session_new(ac_prefs);
267 session->ssl_cert_auto_accept = ac_prefs->ssl_certs_auto_accept;
269 smtp_session = SMTP_SESSION(session);
271 if (ac_prefs->set_domain && ac_prefs->domain && strlen(ac_prefs->domain)) {
272 smtp_session->hostname = g_strdup(ac_prefs->domain);
273 } else {
274 smtp_session->hostname = NULL;
277 #ifdef USE_GNUTLS
278 port = ac_prefs->set_smtpport ? ac_prefs->smtpport :
279 ac_prefs->ssl_smtp == SSL_TUNNEL ? SSMTP_PORT : SMTP_PORT;
280 session->ssl_type = ac_prefs->ssl_smtp;
281 if (ac_prefs->ssl_smtp != SSL_NONE)
282 session->nonblocking = ac_prefs->use_nonblocking_ssl;
283 if (ac_prefs->set_gnutls_priority && ac_prefs->gnutls_priority &&
284 strlen(ac_prefs->gnutls_priority))
285 session->gnutls_priority = g_strdup(ac_prefs->gnutls_priority);
286 session->use_tls_sni = ac_prefs->use_tls_sni;
287 #ifdef USE_OAUTH2
288 if (ac_prefs->use_smtp_auth && ac_prefs->smtp_auth_type == SMTPAUTH_OAUTH2)
289 oauth2_check_passwds(ac_prefs);
290 #endif
291 #else
292 if (ac_prefs->ssl_smtp != SSL_NONE) {
293 if (alertpanel_full(_("Insecure connection"),
294 _("This connection is configured to be secured "
295 "using TLS, but TLS is not available "
296 "in this build of Claws Mail. \n\n"
297 "Do you want to continue connecting to this "
298 "server? The communication would not be "
299 "secure."),
300 NULL, _("_Cancel"), NULL, _("Con_tinue connecting"),
301 NULL, NULL, ALERTFOCUS_FIRST, FALSE, NULL, ALERT_WARNING) != G_ALERTALTERNATE) {
302 session_destroy(session);
303 return -1;
306 port = ac_prefs->set_smtpport ? ac_prefs->smtpport : SMTP_PORT;
307 #endif
309 if (ac_prefs->use_smtp_auth) {
310 smtp_session->forced_auth_type = ac_prefs->smtp_auth_type;
311 if (ac_prefs->smtp_userid && strlen(ac_prefs->smtp_userid)) {
312 smtp_session->user = g_strdup(ac_prefs->smtp_userid);
313 if (password_get(smtp_session->user,
314 ac_prefs->smtp_server, "smtp", port,
315 &(smtp_session->pass))) {
316 /* NOP */;
317 } else if ((smtp_session->pass =
318 passwd_store_get_account(ac_prefs->account_id,
319 PWS_ACCOUNT_SEND)) == NULL) {
320 smtp_session->pass =
321 input_dialog_query_password_keep
322 (ac_prefs->smtp_server,
323 smtp_session->user,
324 &(ac_prefs->session_smtp_passwd));
325 if (!smtp_session->pass) {
326 session_destroy(session);
327 return -1;
330 } else {
331 smtp_session->user = g_strdup(ac_prefs->userid);
332 if (password_get(smtp_session->user,
333 ac_prefs->smtp_server, "smtp", port,
334 &(smtp_session->pass))) {
335 /* NOP */;
336 } else if ((smtp_session->pass = passwd_store_get_account(
337 ac_prefs->account_id, PWS_ACCOUNT_RECV)) == NULL) {
338 smtp_session->pass =
339 input_dialog_query_password_keep
340 (ac_prefs->smtp_server,
341 smtp_session->user,
342 &(ac_prefs->session_smtp_passwd));
343 if (!smtp_session->pass) {
344 session_destroy(session);
345 return -1;
349 } else {
350 smtp_session->user = NULL;
351 smtp_session->pass = NULL;
354 send_dialog = send_progress_dialog_create();
355 send_dialog->session = session;
356 smtp_session->dialog = send_dialog;
358 progress_dialog_list_set(send_dialog->dialog, 0, NULL,
359 ac_prefs->smtp_server,
360 _("Connecting"));
362 if (ac_prefs->pop_before_smtp
363 && (ac_prefs->protocol == A_POP3)
364 && (time(NULL) - ac_prefs->last_pop_login_time) > (60 * ac_prefs->pop_before_smtp_timeout)) {
365 g_snprintf(buf, sizeof(buf), _("Doing POP before SMTP..."));
366 log_message(LOG_PROTOCOL, "%s\n", buf);
367 progress_dialog_set_label(send_dialog->dialog, buf);
368 progress_dialog_list_set_status(send_dialog->dialog, 0, _("POP before SMTP"));
369 GTK_EVENTS_FLUSH();
370 inc_pop_before_smtp(ac_prefs);
373 g_snprintf(buf, sizeof(buf), _("Account '%s': Connecting to SMTP server: %s:%d..."),
374 ac_prefs->account_name, ac_prefs->smtp_server, port);
375 progress_dialog_set_label(send_dialog->dialog, buf);
376 log_message(LOG_PROTOCOL, "%s\n", buf);
378 session_set_recv_message_notify(session, send_recv_message, send_dialog);
379 session_set_send_data_progressive_notify
380 (session, send_send_data_progressive, send_dialog);
381 session_set_send_data_notify(session, send_send_data_finished, send_dialog);
383 } else {
384 /* everything is ready to start at MAIL FROM:, just
385 * reinit useful variables.
387 session = SESSION(ac_prefs->session);
388 ac_prefs->session = NULL;
389 smtp_session = SMTP_SESSION(session);
390 smtp_session->state = SMTP_HELO;
391 send_dialog = (SendProgressDialog *)smtp_session->dialog;
392 was_inited = TRUE;
395 /* This has to be initialised for every mail sent */
396 smtp_session->from = g_strdup(spec_from);
397 smtp_session->to_list = to_list;
398 smtp_session->cur_to = to_list;
399 smtp_session->send_data = (guchar *)get_outgoing_rfc2822_str(fp);
400 smtp_session->send_data_len = strlen((gchar *)smtp_session->send_data);
402 if (ac_prefs->use_proxy && ac_prefs->use_proxy_for_send) {
403 if (ac_prefs->use_default_proxy) {
404 proxy_info = (ProxyInfo *)&(prefs_common.proxy_info);
405 if (proxy_info->use_proxy_auth)
406 proxy_info->proxy_pass = passwd_store_get(PWS_CORE, PWS_CORE_PROXY,
407 PWS_CORE_PROXY_PASS);
408 } else {
409 proxy_info = (ProxyInfo *)&(ac_prefs->proxy_info);
410 if (proxy_info->use_proxy_auth)
411 proxy_info->proxy_pass = passwd_store_get_account(ac_prefs->account_id,
412 PWS_ACCOUNT_PROXY_PASS);
415 SESSION(smtp_session)->proxy_info = proxy_info;
417 session_set_timeout(session,
418 prefs_common.io_timeout_secs * 1000);
419 /* connect if necessary */
420 if (!was_inited && session_connect(session, ac_prefs->smtp_server,
421 port) < 0) {
422 session_destroy(session);
423 send_progress_dialog_destroy(send_dialog);
424 ac_prefs->session = NULL;
425 return -1;
428 debug_print("send_message_smtp(): begin event loop\n");
430 if (was_inited) {
431 /* as the server is quiet, start sending ourselves */
432 smtp_from(smtp_session);
435 while (session_is_running(session) && send_dialog->cancelled == FALSE
436 && SMTP_SESSION(session)->state != SMTP_MAIL_SENT_OK)
437 gtk_main_iteration();
439 if (SMTP_SESSION(session)->error_val == SM_AUTHFAIL) {
440 if (ac_prefs->session_smtp_passwd) {
441 g_free(ac_prefs->session_smtp_passwd);
442 ac_prefs->session_smtp_passwd = NULL;
444 ret = -1;
445 } else if (SMTP_SESSION(session)->state == SMTP_MAIL_SENT_OK) {
446 log_message(LOG_PROTOCOL, "%s\n", _("Mail sent successfully."));
447 ret = 0;
448 } else if (session->state == SESSION_EOF &&
449 SMTP_SESSION(session)->state == SMTP_QUIT) {
450 /* consider EOF right after QUIT successful */
451 log_warning(LOG_PROTOCOL, "%s\n", _("Connection closed by the remote host."));
452 ret = 0;
453 } else if (session->state == SESSION_ERROR ||
454 session->state == SESSION_EOF ||
455 session->state == SESSION_TIMEOUT ||
456 SMTP_SESSION(session)->state == SMTP_ERROR ||
457 SMTP_SESSION(session)->error_val != SM_OK)
458 ret = -1;
459 else if (send_dialog->cancelled == TRUE)
460 ret = -1;
462 if (ret == -1) {
463 manage_window_focus_in(send_dialog->dialog->window, NULL, NULL);
464 send_put_error(session);
465 manage_window_focus_out(send_dialog->dialog->window, NULL, NULL);
468 /* if we should close the connection, let's do it.
469 * Close it in case of error, too, as it helps reinitializing things
470 * easier.
472 if (!keep_session || ret != 0) {
473 if (session_is_connected(session))
474 smtp_quit(smtp_session);
475 while (session_is_connected(session) && !send_dialog->cancelled)
476 gtk_main_iteration();
477 session_destroy(session);
478 ac_prefs->session = NULL;
479 send_progress_dialog_destroy(send_dialog);
480 } else {
481 g_free(smtp_session->from);
482 g_free(smtp_session->send_data);
483 g_free(smtp_session->error_msg);
485 if (keep_session && ret == 0 && ac_prefs->session == NULL)
486 ac_prefs->session = SMTP_SESSION(session);
489 statusbar_pop_all();
490 statusbar_verbosity_set(FALSE);
491 return ret;
494 gint send_message_smtp(PrefsAccount *ac_prefs, GSList *to_list, FILE *fp)
496 return send_message_smtp_full(ac_prefs, to_list, fp, FALSE);
499 static gint send_recv_message(Session *session, const gchar *msg, gpointer data)
501 gchar buf[BUFFSIZE];
502 SMTPSession *smtp_session = SMTP_SESSION(session);
503 SendProgressDialog *dialog = (SendProgressDialog *)data;
504 gchar *state_str = NULL;
506 cm_return_val_if_fail(dialog != NULL, -1);
508 switch (smtp_session->state) {
509 case SMTP_READY:
510 return 0;
511 case SMTP_HELO:
512 g_snprintf(buf, sizeof(buf), _("Sending HELO..."));
513 state_str = _("Authenticating");
514 statusbar_print_all(_("Sending message..."));
515 break;
516 case SMTP_EHLO:
517 g_snprintf(buf, sizeof(buf), _("Sending EHLO..."));
518 state_str = _("Authenticating");
519 statusbar_print_all(_("Sending message..."));
520 break;
521 case SMTP_AUTH:
522 g_snprintf(buf, sizeof(buf), _("Authenticating..."));
523 state_str = _("Authenticating");
524 break;
525 case SMTP_FROM:
526 g_snprintf(buf, sizeof(buf), _("Sending MAIL FROM..."));
527 state_str = _("Sending");
528 break;
529 case SMTP_RCPT:
530 g_snprintf(buf, sizeof(buf), _("Sending RCPT TO..."));
531 state_str = _("Sending");
532 break;
533 case SMTP_DATA:
534 case SMTP_EOM:
535 g_snprintf(buf, sizeof(buf), _("Sending DATA..."));
536 state_str = _("Sending");
537 break;
538 case SMTP_QUIT:
539 g_snprintf(buf, sizeof(buf), _("Quitting..."));
540 state_str = _("Quitting");
541 break;
542 case SMTP_ERROR:
543 g_warning("send: error: %s", msg);
544 return 0;
545 default:
546 return 0;
549 progress_dialog_set_label(dialog->dialog, buf);
550 progress_dialog_list_set_status(dialog->dialog, 0, state_str);
552 return 0;
555 static gint send_send_data_progressive(Session *session, guint cur_len,
556 guint total_len, gpointer data)
558 gchar buf[BUFFSIZE];
559 SendProgressDialog *dialog = (SendProgressDialog *)data;
560 MainWindow *mainwin = mainwindow_get_mainwindow();
562 cm_return_val_if_fail(dialog != NULL, -1);
564 if (SMTP_SESSION(session)->state != SMTP_SEND_DATA &&
565 SMTP_SESSION(session)->state != SMTP_EOM)
566 return 0;
568 g_snprintf(buf, sizeof(buf), _("Sending message (%d / %d bytes)"),
569 cur_len, total_len);
570 progress_dialog_set_label(dialog->dialog, buf);
571 progress_dialog_set_fraction
572 (dialog->dialog, (total_len == 0) ? 0 : (gfloat)cur_len / (gfloat)total_len);
574 if (mainwin) {
575 if (!gtk_widget_get_visible(mainwin->progressbar))
576 gtk_widget_show(mainwin->progressbar);
577 gtk_progress_bar_set_fraction
578 (GTK_PROGRESS_BAR(mainwin->progressbar),
579 (total_len == 0) ? 0 : (gfloat)cur_len / (gfloat)total_len);
582 return 0;
585 static gint send_send_data_finished(Session *session, guint len, gpointer data)
587 SendProgressDialog *dialog = (SendProgressDialog *)data;
588 MainWindow *mainwin = mainwindow_get_mainwindow();
590 cm_return_val_if_fail(dialog != NULL, -1);
592 send_send_data_progressive(session, len, len, dialog);
593 if (mainwin) {
594 gtk_widget_hide(mainwin->progressbar);
595 gtk_progress_bar_set_fraction
596 (GTK_PROGRESS_BAR(mainwin->progressbar),(gfloat)0);
599 return 0;
602 static void send_progress_dialog_size_allocate_cb(GtkWidget *widget,
603 GtkAllocation *allocation)
605 cm_return_if_fail(allocation != NULL);
607 gtk_window_get_size(GTK_WINDOW(widget),
608 &prefs_common.sendwin_width, &prefs_common.sendwin_height);
611 static SendProgressDialog *send_progress_dialog_create(void)
613 SendProgressDialog *dialog;
614 ProgressDialog *progress;
615 static GdkGeometry geometry;
617 dialog = g_new0(SendProgressDialog, 1);
619 progress = progress_dialog_create();
620 gtk_window_set_title(GTK_WINDOW(progress->window),
621 _("Sending message"));
622 g_signal_connect(G_OBJECT(progress->showlog_btn), "clicked",
623 G_CALLBACK(send_showlog_button_cb), dialog);
624 g_signal_connect(G_OBJECT(progress->cancel_btn), "clicked",
625 G_CALLBACK(send_cancel_button_cb), dialog);
626 g_signal_connect(G_OBJECT(progress->window), "delete_event",
627 G_CALLBACK(gtk_true), NULL);
628 gtk_window_set_modal(GTK_WINDOW(progress->window), TRUE);
629 g_signal_connect(G_OBJECT(progress->window), "size_allocate",
630 G_CALLBACK(send_progress_dialog_size_allocate_cb), NULL);
631 manage_window_set_transient(GTK_WINDOW(progress->window));
633 progress_dialog_get_fraction(progress);
635 if (!geometry.min_height) {
636 geometry.min_width = 460;
637 geometry.min_height = 250;
640 gtk_window_set_geometry_hints(GTK_WINDOW(progress->window), NULL, &geometry,
641 GDK_HINT_MIN_SIZE);
642 gtk_widget_set_size_request(progress->window, prefs_common.sendwin_width,
643 prefs_common.sendwin_height);
645 if (!prefs_common.send_dialog_invisible) {
646 gtk_widget_show_now(progress->window);
649 dialog->dialog = progress;
651 return dialog;
654 static void send_progress_dialog_destroy(SendProgressDialog *dialog)
656 cm_return_if_fail(dialog != NULL);
657 if (!prefs_common.send_dialog_invisible) {
658 progress_dialog_destroy(dialog->dialog);
660 g_free(dialog);
661 send_dialog = NULL;
664 static void send_showlog_button_cb(GtkWidget *widget, gpointer data)
666 MainWindow *mainwin = mainwindow_get_mainwindow();
668 log_window_show(mainwin->logwin);
671 static void send_cancel_button_cb(GtkWidget *widget, gpointer data)
673 SendProgressDialog *dialog = (SendProgressDialog *)data;
674 statusbar_progress_all(0,0,0);
676 dialog->cancelled = TRUE;
679 static void send_put_error(Session *session)
681 gchar *msg;
682 gchar *log_msg = NULL;
683 gchar *err_msg = NULL;
685 msg = SMTP_SESSION(session)->error_msg;
687 switch (SMTP_SESSION(session)->error_val) {
688 case SM_ERROR:
689 case SM_UNRECOVERABLE:
690 log_msg = _("Error occurred while sending the message.");
691 if (msg)
692 err_msg = g_strdup_printf
693 (_("Error occurred while sending the message:\n%s"),
694 msg);
695 else
696 err_msg = g_strdup(log_msg);
697 break;
698 case SM_AUTHFAIL:
699 log_msg = _("Authentication failed.");
700 if (msg)
701 err_msg = g_strdup_printf
702 (_("Authentication failed:\n%s"), msg);
703 else
704 err_msg = g_strdup(log_msg);
705 break;
706 default:
707 switch (session->state) {
708 case SESSION_ERROR:
709 log_msg =
710 _("Error occurred while sending the message.");
711 err_msg = g_strdup(log_msg);
712 break;
713 case SESSION_EOF:
714 log_msg = _("Connection closed by the remote host.");
715 err_msg = g_strdup(log_msg);
716 break;
717 case SESSION_TIMEOUT:
718 log_msg = _("Session timed out. You may be able to "
719 "recover by increasing the timeout value in "
720 "Preferences/Other/Miscellaneous.");
721 err_msg = g_strdup(log_msg);
722 break;
723 default:
724 break;
726 break;
729 if (err_msg) {
730 log_error(LOG_PROTOCOL, "%s\n", err_msg);
731 g_free(err_msg);
732 } else {
733 if (log_msg)
734 log_warning(LOG_PROTOCOL, "%s\n", log_msg);