Remove dead code, this changed signal doesn't exist and we've also
[claws.git] / src / compose.c
index ee9ce30e766eaee9c578eb16b98be9990cd413d1..b085beba59fc770db2eea549d22caec2cd9d737d 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
@@ -377,8 +376,6 @@ static void compose_notebook_size_alloc (GtkNotebook *notebook,
 static gboolean compose_edit_size_alloc (GtkEditable   *widget,
                                         GtkAllocation  *allocation,
                                         GtkSHRuler     *shruler);
-static void account_activated          (GtkComboBox *optmenu,
-                                        gpointer        data);
 static void attach_selected            (GtkTreeView    *tree_view, 
                                         GtkTreePath    *tree_path,
                                         GtkTreeViewColumn *column, 
@@ -2972,27 +2969,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 +3350,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 +3399,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
@@ -5374,7 +5382,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 +5411,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 +5534,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 +5646,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;
@@ -5665,8 +5669,12 @@ static gint compose_write_to_file(Compose *compose, FILE *fp, gint action, gbool
            privacy_system_can_sign(compose->privacy_system)) {
                encoding = ENC_QUOTED_PRINTABLE;
        }
-       
+
+#ifdef G_OS_WIN32
+       debug_print("main text: %Id bytes encoded as %s in %d\n",
+#else
        debug_print("main text: %zd bytes encoded as %s in %d\n",
+#endif
                strlen(buf), out_codeset, encoding);
 
        /* check for line length limit */
@@ -6301,7 +6309,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 +6459,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 +6558,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) {
@@ -8170,9 +8161,6 @@ static GtkWidget *compose_account_option_menu_create(Compose *compose)
 
        gtk_combo_box_set_active(GTK_COMBO_BOX(optmenu), def_menu);
 
-       g_signal_connect(G_OBJECT(optmenu), "changed",
-                       G_CALLBACK(account_activated),
-                       compose);
        g_signal_connect(G_OBJECT(from_name), "populate-popup",
                         G_CALLBACK(compose_entry_popup_extend),
                         NULL);
@@ -9740,121 +9728,6 @@ typedef struct {
        gboolean                entry_marked;
 } HeaderEntryState;
 
-static void account_activated(GtkComboBox *optmenu, gpointer data)
-{
-       Compose *compose = (Compose *)data;
-
-       PrefsAccount *ac;
-       gchar *folderidentifier;
-       gint account_id = 0;
-       GtkTreeModel *menu;
-       GtkTreeIter iter;
-       GSList *list, *saved_list = NULL;
-       HeaderEntryState *state;
-       GtkRcStyle *style = NULL;
-#if !GTK_CHECK_VERSION(3, 0, 0)
-       static GdkColor yellow;
-       static gboolean color_set = FALSE;
-#else
-       static GdkColor yellow = { (guint32)0, (guint32)0xf5, (guint32)0xf6, (guint32)0xbe };
-#endif
-
-       /* Get ID of active account in the combo box */
-       menu = gtk_combo_box_get_model(optmenu);
-       cm_return_if_fail(gtk_combo_box_get_active_iter(optmenu, &iter));
-       gtk_tree_model_get(menu, &iter, 1, &account_id, -1);
-
-       ac = account_find_from_id(account_id);
-       cm_return_if_fail(ac != NULL);
-
-       if (ac != compose->account) {
-               compose_select_account(compose, ac, FALSE);
-
-               for (list = compose->header_list; list; list = list->next) {
-                       ComposeHeaderEntry *hentry=(ComposeHeaderEntry *)list->data;
-                       
-                       if (hentry->type == PREF_ACCOUNT || !list->next) {
-                               compose_destroy_headerentry(compose, hentry);
-                               continue;
-                       }
-                       
-                       state = g_malloc0(sizeof(HeaderEntryState));
-                       state->header = gtk_editable_get_chars(GTK_EDITABLE(
-                                       gtk_bin_get_child(GTK_BIN(hentry->combo))), 0, -1);
-                       state->entry = gtk_editable_get_chars(
-                                       GTK_EDITABLE(hentry->entry), 0, -1);
-                       state->type = hentry->type;
-                               
-#if !GTK_CHECK_VERSION(3, 0, 0)
-                       if (!color_set) {
-                               gdk_color_parse("#f5f6be", &yellow);
-                               color_set = gdk_colormap_alloc_color(
-                                                       gdk_colormap_get_system(),
-                                                       &yellow, FALSE, TRUE);
-                       }
-#endif
-                               
-                       style = gtk_widget_get_modifier_style(hentry->entry);
-                       state->entry_marked = gdk_color_equal(&yellow,
-                                               &style->base[GTK_STATE_NORMAL]);
-
-                       saved_list = g_slist_append(saved_list, state);
-                       compose_destroy_headerentry(compose, hentry);
-               }
-
-               compose->header_last = NULL;
-               g_slist_free(compose->header_list);
-               compose->header_list = NULL;
-               compose->header_nextrow = 1;
-               compose_create_header_entry(compose);
-               
-               if (ac->set_autocc && ac->auto_cc)
-                       compose_entry_append(compose, ac->auto_cc,
-                                               COMPOSE_CC, PREF_ACCOUNT);
-
-               if (ac->set_autobcc && ac->auto_bcc) 
-                       compose_entry_append(compose, ac->auto_bcc,
-                                               COMPOSE_BCC, PREF_ACCOUNT);
-       
-               if (ac->set_autoreplyto && ac->auto_replyto)
-                       compose_entry_append(compose, ac->auto_replyto,
-                                               COMPOSE_REPLYTO, PREF_ACCOUNT);
-               
-               for (list = saved_list; list; list = list->next) {
-                       state = (HeaderEntryState *) list->data;
-                       
-                       compose_add_header_entry(compose, state->header,
-                                               state->entry, state->type);
-                       if (state->entry_marked)
-                               compose_entry_mark_default_to(compose, state->entry);
-                       
-                       g_free(state->header);  
-                       g_free(state->entry);
-                       g_free(state);
-               }
-               g_slist_free(saved_list);
-               
-               combobox_select_by_data(GTK_COMBO_BOX(compose->header_last->combo),
-                                       (ac->protocol == A_NNTP) ? 
-                                       COMPOSE_NEWSGROUPS : COMPOSE_TO);
-       }
-
-       /* Set message save folder */
-       if (account_get_special_folder(compose->account, F_OUTBOX)) {
-               gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), prefs_common.savemsg);
-       }
-       g_signal_connect(G_OBJECT(compose->savemsg_checkbtn), "toggled",
-                        G_CALLBACK(compose_savemsg_checkbtn_cb), compose);
-                          
-       compose_set_save_to(compose, NULL);
-       if (account_get_special_folder(compose->account, F_OUTBOX)) {
-               folderidentifier = folder_item_get_identifier(account_get_special_folder
-                                 (compose->account, F_OUTBOX));
-               compose_set_save_to(compose, folderidentifier);
-               g_free(folderidentifier);
-       }
-}
-
 static void attach_selected(GtkTreeView *tree_view, GtkTreePath *tree_path,
                            GtkTreeViewColumn *column, Compose *compose)
 {
@@ -10321,7 +10194,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 +10208,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 +10404,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);
 }
 
@@ -11352,6 +11231,8 @@ static void compose_insert_drag_received_cb (GtkWidget          *widget,
        Compose *compose = (Compose *)user_data;
        GList *list, *tmp;
        GdkAtom type;
+       guint num_files;
+       gchar *msg;
 
        /* strangely, testing data->type == gdk_atom_intern("text/uri-list", TRUE)
         * does not work */
@@ -11361,6 +11242,7 @@ static void compose_insert_drag_received_cb (GtkWidget          *widget,
                const gchar* ddata = (const gchar *)gtk_selection_data_get_data(data);
 
                list = uri_list_extract_filenames(ddata);
+               num_files = g_list_length(list);
                if (list == NULL && strstr(ddata, "://")) {
                        /* Assume a list of no files, and data has ://, is a remote link */
                        gchar *tmpdata = g_strstrip(g_strdup(ddata));
@@ -11376,11 +11258,18 @@ static void compose_insert_drag_received_cb (GtkWidget                *widget,
                }
                switch (prefs_common.compose_dnd_mode) {
                        case COMPOSE_DND_ASK:
-                               val = alertpanel_full(_("Insert or attach?"),
-                                        _("Do you want to insert the contents of the file(s) "
-                                          "into the message body, or attach it to the email?"),
+                               msg = g_strdup_printf(
+                                               ngettext(
+                                                       "Do you want to insert the contents of the file "
+                                                       "into the message body, or attach it to the email?",
+                                                       "Do you want to insert the contents of the %d files "
+                                                       "into the message body, or attach them to the email?",
+                                                       num_files),
+                                               num_files);
+                               val = alertpanel_full(_("Insert or attach?"), msg,
                                          GTK_STOCK_CANCEL, g_strconcat("+", _("_Insert"), NULL), _("_Attach"),
                                          TRUE, NULL, ALERT_QUESTION, G_ALERTALTERNATE);
+                               g_free(msg);
                                break;
                        case COMPOSE_DND_INSERT:
                                val = G_ALERTALTERNATE;
@@ -11739,9 +11628,6 @@ static PrefsAccount *compose_guess_forward_account_from_msginfo(MsgInfo *msginfo
        if (msginfo->folder->prefs->enable_default_account)
                account = account_find_from_id(msginfo->folder->prefs->default_account);
                
-       if (!account) 
-               account = msginfo->folder->folder->account;
-               
        if (!account && msginfo->to && prefs_common.forward_account_autosel) {
                gchar *to;
                Xstrdup_a(to, msginfo->to, return NULL);
@@ -11768,6 +11654,9 @@ static PrefsAccount *compose_guess_forward_account_from_msginfo(MsgInfo *msginfo
                        account = account_find_from_address(buf, FALSE);
                 }
        }
+
+       if (!account)
+               account = msginfo->folder->folder->account;
        
        return account;
 }