Removed a superfluous debug_print() call.
[claws.git] / src / compose.c
index f7d18a04f5548b7fdbd56a7aafc55363f7bbe2d9..afe00fc351c9fc931b5bd1a6d2b87572f530a12f 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2015 Hiroyuki Yamamoto and the Claws Mail team
+ * Copyright (C) 1999-2016 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
@@ -14,7 +14,6 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
  */
 
 #ifdef HAVE_CONFIG_H
@@ -1535,7 +1534,7 @@ static void compose_extract_original_charset(Compose *compose)
                                g_strdup(procmime_mimeinfo_get_parameter(
                                                partinfo, "charset"));
                }
-               procmime_mimeinfo_free_all(mimeinfo);
+               procmime_mimeinfo_free_all(&mimeinfo);
        }
 }
 
@@ -2972,27 +2971,29 @@ static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
        if (compose->mode == COMPOSE_REEDIT) {
                if (msginfo->inreplyto && *msginfo->inreplyto)
                        compose->inreplyto = g_strdup(msginfo->inreplyto);
-               return 0;
-       }
 
-       if (msginfo->msgid && *msginfo->msgid)
-               compose->inreplyto = g_strdup(msginfo->msgid);
-
-       if (!compose->references) {
-               if (msginfo->msgid && *msginfo->msgid) {
-                       if (msginfo->inreplyto && *msginfo->inreplyto)
-                               compose->references =
-                                       g_strdup_printf("<%s>\n\t<%s>",
-                                                       msginfo->inreplyto,
-                                                       msginfo->msgid);
-                       else
+               if (msginfo->msgid && *msginfo->msgid)
+                       compose->msgid = g_strdup(msginfo->msgid);
+       } else {
+               if (msginfo->msgid && *msginfo->msgid)
+                       compose->inreplyto = g_strdup(msginfo->msgid);
+
+               if (!compose->references) {
+                       if (msginfo->msgid && *msginfo->msgid) {
+                               if (msginfo->inreplyto && *msginfo->inreplyto)
+                                       compose->references =
+                                               g_strdup_printf("<%s>\n\t<%s>",
+                                                               msginfo->inreplyto,
+                                                               msginfo->msgid);
+                               else
+                                       compose->references =
+                                               g_strconcat("<", msginfo->msgid, ">",
+                                                           NULL);
+                       } else if (msginfo->inreplyto && *msginfo->inreplyto) {
                                compose->references =
-                                       g_strconcat("<", msginfo->msgid, ">",
+                                       g_strconcat("<", msginfo->inreplyto, ">",
                                                    NULL);
-               } else if (msginfo->inreplyto && *msginfo->inreplyto) {
-                       compose->references =
-                               g_strconcat("<", msginfo->inreplyto, ">",
-                                           NULL);
+                       }
                }
        }
 
@@ -3351,6 +3352,10 @@ static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
                                          ? msginfo->from :
                                          msginfo->to,
                                          COMPOSE_TO, PREF_NONE);
+                               if (compose->replyto)
+                                               compose_entry_append(compose,
+                                                       compose->replyto,
+                                                       COMPOSE_CC, PREF_NONE);
                        } else {
                                if (!folder_has_parent_of_type(msginfo->folder, F_QUEUE) &&
                                    !folder_has_parent_of_type(msginfo->folder, F_OUTBOX) &&
@@ -3396,6 +3401,11 @@ static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
                                 compose->followup_to ? compose->followup_to :
                                 compose->newsgroups ? compose->newsgroups : "",
                                 COMPOSE_NEWSGROUPS, PREF_NONE);
+
+                       compose_entry_append
+                               (compose,
+                                msginfo->cc ? msginfo->cc : "",
+                                COMPOSE_CC, PREF_NONE);
                } 
                else 
                        compose_entry_append
@@ -3877,7 +3887,7 @@ static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
        if (!mimeinfo) return;
 
        if (mimeinfo->node->children == NULL) {
-               procmime_mimeinfo_free_all(mimeinfo);
+               procmime_mimeinfo_free_all(&mimeinfo);
                return;
        }
 
@@ -3947,7 +3957,7 @@ static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
                g_free(outfile);
                NEXT_PART_NOT_CHILD(child);
        }
-       procmime_mimeinfo_free_all(mimeinfo);
+       procmime_mimeinfo_free_all(&mimeinfo);
 }
 
 #undef NEXT_PART_NOT_CHILD
@@ -5374,7 +5384,10 @@ static gint compose_redirect_write_headers(Compose *compose, FILE *fp)
        cm_return_val_if_fail(compose->account->address != NULL, -1);
 
        /* Resent-Date */
-       get_rfc822_date(buf, sizeof(buf));
+       if (prefs_common.hide_timezone)
+               get_rfc822_date_hide_tz(buf, sizeof(buf));
+       else
+               get_rfc822_date(buf, sizeof(buf));
        err |= (fprintf(fp, "Resent-Date: %s\n", buf) < 0);
 
        /* Resent-From */
@@ -5400,27 +5413,12 @@ static gint compose_redirect_write_headers(Compose *compose, FILE *fp)
        }
 
        /* Resent-Message-ID */
-       if (compose->account->set_domain && compose->account->domain) {
-               g_snprintf(buf, sizeof(buf), "%s", compose->account->domain); 
-       } else if (!strncmp(get_domain_name(), "localhost", strlen("localhost"))) {
-               g_snprintf(buf, sizeof(buf), "%s", 
-                       strchr(compose->account->address, '@') ?
-                               strchr(compose->account->address, '@')+1 :
-                               compose->account->address);
-       } else {
-               g_snprintf(buf, sizeof(buf), "%s", "");
-       }
-
        if (compose->account->gen_msgid) {
-               gchar *addr = NULL;
-               if (compose->account->msgid_with_addr) {
-                       addr = compose->account->address;
-               }
-               generate_msgid(buf, sizeof(buf), addr);
-               err |= (fprintf(fp, "Resent-Message-ID: <%s>\n", buf) < 0);
+               gchar *addr = prefs_account_generate_msgid(compose->account);
+               err |= (fprintf(fp, "Resent-Message-ID: <%s>\n", addr) < 0);
                if (compose->msgid)
                        g_free(compose->msgid);
-               compose->msgid = g_strdup(buf);
+               compose->msgid = addr;
        } else {
                compose->msgid = NULL;
        }
@@ -5538,9 +5536,17 @@ static gint compose_write_to_file(Compose *compose, FILE *fp, gint action, gbool
        gchar *from_name = NULL;
        FolderItem *outbox;
 
-       if (action == COMPOSE_WRITE_FOR_SEND)
+       if (action == COMPOSE_WRITE_FOR_SEND) {
                attach_parts = TRUE;
 
+               /* We're sending the message, generate a Message-ID
+                * if necessary. */
+               if (compose->msgid == NULL &&
+                               compose->account->gen_msgid) {
+                       compose->msgid = prefs_account_generate_msgid(compose->account);
+               }
+       }
+
        /* create message MimeInfo */
        mimemsg = procmime_mimeinfo_new();
         mimemsg->type = MIMETYPE_MESSAGE;
@@ -5642,7 +5648,7 @@ static gint compose_write_to_file(Compose *compose, FILE *fp, gint action, gbool
        }
        g_free(chars);
 
-       if (encoding == ENC_8BIT || encoding == ENC_7BIT) {
+       if (prefs_common.rewrite_first_from && (encoding == ENC_8BIT || encoding == ENC_7BIT)) {
                if (!strncmp(buf, "From ", sizeof("From ")-1) ||
                    strstr(buf, "\nFrom ") != NULL) {
                        encoding = ENC_QUOTED_PRINTABLE;
@@ -5795,7 +5801,7 @@ static gint compose_write_to_file(Compose *compose, FILE *fp, gint action, gbool
 
        procmime_write_mimeinfo(mimemsg, fp);
        
-       procmime_mimeinfo_free_all(mimemsg);
+       procmime_mimeinfo_free_all(&mimemsg);
 
        return 0;
 }
@@ -6301,7 +6307,7 @@ static gchar *compose_quote_list_of_addresses(gchar *str)
                                faddr = g_strconcat(name, addr, NULL);
                                g_free(name);
                                g_free(addr);
-                               debug_print("new auto-quoted address: '%s'", faddr);
+                               debug_print("new auto-quoted address: '%s'\n", faddr);
                        }
                }
                if (result == NULL)
@@ -6451,7 +6457,10 @@ static gchar *compose_get_header(Compose *compose)
        header = g_string_sized_new(64);
 
        /* Date */
-       get_rfc822_date(buf, sizeof(buf));
+       if (prefs_common.hide_timezone)
+               get_rfc822_date_hide_tz(buf, sizeof(buf));
+       else
+               get_rfc822_date(buf, sizeof(buf));
        g_string_append_printf(header, "Date: %s\n", buf);
 
        /* From */
@@ -6547,29 +6556,9 @@ static gchar *compose_get_header(Compose *compose)
        g_free(str);
 
        /* Message-ID */
-       if (compose->account->set_domain && compose->account->domain) {
-               g_snprintf(buf, sizeof(buf), "%s", compose->account->domain); 
-       } else if (!strncmp(get_domain_name(), "localhost", strlen("localhost"))) {
-               g_snprintf(buf, sizeof(buf), "%s", 
-                       strchr(compose->account->address, '@') ?
-                               strchr(compose->account->address, '@')+1 :
-                               compose->account->address);
-       } else {
-               g_snprintf(buf, sizeof(buf), "%s", "");
-       }
-       
-       if (compose->account->gen_msgid) {
-               gchar *addr = NULL;
-               if (compose->account->msgid_with_addr) {
-                       addr = compose->account->address;
-               }
-               generate_msgid(buf, sizeof(buf), addr);
-               g_string_append_printf(header, "Message-ID: <%s>\n", buf);
-               if (compose->msgid)
-                       g_free(compose->msgid);
-               compose->msgid = g_strdup(buf);
-       } else {
-               compose->msgid = NULL;
+       if (compose->msgid != NULL && strlen(compose->msgid) > 0) {
+               g_string_append_printf(header, "Message-ID: <%s>\n",
+                               compose->msgid);
        }
 
        if (compose->remove_references == FALSE) {
@@ -10321,7 +10310,7 @@ static void compose_attach_cb(GtkAction *action, gpointer data)
         * which unsets it (via focus_out_event callback on compose window). */
        manage_window_focus_in(compose->window, NULL, NULL);
 
-       file_list = filesel_select_multiple_files_open(_("Select file"));
+       file_list = filesel_select_multiple_files_open(_("Select file"), NULL);
 
        if (file_list) {
                compose_attach_from_list(compose, file_list, TRUE);
@@ -10335,7 +10324,7 @@ static void compose_insert_file_cb(GtkAction *action, gpointer data)
        GList *file_list;
        gint files_inserted = 0;
 
-       file_list = filesel_select_multiple_files_open(_("Select file"));
+       file_list = filesel_select_multiple_files_open(_("Select file"), NULL);
 
        if (file_list) {
                GList *tmp;
@@ -10531,6 +10520,12 @@ static void compose_ext_editor_cb(GtkAction *action, gpointer data)
 {
        Compose *compose = (Compose *)data;
 
+#ifdef G_OS_UNIX
+       if (compose->exteditor_tag != -1) {
+               debug_print("ignoring open external editor: external editor still open\n");
+               return;
+       }
+#endif
        compose_exec_ext_editor(compose);
 }