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