2012-11-27 [wwp] 3.9.0cvs21
[claws.git] / src / send_message.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2012 Hiroyuki Yamamoto and the Claws Mail team
4  *
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.
9  *
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.
14  *
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/>.
17  * 
18  */
19
20 #ifdef HAVE_CONFIG_H
21 #  include "config.h"
22 #include "claws-features.h"
23 #endif
24
25 #include "defs.h"
26
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
37
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 "socket.h"
53 #include "utils.h"
54 #include "gtkutils.h"
55 #include "inc.h"
56 #include "log.h"
57
58 typedef struct _SendProgressDialog      SendProgressDialog;
59
60 struct _SendProgressDialog
61 {
62         ProgressDialog *dialog;
63         Session *session;
64         gboolean cancelled;
65 };
66
67 static SendProgressDialog *send_dialog = NULL;
68
69 static gint send_recv_message           (Session                *session,
70                                          const gchar            *msg,
71                                          gpointer                data);
72 static gint send_send_data_progressive  (Session                *session,
73                                          guint                   cur_len,
74                                          guint                   total_len,
75                                          gpointer                data);
76 static gint send_send_data_finished     (Session                *session,
77                                          guint                   len,
78                                          gpointer                data);
79
80 static SendProgressDialog *send_progress_dialog_create(void);
81 static void send_progress_dialog_destroy(SendProgressDialog *dialog);
82
83 static void send_showlog_button_cb      (GtkWidget      *widget,
84                                          gpointer        data);
85 static void send_cancel_button_cb       (GtkWidget      *widget,
86                                          gpointer        data);
87
88 static void send_put_error              (Session        *session);
89
90
91 void send_cancel(void)
92 {
93         if (send_dialog)
94                 send_cancel_button_cb(NULL, send_dialog);
95 }
96
97 gint send_message(const gchar *file, PrefsAccount *ac_prefs, GSList *to_list)
98 {
99         FILE *fp;
100         gint val;
101
102         cm_return_val_if_fail(file != NULL, -1);
103         cm_return_val_if_fail(ac_prefs != NULL, -1);
104         cm_return_val_if_fail(to_list != NULL, -1);
105
106         if ((fp = g_fopen(file, "rb")) == NULL) {
107                 FILE_OP_ERROR(file, "fopen");
108                 return -1;
109         }
110
111         inc_lock();
112         if (ac_prefs->use_mail_command && ac_prefs->mail_command &&
113             (*ac_prefs->mail_command)) {
114                 val = send_message_local(ac_prefs->mail_command, fp);
115                 fclose(fp);
116                 inc_unlock();
117                 return val;
118         } else {
119                 val = send_message_smtp(ac_prefs, to_list, fp);
120                 
121                 fclose(fp);
122                 inc_unlock();
123                 return val;
124         }
125 }
126
127 enum
128 {
129         Q_SENDER     = 0,
130         Q_SMTPSERVER = 1,
131         Q_RECIPIENTS = 2,
132         Q_ACCOUNT_ID = 3
133 };
134
135 gint send_message_local(const gchar *command, FILE *fp)
136 {
137         gchar **argv;
138         GPid pid;
139         gint child_stdin;
140         gchar buf[BUFFSIZE];
141         gboolean err = FALSE;
142         gint status;
143
144         cm_return_val_if_fail(command != NULL, -1);
145         cm_return_val_if_fail(fp != NULL, -1);
146
147         log_message(LOG_PROTOCOL, _("Sending message using command: %s\n"), command);
148
149         argv = strsplit_with_quote(command, " ", 0);
150
151         if (g_spawn_async_with_pipes(NULL, argv, NULL,
152 #ifdef G_OS_WIN32
153                                      0,
154 #else
155                                      G_SPAWN_DO_NOT_REAP_CHILD,
156 #endif
157                                      NULL, NULL,
158                                      &pid, &child_stdin, NULL, NULL,
159                                      NULL) == FALSE) {
160                 g_snprintf(buf, sizeof(buf),
161                            _("Couldn't execute command: %s"), command);
162                 log_warning(LOG_PROTOCOL, "%s\n", buf);
163                 alertpanel_error("%s", buf);
164                 g_strfreev(argv);
165                 return -1;
166         }
167         g_strfreev(argv);
168
169         while (fgets(buf, sizeof(buf), fp) != NULL) {
170                 strretchomp(buf);
171                 if (buf[0] == '.' && buf[1] == '\0') {
172                         if (fd_write_all(child_stdin, ".", 1) < 0) {
173                                 err = TRUE;
174                                 break;
175                         }
176                 }
177                 if (fd_write_all(child_stdin, buf, strlen(buf)) < 0 ||
178                     fd_write_all(child_stdin, "\n", 1) < 0) {
179                         err = TRUE;
180                         break;
181                 }
182         }
183
184         fd_close(child_stdin);
185
186 #ifndef G_OS_WIN32
187         waitpid(pid, &status, 0);
188         if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
189                 err = TRUE;
190 #endif
191
192         g_spawn_close_pid(pid);
193
194         if (err) {
195                 g_snprintf(buf, sizeof(buf),
196                            _("Error occurred while executing command: %s"),
197                            command);
198                 log_warning(LOG_PROTOCOL, "%s\n", buf);
199                 alertpanel_error("%s", buf);
200                 return -1;
201         }
202
203         return 0;
204 }
205
206 gint send_message_smtp_full(PrefsAccount *ac_prefs, GSList *to_list, FILE *fp, gboolean keep_session)
207 {
208         Session *session;
209         SMTPSession *smtp_session;
210         gushort port = 0;
211         gchar buf[BUFFSIZE];
212         gint ret = 0;
213         gboolean was_inited = FALSE;
214         MsgInfo *tmp_msginfo = NULL;
215         MsgFlags flags = {0, 0};
216         long fp_pos = 0;
217         gchar spec_from[BUFFSIZE];
218
219         cm_return_val_if_fail(ac_prefs != NULL, -1);
220         cm_return_val_if_fail(ac_prefs->address != NULL, -1);
221         cm_return_val_if_fail(ac_prefs->smtp_server != NULL, -1);
222         cm_return_val_if_fail(to_list != NULL, -1);
223         cm_return_val_if_fail(fp != NULL, -1);
224
225         /* get the From address used, not necessarily the ac_prefs',
226          * because it's editable. */
227
228         fp_pos = ftell(fp);
229         tmp_msginfo = procheader_parse_stream(fp, flags, FALSE, FALSE);
230         fseek(fp, fp_pos, SEEK_SET);
231         
232         if (tmp_msginfo && tmp_msginfo->from) {
233                 strncpy2(spec_from, tmp_msginfo->from, BUFFSIZE-1);
234                 extract_address(spec_from);
235         } else {
236                 strncpy2(spec_from, ac_prefs->address, BUFFSIZE-1);
237         }
238         if (tmp_msginfo) {
239                 procmsg_msginfo_free(tmp_msginfo);
240         }
241
242         if (!ac_prefs->session) {
243                 /* we can't reuse a previously initialised session */
244                 session = smtp_session_new(ac_prefs);
245                 smtp_session = SMTP_SESSION(session);
246
247                 if (ac_prefs->set_domain && ac_prefs->domain && strlen(ac_prefs->domain)) {
248                         smtp_session->hostname = g_strdup(ac_prefs->domain);
249                 } else {
250                         smtp_session->hostname = NULL;
251                 }
252
253                 if (ac_prefs->use_smtp_auth) {
254                         smtp_session->forced_auth_type = ac_prefs->smtp_auth_type;
255                         if (ac_prefs->smtp_userid && strlen(ac_prefs->smtp_userid)) {
256                                 smtp_session->user = g_strdup(ac_prefs->smtp_userid);
257                                 if (ac_prefs->smtp_passwd)
258                                         smtp_session->pass =
259                                                 g_strdup(ac_prefs->smtp_passwd);
260                                 else {
261                                         smtp_session->pass =
262                                                 input_dialog_query_password_keep
263                                                         (ac_prefs->smtp_server,
264                                                          smtp_session->user,
265                                                          &(ac_prefs->session_smtp_passwd));
266                                         if (!smtp_session->pass) {
267                                                 session_destroy(session);
268                                                 return -1;
269                                         }
270                                 }
271                         } else {
272                                 smtp_session->user = g_strdup(ac_prefs->userid);
273                                 if (ac_prefs->passwd)
274                                         smtp_session->pass = g_strdup(ac_prefs->passwd);
275                                 else {
276                                         smtp_session->pass =
277                                                 input_dialog_query_password_keep
278                                                         (ac_prefs->smtp_server,
279                                                          smtp_session->user,
280                                                          &(ac_prefs->session_smtp_passwd));
281                                         if (!smtp_session->pass) {
282                                                 session_destroy(session);
283                                                 return -1;
284                                         }
285                                 }
286                         }
287                 } else {
288                         smtp_session->user = NULL;
289                         smtp_session->pass = NULL;
290                 }
291
292 #ifdef USE_GNUTLS
293                 port = ac_prefs->set_smtpport ? ac_prefs->smtpport :
294                         ac_prefs->ssl_smtp == SSL_TUNNEL ? SSMTP_PORT : SMTP_PORT;
295                 session->ssl_type = ac_prefs->ssl_smtp;
296                 if (ac_prefs->ssl_smtp != SSL_NONE)
297                         session->nonblocking = ac_prefs->use_nonblocking_ssl;
298 #else
299                 if (ac_prefs->ssl_smtp != SSL_NONE) {
300                         if (alertpanel_full(_("Insecure connection"),
301                                 _("This connection is configured to be secured "
302                                   "using SSL, but SSL is not available in this "
303                                   "build of Claws Mail. \n\n"
304                                   "Do you want to continue connecting to this "
305                                   "server? The communication would not be "
306                                   "secure."),
307                                   GTK_STOCK_CANCEL, _("Con_tinue connecting"),
308                                   NULL, FALSE, NULL, ALERT_WARNING,
309                                   G_ALERTDEFAULT) != G_ALERTALTERNATE) {
310                                 session_destroy(session);
311                                 return -1;
312                         }
313                 }
314                 port = ac_prefs->set_smtpport ? ac_prefs->smtpport : SMTP_PORT;
315 #endif
316
317                 send_dialog = send_progress_dialog_create();
318                 send_dialog->session = session;
319                 smtp_session->dialog = send_dialog;
320
321                 progress_dialog_list_set(send_dialog->dialog, 0, NULL, 
322                                          ac_prefs->smtp_server, 
323                                          _("Connecting"));
324
325                 if (ac_prefs->pop_before_smtp
326                     && (ac_prefs->protocol == A_APOP || ac_prefs->protocol == A_POP3)
327                     && (time(NULL) - ac_prefs->last_pop_login_time) > (60 * ac_prefs->pop_before_smtp_timeout)) {
328                         g_snprintf(buf, sizeof(buf), _("Doing POP before SMTP..."));
329                         log_message(LOG_PROTOCOL, "%s\n", buf);
330                         progress_dialog_set_label(send_dialog->dialog, buf);
331                         progress_dialog_list_set_status(send_dialog->dialog, 0, _("POP before SMTP"));
332                         GTK_EVENTS_FLUSH();
333                         inc_pop_before_smtp(ac_prefs);
334                 }
335
336                 g_snprintf(buf, sizeof(buf), _("Account '%s': Connecting to SMTP server: %s:%d..."),
337                                 ac_prefs->account_name, ac_prefs->smtp_server, port);
338                 progress_dialog_set_label(send_dialog->dialog, buf);
339                 log_message(LOG_PROTOCOL, "%s\n", buf);
340
341                 session_set_recv_message_notify(session, send_recv_message, send_dialog);
342                 session_set_send_data_progressive_notify
343                         (session, send_send_data_progressive, send_dialog);
344                 session_set_send_data_notify(session, send_send_data_finished, send_dialog);
345
346         } else {
347                 /* everything is ready to start at MAIL FROM:, just
348                  * reinit useful variables. 
349                  */
350                 session = SESSION(ac_prefs->session);
351                 ac_prefs->session = NULL;
352                 smtp_session = SMTP_SESSION(session);
353                 smtp_session->state = SMTP_HELO;
354                 send_dialog = (SendProgressDialog *)smtp_session->dialog;
355                 was_inited = TRUE;
356         }
357
358         /* This has to be initialised for every mail sent */
359         smtp_session->from = g_strdup(spec_from);
360         smtp_session->to_list = to_list;
361         smtp_session->cur_to = to_list;
362         smtp_session->send_data = (guchar *)get_outgoing_rfc2822_str(fp);
363         smtp_session->send_data_len = strlen((gchar *)smtp_session->send_data);
364
365         session_set_timeout(session,
366                             prefs_common.io_timeout_secs * 1000);
367         /* connect if necessary */
368         if (!was_inited && session_connect(session, ac_prefs->smtp_server, port) < 0) {
369                 session_destroy(session);
370                 send_progress_dialog_destroy(send_dialog);
371                 ac_prefs->session = NULL;
372                 return -1;
373         }
374
375         debug_print("send_message_smtp(): begin event loop\n");
376
377         if (was_inited) {
378                 /* as the server is quiet, start sending ourselves */
379                 smtp_from(smtp_session);
380         }
381
382         while (session_is_running(session) && send_dialog->cancelled == FALSE
383                 && SMTP_SESSION(session)->state != SMTP_MAIL_SENT_OK)
384                 gtk_main_iteration();
385
386         if (SMTP_SESSION(session)->error_val == SM_AUTHFAIL) {
387                 if (ac_prefs->session_smtp_passwd) {
388                         g_free(ac_prefs->session_smtp_passwd);
389                         ac_prefs->session_smtp_passwd = NULL;
390                 }
391                 ret = -1;
392         } else if (SMTP_SESSION(session)->state == SMTP_MAIL_SENT_OK) {
393                 log_message(LOG_PROTOCOL, "%s\n", _("Mail sent successfully."));
394                 ret = 0;
395         } else if (session->state == SESSION_EOF &&
396                    SMTP_SESSION(session)->state == SMTP_QUIT) {
397                 /* consider EOF right after QUIT successful */
398                 log_warning(LOG_PROTOCOL, "%s\n", _("Connection closed by the remote host."));
399                 ret = 0;
400         } else if (session->state == SESSION_ERROR ||
401                    session->state == SESSION_EOF ||
402                    session->state == SESSION_TIMEOUT ||
403                    SMTP_SESSION(session)->state == SMTP_ERROR ||
404                    SMTP_SESSION(session)->error_val != SM_OK)
405                 ret = -1;
406         else if (send_dialog->cancelled == TRUE)
407                 ret = -1;
408
409         if (ret == -1) {
410                 manage_window_focus_in(send_dialog->dialog->window, NULL, NULL);
411                 send_put_error(session);
412                 manage_window_focus_out(send_dialog->dialog->window, NULL, NULL);
413         }
414
415         /* if we should close the connection, let's do it.
416          * Close it in case of error, too, as it helps reinitializing things
417          * easier.
418          */
419         if (!keep_session || ret != 0) {
420                 if (session_is_connected(session))
421                         smtp_quit(smtp_session);
422                 while (session_is_connected(session) && !send_dialog->cancelled)
423                         gtk_main_iteration();
424                 session_destroy(session);
425                 ac_prefs->session = NULL;
426                 send_progress_dialog_destroy(send_dialog);
427         } else {
428                 g_free(smtp_session->from);
429                 g_free(smtp_session->send_data);
430                 g_free(smtp_session->error_msg);
431         }
432         if (keep_session && ret == 0 && ac_prefs->session == NULL)
433                 ac_prefs->session = SMTP_SESSION(session);
434
435
436         statuswindow_pop_all();
437         statusbar_verbosity_set(FALSE);
438         return ret;
439 }
440
441 gint send_message_smtp(PrefsAccount *ac_prefs, GSList *to_list, FILE *fp)
442 {
443         return send_message_smtp_full(ac_prefs, to_list, fp, FALSE);
444 }
445
446 static gint send_recv_message(Session *session, const gchar *msg, gpointer data)
447 {
448         gchar buf[BUFFSIZE];
449         SMTPSession *smtp_session = SMTP_SESSION(session);
450         SendProgressDialog *dialog = (SendProgressDialog *)data;
451         gchar *state_str = NULL;
452
453         cm_return_val_if_fail(dialog != NULL, -1);
454
455         switch (smtp_session->state) {
456         case SMTP_READY:
457         case SMTP_CONNECTED:
458                 return 0;
459         case SMTP_HELO:
460                 g_snprintf(buf, sizeof(buf), _("Sending HELO..."));
461                 state_str = _("Authenticating");
462                 statuswindow_print_all(_("Sending message..."));
463                 break;
464         case SMTP_EHLO:
465                 g_snprintf(buf, sizeof(buf), _("Sending EHLO..."));
466                 state_str = _("Authenticating");
467                 statuswindow_print_all(_("Sending message..."));
468                 break;
469         case SMTP_AUTH:
470                 g_snprintf(buf, sizeof(buf), _("Authenticating..."));
471                 state_str = _("Authenticating");
472                 break;
473         case SMTP_FROM:
474                 g_snprintf(buf, sizeof(buf), _("Sending MAIL FROM..."));
475                 state_str = _("Sending");
476                 break;
477         case SMTP_RCPT:
478                 g_snprintf(buf, sizeof(buf), _("Sending RCPT TO..."));
479                 state_str = _("Sending");
480                 break;
481         case SMTP_DATA:
482         case SMTP_EOM:
483                 g_snprintf(buf, sizeof(buf), _("Sending DATA..."));
484                 state_str = _("Sending");
485                 break;
486         case SMTP_QUIT:
487                 g_snprintf(buf, sizeof(buf), _("Quitting..."));
488                 state_str = _("Quitting");
489                 break;
490         case SMTP_ERROR:
491                 g_warning("send: error: %s\n", msg);
492                 return 0;
493         default:
494                 return 0;
495         }
496
497         progress_dialog_set_label(dialog->dialog, buf);
498         progress_dialog_list_set_status(dialog->dialog, 0, state_str);
499
500         return 0;
501 }
502
503 static gint send_send_data_progressive(Session *session, guint cur_len,
504                                        guint total_len, gpointer data)
505 {
506         gchar buf[BUFFSIZE];
507         SendProgressDialog *dialog = (SendProgressDialog *)data;
508         MainWindow *mainwin = mainwindow_get_mainwindow();
509         
510         cm_return_val_if_fail(dialog != NULL, -1);
511
512         if (SMTP_SESSION(session)->state != SMTP_SEND_DATA &&
513             SMTP_SESSION(session)->state != SMTP_EOM)
514                 return 0;
515
516         g_snprintf(buf, sizeof(buf), _("Sending message (%d / %d bytes)"),
517                    cur_len, total_len);
518         progress_dialog_set_label(dialog->dialog, buf);
519         progress_dialog_set_fraction
520                 (dialog->dialog, (total_len == 0) ? 0 : (gfloat)cur_len / (gfloat)total_len);
521
522         if (mainwin) {
523                 if (!gtk_widget_get_visible(mainwin->progressbar))      
524                         gtk_widget_show(mainwin->progressbar);
525                 gtk_progress_bar_set_fraction
526                         (GTK_PROGRESS_BAR(mainwin->progressbar),
527                          (total_len == 0) ? 0 : (gfloat)cur_len / (gfloat)total_len);
528         }
529
530         return 0;
531 }
532
533 static gint send_send_data_finished(Session *session, guint len, gpointer data)
534 {
535         SendProgressDialog *dialog = (SendProgressDialog *)data;
536         MainWindow *mainwin = mainwindow_get_mainwindow();
537
538         cm_return_val_if_fail(dialog != NULL, -1);
539
540         send_send_data_progressive(session, len, len, dialog);
541         if (mainwin) {
542                 gtk_widget_hide(mainwin->progressbar);
543                 gtk_progress_bar_set_fraction
544                         (GTK_PROGRESS_BAR(mainwin->progressbar),(gfloat)0);
545         }
546
547         return 0;
548 }
549
550 static void send_progress_dialog_size_allocate_cb(GtkWidget *widget,
551                                          GtkAllocation *allocation)
552 {
553         cm_return_if_fail(allocation != NULL);
554
555         prefs_common.sendwin_width = allocation->width;
556         prefs_common.sendwin_height = allocation->height;
557 }
558
559 static SendProgressDialog *send_progress_dialog_create(void)
560 {
561         SendProgressDialog *dialog;
562         ProgressDialog *progress;
563         static GdkGeometry geometry;
564
565         dialog = g_new0(SendProgressDialog, 1);
566
567         progress = progress_dialog_create();
568         gtk_window_set_title(GTK_WINDOW(progress->window),
569                              _("Sending message"));
570         g_signal_connect(G_OBJECT(progress->showlog_btn), "clicked",
571                          G_CALLBACK(send_showlog_button_cb), dialog);
572         g_signal_connect(G_OBJECT(progress->cancel_btn), "clicked",
573                          G_CALLBACK(send_cancel_button_cb), dialog);
574         g_signal_connect(G_OBJECT(progress->window), "delete_event",
575                          G_CALLBACK(gtk_true), NULL);
576         gtk_window_set_modal(GTK_WINDOW(progress->window), TRUE);
577         g_signal_connect(G_OBJECT(progress->window), "size_allocate",
578                          G_CALLBACK(send_progress_dialog_size_allocate_cb), NULL);
579         manage_window_set_transient(GTK_WINDOW(progress->window));
580
581         progress_dialog_get_fraction(progress);
582
583         if (!geometry.min_height) {
584                 geometry.min_width = 460;
585                 geometry.min_height = 250;
586         }
587
588         gtk_window_set_geometry_hints(GTK_WINDOW(progress->window), NULL, &geometry,
589                                       GDK_HINT_MIN_SIZE);
590         gtk_widget_set_size_request(progress->window, prefs_common.sendwin_width,
591                                     prefs_common.sendwin_height);
592
593         if (!prefs_common.send_dialog_invisible) {
594                 gtk_widget_show_now(progress->window);
595         }
596         
597         dialog->dialog = progress;
598
599         return dialog;
600 }
601
602 static void send_progress_dialog_destroy(SendProgressDialog *dialog)
603 {
604         cm_return_if_fail(dialog != NULL);
605         if (!prefs_common.send_dialog_invisible) {
606                 progress_dialog_destroy(dialog->dialog);
607         }
608         g_free(dialog);
609         dialog = NULL;
610 }
611
612 static void send_showlog_button_cb(GtkWidget *widget, gpointer data)
613 {
614         MainWindow *mainwin = mainwindow_get_mainwindow();
615
616         log_window_show(mainwin->logwin);
617 }
618
619 static void send_cancel_button_cb(GtkWidget *widget, gpointer data)
620 {
621         SendProgressDialog *dialog = (SendProgressDialog *)data;
622         statusbar_progress_all(0,0,0);
623
624         dialog->cancelled = TRUE;
625 }
626
627 static void send_put_error(Session *session)
628 {
629         gchar *msg;
630         gchar *log_msg = NULL;
631         gchar *err_msg = NULL;
632
633         msg = SMTP_SESSION(session)->error_msg;
634
635         switch (SMTP_SESSION(session)->error_val) {
636         case SM_ERROR:
637         case SM_UNRECOVERABLE:
638                 log_msg = _("Error occurred while sending the message.");
639                 if (msg)
640                         err_msg = g_strdup_printf
641                                 (_("Error occurred while sending the message:\n%s"),
642                                  msg);
643                 else
644                         err_msg = g_strdup(log_msg);
645                 break;
646         case SM_AUTHFAIL:
647                 log_msg = _("Authentication failed.");
648                 if (msg)
649                         err_msg = g_strdup_printf
650                                 (_("Authentication failed:\n%s"), msg);
651                 else
652                         err_msg = g_strdup(log_msg);
653                 break;
654         default:
655                 switch (session->state) {
656                 case SESSION_ERROR:
657                         log_msg =
658                                 _("Error occurred while sending the message.");
659                         err_msg = g_strdup(log_msg);
660                         break;
661                 case SESSION_EOF:
662                         log_msg = _("Connection closed by the remote host.");
663                         err_msg = g_strdup(log_msg);
664                         break;
665                 case SESSION_TIMEOUT:
666                         log_msg = _("Session timed out. You may be able to "
667                                     "recover by increasing the timeout value in "
668                                     "Preferences/Other/Miscellaneous.");
669                         err_msg = g_strdup(log_msg);
670                         break;
671                 default:
672                         break;
673                 }
674                 break;
675         }
676
677         if (err_msg) {
678                 log_error(LOG_PROTOCOL, "%s\n", err_msg);
679                 g_free(err_msg);
680         } else {
681                 if (log_msg)
682                         log_warning(LOG_PROTOCOL, "%s\n", log_msg);
683         }
684 }
685