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