Use account ID instead of name in passwordstorerc.
[claws.git] / src / send_message.c
index e76794d70f41b015db1ecaf91c1a18a5c18149bb..75bdd2016c184e825abc4b8157c35cc7ffcb3f88 100644 (file)
@@ -54,6 +54,7 @@
 #include "gtkutils.h"
 #include "inc.h"
 #include "log.h"
+#include "passwordstore.h"
 
 typedef struct _SendProgressDialog     SendProgressDialog;
 
@@ -231,22 +232,34 @@ gint send_message_smtp_full(PrefsAccount *ac_prefs, GSList *to_list, FILE *fp, g
         * because it's editable. */
 
        fp_pos = ftell(fp);
-       tmp_msginfo = procheader_parse_stream(fp, flags, FALSE, FALSE);
-       fseek(fp, fp_pos, SEEK_SET);
-       
-       if (tmp_msginfo && tmp_msginfo->from) {
+       if (fp_pos < 0) {
+               perror("ftell");
+               return -1;
+       }
+       tmp_msginfo = procheader_parse_stream(fp, flags, TRUE, FALSE);
+       if (fseek(fp, fp_pos, SEEK_SET) < 0) {
+               perror("fseek");
+               return -1;
+       }
+
+       if (tmp_msginfo && tmp_msginfo->extradata && tmp_msginfo->extradata->resent_from) {
+               strncpy2(spec_from, tmp_msginfo->extradata->resent_from, BUFFSIZE-1);
+               extract_address(spec_from);
+       } else if (tmp_msginfo && tmp_msginfo->from) {
                strncpy2(spec_from, tmp_msginfo->from, BUFFSIZE-1);
                extract_address(spec_from);
        } else {
                strncpy2(spec_from, ac_prefs->address, BUFFSIZE-1);
        }
        if (tmp_msginfo) {
-               procmsg_msginfo_free(tmp_msginfo);
+               procmsg_msginfo_free(&tmp_msginfo);
        }
 
        if (!ac_prefs->session) {
                /* we can't reuse a previously initialised session */
                session = smtp_session_new(ac_prefs);
+               session->ssl_cert_auto_accept = ac_prefs->ssl_certs_auto_accept;
+
                smtp_session = SMTP_SESSION(session);
 
                if (ac_prefs->set_domain && ac_prefs->domain && strlen(ac_prefs->domain)) {
@@ -255,14 +268,45 @@ gint send_message_smtp_full(PrefsAccount *ac_prefs, GSList *to_list, FILE *fp, g
                        smtp_session->hostname = NULL;
                }
 
+#ifdef 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;
+               if (ac_prefs->set_gnutls_priority && ac_prefs->gnutls_priority &&
+                   strlen(ac_prefs->gnutls_priority))
+                       session->gnutls_priority = g_strdup(ac_prefs->gnutls_priority);
+#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 Claws Mail. \n\n"
+                                 "Do you want to continue connecting to this "
+                                 "server? The communication would not be "
+                                 "secure."),
+                                 GTK_STOCK_CANCEL, _("Con_tinue connecting"),
+                                 NULL, FALSE, NULL, ALERT_WARNING,
+                                 G_ALERTDEFAULT) != G_ALERTALTERNATE) {
+                               session_destroy(session);
+                               return -1;
+                       }
+               }
+               port = ac_prefs->set_smtpport ? ac_prefs->smtpport : SMTP_PORT;
+#endif
+
                if (ac_prefs->use_smtp_auth) {
                        smtp_session->forced_auth_type = ac_prefs->smtp_auth_type;
                        if (ac_prefs->smtp_userid && strlen(ac_prefs->smtp_userid)) {
                                smtp_session->user = g_strdup(ac_prefs->smtp_userid);
-                               if (ac_prefs->smtp_passwd)
-                                       smtp_session->pass =
-                                               g_strdup(ac_prefs->smtp_passwd);
-                               else {
+                               if (password_get(smtp_session->user,
+                                                       ac_prefs->smtp_server, "smtp", port,
+                                                       &(smtp_session->pass))) {
+                                       /* NOP */;
+                               } else if ((smtp_session->pass =
+                                               passwd_store_get_account(ac_prefs->account_id,
+                                                               PWS_ACCOUNT_SEND)) == NULL) {
                                        smtp_session->pass =
                                                input_dialog_query_password_keep
                                                        (ac_prefs->smtp_server,
@@ -275,9 +319,12 @@ gint send_message_smtp_full(PrefsAccount *ac_prefs, GSList *to_list, FILE *fp, g
                                }
                        } else {
                                smtp_session->user = g_strdup(ac_prefs->userid);
-                               if (ac_prefs->passwd)
-                                       smtp_session->pass = g_strdup(ac_prefs->passwd);
-                               else {
+                               if (password_get(smtp_session->user,
+                                                       ac_prefs->smtp_server, "smtp", port,
+                                                       &(smtp_session->pass))) {
+                                       /* NOP */;
+                               } else if ((smtp_session->pass = passwd_store_get_account(
+                                                       ac_prefs->account_id, PWS_ACCOUNT_RECV)) == NULL) {
                                        smtp_session->pass =
                                                input_dialog_query_password_keep
                                                        (ac_prefs->smtp_server,
@@ -294,34 +341,6 @@ gint send_message_smtp_full(PrefsAccount *ac_prefs, GSList *to_list, FILE *fp, g
                        smtp_session->pass = NULL;
                }
 
-#ifdef 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;
-               if (ac_prefs->set_gnutls_priority && ac_prefs->gnutls_priority &&
-                   strlen(ac_prefs->gnutls_priority))
-                       session->gnutls_priority = g_strdup(ac_prefs->gnutls_priority);
-#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 Claws Mail. \n\n"
-                                 "Do you want to continue connecting to this "
-                                 "server? The communication would not be "
-                                 "secure."),
-                                 GTK_STOCK_CANCEL, _("Con_tinue connecting"),
-                                 NULL, FALSE, NULL, ALERT_WARNING,
-                                 G_ALERTDEFAULT) != G_ALERTALTERNATE) {
-                               session_destroy(session);
-                               return -1;
-                       }
-               }
-               port = ac_prefs->set_smtpport ? ac_prefs->smtpport : SMTP_PORT;
-#endif
-
                send_dialog = send_progress_dialog_create();
                send_dialog->session = session;
                smtp_session->dialog = send_dialog;
@@ -462,7 +481,6 @@ static gint send_recv_message(Session *session, const gchar *msg, gpointer data)
 
        switch (smtp_session->state) {
        case SMTP_READY:
-       case SMTP_CONNECTED:
                return 0;
        case SMTP_HELO:
                g_snprintf(buf, sizeof(buf), _("Sending HELO..."));
@@ -496,7 +514,7 @@ static gint send_recv_message(Session *session, const gchar *msg, gpointer data)
                state_str = _("Quitting");
                break;
        case SMTP_ERROR:
-               g_warning("send: error: %s\n", msg);
+               g_warning("send: error: %s", msg);
                return 0;
        default:
                return 0;