2008-09-16 [colin] 3.5.0cvs109
[claws.git] / src / send_message.c
index 6db9a1d96718b20894f45c3f4fa65387cbd282c0..ea5ac42caf309ac69159c621277ab527fe4d6ad9 100644 (file)
@@ -1,10 +1,10 @@
 /*
  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2006 Hiroyuki Yamamoto and the Sylpheed-Claws team
+ * Copyright (C) 1999-2007 Hiroyuki Yamamoto and the Claws Mail team
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * the Free Software Foundation; either version 3 of the License, or
  * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
@@ -13,8 +13,8 @@
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * 
  */
 
 #ifdef HAVE_CONFIG_H
@@ -25,9 +25,7 @@
 
 #include <glib.h>
 #include <glib/gi18n.h>
-#include <gtk/gtkmain.h>
-#include <gtk/gtksignal.h>
-#include <gtk/gtkwindow.h>
+#include <gtk/gtk.h>
 #include <stdio.h>
 #include <string.h>
 #include <signal.h>
@@ -134,7 +132,7 @@ gint send_message_local(const gchar *command, FILE *fp)
        g_return_val_if_fail(command != NULL, -1);
        g_return_val_if_fail(fp != NULL, -1);
 
-       log_message(_("Sending message using command: %s\n"), command);
+       log_message(LOG_PROTOCOL, _("Sending message using command: %s\n"), command);
 
        argv = strsplit_with_quote(command, " ", 0);
 
@@ -149,7 +147,7 @@ gint send_message_local(const gchar *command, FILE *fp)
                                     NULL) == FALSE) {
                g_snprintf(buf, sizeof(buf),
                           _("Couldn't execute command: %s"), command);
-               log_warning("%s\n", buf);
+               log_warning(LOG_PROTOCOL, "%s\n", buf);
                alertpanel_error("%s", buf);
                g_strfreev(argv);
                return -1;
@@ -185,7 +183,7 @@ gint send_message_local(const gchar *command, FILE *fp)
                g_snprintf(buf, sizeof(buf),
                           _("Error occurred while executing command: %s"),
                           command);
-               log_warning("%s\n", buf);
+               log_warning(LOG_PROTOCOL, "%s\n", buf);
                alertpanel_error("%s", buf);
                return -1;
        }
@@ -232,7 +230,7 @@ gint send_message_smtp_full(PrefsAccount *ac_prefs, GSList *to_list, FILE *fp, g
 
        if (!ac_prefs->session) {
                /* we can't reuse a previously initialised session */
-               session = smtp_session_new();
+               session = smtp_session_new(ac_prefs);
                smtp_session = SMTP_SESSION(session);
 
                if (ac_prefs->set_domain && ac_prefs->domain && strlen(ac_prefs->domain)) {
@@ -248,39 +246,31 @@ gint send_message_smtp_full(PrefsAccount *ac_prefs, GSList *to_list, FILE *fp, g
                                if (ac_prefs->smtp_passwd)
                                        smtp_session->pass =
                                                g_strdup(ac_prefs->smtp_passwd);
-                               else if (ac_prefs->tmp_smtp_pass)
-                                       smtp_session->pass =
-                                               g_strdup(ac_prefs->tmp_smtp_pass);
                                else {
                                        smtp_session->pass =
-                                               input_dialog_query_password
+                                               input_dialog_query_password_keep
                                                        (ac_prefs->smtp_server,
-                                                        smtp_session->user);
+                                                        smtp_session->user,
+                                                        &(ac_prefs->session_smtp_passwd));
                                        if (!smtp_session->pass) {
                                                session_destroy(session);
                                                return -1;
                                        }
-                                       ac_prefs->tmp_smtp_pass =
-                                               g_strdup(smtp_session->pass);
                                }
                        } else {
                                smtp_session->user = g_strdup(ac_prefs->userid);
                                if (ac_prefs->passwd)
                                        smtp_session->pass = g_strdup(ac_prefs->passwd);
-                               else if (ac_prefs->tmp_pass)
-                                       smtp_session->pass =
-                                               g_strdup(ac_prefs->tmp_pass);
                                else {
                                        smtp_session->pass =
-                                               input_dialog_query_password
+                                               input_dialog_query_password_keep
                                                        (ac_prefs->smtp_server,
-                                                        smtp_session->user);
+                                                        smtp_session->user,
+                                                        &(ac_prefs->session_smtp_passwd));
                                        if (!smtp_session->pass) {
                                                session_destroy(session);
                                                return -1;
                                        }
-                                       ac_prefs->tmp_pass =
-                                               g_strdup(smtp_session->pass);
                                }
                        }
                } else {
@@ -288,18 +278,18 @@ gint send_message_smtp_full(PrefsAccount *ac_prefs, GSList *to_list, FILE *fp, g
                        smtp_session->pass = NULL;
                }
 
-       #if USE_OPENSSL
+#if (defined(USE_OPENSSL) || defined (USE_GNUTLS))
                port = ac_prefs->set_smtpport ? ac_prefs->smtpport :
                        ac_prefs->ssl_smtp == SSL_TUNNEL ? SSMTP_PORT : SMTP_PORT;
                session->ssl_type = ac_prefs->ssl_smtp;
                if (ac_prefs->ssl_smtp != SSL_NONE)
                        session->nonblocking = ac_prefs->use_nonblocking_ssl;
-       #else
+#else
                if (ac_prefs->ssl_smtp != SSL_NONE) {
                        if (alertpanel_full(_("Insecure connection"),
                                _("This connection is configured to be secured "
                                  "using SSL, but SSL is not available in this "
-                                 "build of Sylpheed-Claws. \n\n"
+                                 "build of Claws Mail. \n\n"
                                  "Do you want to continue connecting to this "
                                  "server? The communication would not be "
                                  "secure."),
@@ -311,7 +301,7 @@ gint send_message_smtp_full(PrefsAccount *ac_prefs, GSList *to_list, FILE *fp, g
                        }
                }
                port = ac_prefs->set_smtpport ? ac_prefs->smtpport : SMTP_PORT;
-       #endif
+#endif
 
                dialog = send_progress_dialog_create();
                dialog->session = session;
@@ -325,7 +315,7 @@ gint send_message_smtp_full(PrefsAccount *ac_prefs, GSList *to_list, FILE *fp, g
                    && (ac_prefs->protocol == A_APOP || ac_prefs->protocol == A_POP3)
                    && (time(NULL) - ac_prefs->last_pop_login_time) > (60 * ac_prefs->pop_before_smtp_timeout)) {
                        g_snprintf(buf, sizeof(buf), _("Doing POP before SMTP..."));
-                       log_message(buf);
+                       log_message(LOG_PROTOCOL, "%s\n", buf);
                        progress_dialog_set_label(dialog->dialog, buf);
                        progress_dialog_list_set_status(dialog->dialog, 0, _("POP before SMTP"));
                        GTK_EVENTS_FLUSH();
@@ -335,7 +325,7 @@ gint send_message_smtp_full(PrefsAccount *ac_prefs, GSList *to_list, FILE *fp, g
                g_snprintf(buf, sizeof(buf), _("Connecting to SMTP server: %s ..."),
                           ac_prefs->smtp_server);
                progress_dialog_set_label(dialog->dialog, buf);
-               log_message("%s\n", buf);
+               log_message(LOG_PROTOCOL, "%s\n", buf);
 
                session_set_recv_message_notify(session, send_recv_message, dialog);
                session_set_send_data_progressive_notify
@@ -383,21 +373,18 @@ gint send_message_smtp_full(PrefsAccount *ac_prefs, GSList *to_list, FILE *fp, g
                gtk_main_iteration();
 
        if (SMTP_SESSION(session)->error_val == SM_AUTHFAIL) {
-               if (ac_prefs->smtp_userid && ac_prefs->tmp_smtp_pass) {
-                       g_free(ac_prefs->tmp_smtp_pass);
-                       ac_prefs->tmp_smtp_pass = NULL;
-               } else if (ac_prefs->tmp_pass) {
-                       g_free(ac_prefs->tmp_pass);
-                       ac_prefs->tmp_pass = NULL;
+               if (ac_prefs->session_smtp_passwd) {
+                       g_free(ac_prefs->session_smtp_passwd);
+                       ac_prefs->session_smtp_passwd = NULL;
                }
                ret = -1;
        } else if (SMTP_SESSION(session)->state == SMTP_MAIL_SENT_OK) {
-               log_message("%s\n", _("Mail sent successfully."));
+               log_message(LOG_PROTOCOL, "%s\n", _("Mail sent successfully."));
                ret = 0;
        } else if (session->state == SESSION_EOF &&
                   SMTP_SESSION(session)->state == SMTP_QUIT) {
                /* consider EOF right after QUIT successful */
-               log_warning("%s\n", _("Connection closed by the remote host."));
+               log_warning(LOG_PROTOCOL, "%s\n", _("Connection closed by the remote host."));
                ret = 0;
        } else if (session->state == SESSION_ERROR ||
                   session->state == SESSION_EOF ||
@@ -435,7 +422,7 @@ gint send_message_smtp_full(PrefsAccount *ac_prefs, GSList *to_list, FILE *fp, g
                ac_prefs->session = SMTP_SESSION(session);
 
 
-       statusbar_pop_all();
+       statuswindow_pop_all();
        statusbar_verbosity_set(FALSE);
        return ret;
 }
@@ -461,12 +448,12 @@ static gint send_recv_message(Session *session, const gchar *msg, gpointer data)
        case SMTP_HELO:
                g_snprintf(buf, sizeof(buf), _("Sending HELO..."));
                state_str = _("Authenticating");
-               statusbar_print_all(_("Sending message..."));
+               statuswindow_print_all(_("Sending message..."));
                break;
        case SMTP_EHLO:
                g_snprintf(buf, sizeof(buf), _("Sending EHLO..."));
                state_str = _("Authenticating");
-               statusbar_print_all(_("Sending message..."));
+               statuswindow_print_all(_("Sending message..."));
                break;
        case SMTP_AUTH:
                g_snprintf(buf, sizeof(buf), _("Authenticating..."));
@@ -507,7 +494,8 @@ static gint send_send_data_progressive(Session *session, guint cur_len,
 {
        gchar buf[BUFFSIZE];
        SendProgressDialog *dialog = (SendProgressDialog *)data;
-
+       MainWindow *mainwin = mainwindow_get_mainwindow();
+       
        g_return_val_if_fail(dialog != NULL, -1);
 
        if (SMTP_SESSION(session)->state != SMTP_SEND_DATA &&
@@ -520,16 +508,26 @@ static gint send_send_data_progressive(Session *session, guint cur_len,
        progress_dialog_set_fraction
                (dialog->dialog, (total_len == 0) ? 0 : (gfloat)cur_len / (gfloat)total_len);
 
+       if (mainwin)
+               gtk_progress_bar_set_fraction
+                       (GTK_PROGRESS_BAR(mainwin->progressbar),
+                        (total_len == 0) ? 0 : (gfloat)cur_len / (gfloat)total_len);
+
        return 0;
 }
 
 static gint send_send_data_finished(Session *session, guint len, gpointer data)
 {
        SendProgressDialog *dialog = (SendProgressDialog *)data;
+       MainWindow *mainwin = mainwindow_get_mainwindow();
 
        g_return_val_if_fail(dialog != NULL, -1);
 
        send_send_data_progressive(session, len, len, dialog);
+       if (mainwin)
+               gtk_progress_bar_set_fraction
+                       (GTK_PROGRESS_BAR(mainwin->progressbar),(gfloat)0);
+
        return 0;
 }
 
@@ -574,7 +572,7 @@ static SendProgressDialog *send_progress_dialog_create(void)
        gtk_widget_set_size_request(progress->window, prefs_common.sendwin_width,
                                    prefs_common.sendwin_height);
 
-       if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS) {
+       if (!prefs_common.send_dialog_invisible) {
                gtk_widget_show_now(progress->window);
        }
        
@@ -586,7 +584,7 @@ static SendProgressDialog *send_progress_dialog_create(void)
 static void send_progress_dialog_destroy(SendProgressDialog *dialog)
 {
        g_return_if_fail(dialog != NULL);
-       if (prefs_common.send_dialog_mode == SEND_DIALOG_ALWAYS) {
+       if (!prefs_common.send_dialog_invisible) {
                progress_dialog_destroy(dialog->dialog);
        }
        g_free(dialog);
@@ -638,7 +636,9 @@ static void send_put_error(Session *session)
                        err_msg = g_strdup(log_msg);
                        break;
                case SESSION_TIMEOUT:
-                       log_msg = _("Session timed out.");
+                       log_msg = _("Session timed out. You may be able to "
+                                   "recover by increasing the timeout value in "
+                                   "Preferences/Other.");
                        err_msg = g_strdup(log_msg);
                        break;
                default:
@@ -648,11 +648,11 @@ static void send_put_error(Session *session)
        }
 
        if (err_msg) {
-               log_error("%s\n", err_msg);
+               log_error(LOG_PROTOCOL, "%s\n", err_msg);
                g_free(err_msg);
        } else {
                if (log_msg)
-                       log_warning("%s\n", log_msg);
+                       log_warning(LOG_PROTOCOL, "%s\n", log_msg);
        }
 }