Fix bug #2210, but not on Address Book
[claws.git] / src / compose.c
index f351d8fb2010406de61ce908668c22790a09ace4..1c8b05b7745e7726e016f6b4ef512bc9483753e3 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2012 Hiroyuki Yamamoto and the Claws Mail team
+ * Copyright (C) 1999-2013 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
@@ -930,11 +930,20 @@ static void compose_set_save_to(Compose *compose, const gchar *folderidentifier)
 {
        GtkEditable *entry;
        if (folderidentifier) {
+#if !GTK_CHECK_VERSION(2, 24, 0)
                combobox_unset_popdown_strings(GTK_COMBO_BOX(compose->savemsg_combo));
+#else
+               combobox_unset_popdown_strings(GTK_COMBO_BOX_TEXT(compose->savemsg_combo));
+#endif
                prefs_common.compose_save_to_history = add_history(
                                prefs_common.compose_save_to_history, folderidentifier);
+#if !GTK_CHECK_VERSION(2, 24, 0)
                combobox_set_popdown_strings(GTK_COMBO_BOX(compose->savemsg_combo),
                                prefs_common.compose_save_to_history);
+#else
+               combobox_set_popdown_strings(GTK_COMBO_BOX_TEXT(compose->savemsg_combo),
+                               prefs_common.compose_save_to_history);
+#endif
        }
 
        entry = GTK_EDITABLE(gtk_bin_get_child(GTK_BIN(compose->savemsg_combo)));
@@ -952,11 +961,20 @@ static gchar *compose_get_save_to(Compose *compose)
        result = gtk_editable_get_chars(entry, 0, -1);
        
        if (result) {
+#if !GTK_CHECK_VERSION(2, 24, 0)
                combobox_unset_popdown_strings(GTK_COMBO_BOX(compose->savemsg_combo));
+#else
+               combobox_unset_popdown_strings(GTK_COMBO_BOX_TEXT(compose->savemsg_combo));
+#endif
                prefs_common.compose_save_to_history = add_history(
                                prefs_common.compose_save_to_history, result);
+#if !GTK_CHECK_VERSION(2, 24, 0)
                combobox_set_popdown_strings(GTK_COMBO_BOX(compose->savemsg_combo),
                                prefs_common.compose_save_to_history);
+#else
+               combobox_set_popdown_strings(GTK_COMBO_BOX_TEXT(compose->savemsg_combo),
+                               prefs_common.compose_save_to_history);
+#endif
        }
        return result;
 }
@@ -984,8 +1002,15 @@ Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderI
                /* mailto defines a from, check if we can get account prefs from it,
                   if not, the account prefs will be guessed using other ways, but we'll keep
                   the from anyway */
-               if (mailto_from)
+               if (mailto_from) {
                        mailto_account = account_find_from_address(mailto_from, TRUE);
+                       if (mailto_account == NULL) {
+                               gchar *tmp_from;
+                               Xstrdup_a(tmp_from, mailto_from, return NULL);
+                               extract_address(tmp_from);
+                               mailto_account = account_find_from_address(tmp_from, TRUE);
+                       }
+               }
                if (mailto_account)
                        account = mailto_account;
        }
@@ -1260,12 +1285,11 @@ static void compose_force_encryption(Compose *compose, PrefsAccount *account,
        if (override_pref == FALSE && account->default_encrypt_reply == FALSE)
                return;
 
-       if (system)
-               privacy = system;
-       else if (account->default_privacy_system
-       &&  strlen(account->default_privacy_system)) {
+       if (account->default_privacy_system && strlen(account->default_privacy_system))
                privacy = account->default_privacy_system;
-       } else {
+       else if (system)
+               privacy = system;
+       else {
                GSList *privacy_avail = privacy_get_system_ids();
                if (privacy_avail && g_slist_length(privacy_avail)) {
                        privacy = (gchar *)(privacy_avail->data);
@@ -1291,12 +1315,11 @@ static void compose_force_signing(Compose *compose, PrefsAccount *account, const
 {
        const gchar *privacy = NULL;
 
-       if (system)
-               privacy = system;
-       else if (account->default_privacy_system
-       &&  strlen(account->default_privacy_system)) {
+       if (account->default_privacy_system && strlen(account->default_privacy_system))
                privacy = account->default_privacy_system;
-       } else {
+       else if (system)
+               privacy = system;
+       else {
                GSList *privacy_avail = privacy_get_system_ids();
                if (privacy_avail && g_slist_length(privacy_avail)) {
                        privacy = (gchar *)(privacy_avail->data);
@@ -3504,6 +3527,7 @@ static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *fi
        gboolean badtxt = FALSE;
        struct stat file_stat;
        int ret;
+       GString *file_contents = NULL;
 
        cm_return_val_if_fail(file != NULL, COMPOSE_INSERT_NO_FILE);
 
@@ -3563,6 +3587,7 @@ static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *fi
 
        cur_encoding = conv_get_locale_charset_str_no_utf8();
 
+       file_contents = g_string_new("");
        while (fgets(buf, sizeof(buf), fp) != NULL) {
                gchar *str;
 
@@ -3582,10 +3607,14 @@ static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *fi
                                if (str[len] == '\r') str[len] = '\n';
                }
 
-               gtk_text_buffer_insert(buffer, &iter, str, -1);
+               file_contents = g_string_append(file_contents, str);
                g_free(str);
        }
 
+       gtk_text_buffer_insert(buffer, &iter, file_contents->str, -1);
+       g_string_free(file_contents, TRUE);
+
+       compose_changed_cb(NULL, compose);
        g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
                                          G_CALLBACK(text_inserted),
                                          compose);
@@ -4969,9 +4998,9 @@ static gboolean compose_check_entries(Compose *compose, gboolean check_everythin
                return FALSE;
        }
 
-       if (!compose->batch) {
+       if (!compose->batch && prefs_common.warn_empty_subj == TRUE) {
                str = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
-               if (*str == '\0' && check_everything == TRUE && 
+               if (*str == '\0' && check_everything == TRUE &&
                    compose->mode != COMPOSE_REDIRECT) {
                        AlertValue aval;
                        gchar *button_label;
@@ -4985,9 +5014,14 @@ static gboolean compose_check_entries(Compose *compose, gboolean check_everythin
                                        compose->sending?_("Send it anyway?"):
                                        _("Queue it anyway?"));
 
-                       aval = alertpanel(compose->sending?_("Send"):_("Send later"), message,
-                                         GTK_STOCK_CANCEL, button_label, NULL);
+                       aval = alertpanel_full(compose->sending?_("Send"):_("Send later"), message,
+                                              GTK_STOCK_CANCEL, button_label, NULL, TRUE, NULL,
+                                              ALERT_QUESTION, G_ALERTDEFAULT);
                        g_free(message);
+                       if (aval & G_ALERTDISABLE) {
+                               aval &= ~G_ALERTDISABLE;
+                               prefs_common.warn_empty_subj = FALSE;
+                       }
                        if (aval != G_ALERTALTERNATE)
                                return FALSE;
                }
@@ -6095,6 +6129,44 @@ static int compose_add_attachments(Compose *compose, MimeInfo *parent)
        return 0;
 }
 
+static gchar *compose_quote_list_of_addresses(gchar *str)
+{
+       GSList *list = NULL, *item = NULL;
+       gchar *qname = NULL, *faddr = NULL, *result = NULL;
+
+       list = address_list_append_with_comments(list, str);
+       for (item = list; item != NULL; item = item->next) {
+               gchar *spec = item->data;
+               gchar *endofname = strstr(spec, " <");
+               *endofname = '\0';
+               QUOTE_IF_REQUIRED_NORMAL(qname, spec, return NULL);
+               *endofname = ' ';
+               if (*qname != *spec) { /* has been quoted, compute new */
+                       gchar *addr = g_strdup(endofname);
+                       gchar *name = g_strdup(qname);
+                       faddr = g_strconcat(name, addr, NULL);
+                       g_free(name);
+                       g_free(addr);
+                       debug_print("new auto-quoted address: '%s'", faddr);
+               }
+               if (result == NULL)
+                       result = g_strdup((faddr != NULL)? faddr: spec);
+               else {
+                       result = g_strconcat(result,
+                                            ", ",
+                                            (faddr != NULL)? faddr: spec,
+                                            NULL);
+               }
+               if (faddr != NULL) {
+                       g_free(faddr);
+                       faddr = NULL;
+               }
+       }
+       slist_free_strings_full(list);
+
+       return result;
+}
+
 #define IS_IN_CUSTOM_HEADER(header) \
        (compose->account->add_customhdr && \
         custom_header_find(compose->account->customhdr_list, header) != NULL)
@@ -6127,9 +6199,11 @@ static void compose_add_headerfield_from_headerlist(Compose *compose,
                headerentryname = gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN((headerentry->combo)))));
 
                if (!g_utf8_collate(trans_fieldname, headerentryname)) {
-                       str = gtk_editable_get_chars(GTK_EDITABLE(headerentry->entry), 0, -1);
-                       g_strstrip(str);
-                       if (str[0] != '\0') {
+                       gchar * ustr = gtk_editable_get_chars(GTK_EDITABLE(headerentry->entry), 0, -1);
+                       g_strstrip(ustr);
+                       str = compose_quote_list_of_addresses(ustr);
+                       g_free(ustr);
+                       if (str != NULL && str[0] != '\0') {
                                if (add_field)
                                        g_string_append(fieldstr, seperator);
                                g_string_append(fieldstr, str);
@@ -6625,9 +6699,9 @@ void compose_add_extra_header_entries(GtkListStore *model)
                        goto extra_headers_done;
                }
                while (fgets(buf, BUFFSIZE, exh) != NULL) {
-                       lastc = strlen(buf) - 1;        /* remove trailing \n */
-                       buf[lastc] = (buf[lastc] == '\n')? '\0': buf[lastc];
-                       --lastc;
+                       lastc = strlen(buf) - 1;        /* remove trailing control chars */
+                       while (lastc >= 0 && buf[lastc] != ':')
+                               buf[lastc--] = '\0';
                        if (lastc > 0 && buf[0] != '#' && buf[lastc] == ':') {
                                buf[lastc] = '\0'; /* remove trailing : for comparison */
                                if (custom_header_is_allowed(buf)) {
@@ -6696,7 +6770,7 @@ static void compose_create_header_entry(Compose *compose)
        GtkCellRenderer *cell = gtk_cell_renderer_text_new();
        gtk_cell_renderer_set_alignment(cell, 0.0, 0.5);
        gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo), cell, TRUE);
-       gtk_combo_box_set_entry_text_column(combo, 0);
+       gtk_combo_box_set_entry_text_column(GTK_COMBO_BOX(combo), 0);
 #endif
        gtk_combo_box_set_active(GTK_COMBO_BOX(combo), 0);
        g_signal_connect(G_OBJECT(gtk_bin_get_child(GTK_BIN(combo))), "grab_focus",
@@ -6994,15 +7068,8 @@ static GtkWidget *compose_create_attach(Compose *compose)
                         G_CALLBACK(attach_selected), compose);
        g_signal_connect(G_OBJECT(attach_clist), "button_press_event",
                         G_CALLBACK(attach_button_pressed), compose);
-#ifndef MAEMO
        g_signal_connect(G_OBJECT(attach_clist), "popup-menu",
                         G_CALLBACK(popup_attach_button_pressed), compose);
-#else
-       gtk_widget_tap_and_hold_setup(GTK_WIDGET(attach_clist), NULL, NULL,
-                       GTK_TAP_AND_HOLD_NONE | GTK_TAP_AND_HOLD_NO_INTERNALS);
-       g_signal_connect(G_OBJECT(attach_clist), "tap-and-hold",
-                        G_CALLBACK(popup_attach_button_pressed), compose);
-#endif
        g_signal_connect(G_OBJECT(attach_clist), "key_press_event",
                         G_CALLBACK(attach_key_pressed), compose);
 
@@ -7064,9 +7131,13 @@ static GtkWidget *compose_create_others(Compose *compose)
        gtk_widget_show(savemsg_combo);
 
        if (prefs_common.compose_save_to_history)
+#if !GTK_CHECK_VERSION(2, 24, 0)
                combobox_set_popdown_strings(GTK_COMBO_BOX(savemsg_combo),
                                prefs_common.compose_save_to_history);
-
+#else
+               combobox_set_popdown_strings(GTK_COMBO_BOX_TEXT(savemsg_combo),
+                               prefs_common.compose_save_to_history);
+#endif
        gtk_table_attach(GTK_TABLE(table), savemsg_combo, 1, 2, rowcount, rowcount + 1, GTK_FILL|GTK_EXPAND, GTK_SHRINK, 0, 0);
        gtk_widget_set_sensitive(GTK_WIDGET(savemsg_combo), prefs_common.savemsg);
        g_signal_connect_after(G_OBJECT(savemsg_combo), "grab_focus",
@@ -7347,11 +7418,7 @@ static Compose *compose_create(PrefsAccount *account,
        gtk_action_group_add_radio_actions(action_group, compose_radio_enc_entries,
                        G_N_ELEMENTS(compose_radio_enc_entries), C_AUTO, G_CALLBACK(compose_set_encoding_cb), (gpointer)compose);
 
-#ifndef MAEMO
        MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/", "Menu", NULL, GTK_UI_MANAGER_MENUBAR)
-#else
-       MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/", "Menu", NULL, GTK_UI_MANAGER_POPUP)
-#endif
 
        MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu", "Message", "Message", GTK_UI_MANAGER_MENU)
        MENUITEM_ADDUI_MANAGER(compose->ui_manager, "/Menu", "Edit", "Edit", GTK_UI_MANAGER_MENU)
@@ -7532,11 +7599,7 @@ static Compose *compose_create(PrefsAccount *account,
        gtk_widget_show_all(menubar);
 
        gtk_window_add_accel_group(GTK_WINDOW(window), gtk_ui_manager_get_accel_group(compose->ui_manager));
-#ifndef MAEMO
        gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
-#else
-       hildon_window_set_menu(HILDON_WINDOW(window), GTK_MENU(menubar));
-#endif
 
        if (prefs_common.toolbar_detachable) {
                handlebox = gtk_handle_box_new();
@@ -7546,13 +7609,8 @@ static Compose *compose_create(PrefsAccount *account,
        gtk_box_pack_start(GTK_BOX(vbox), handlebox, FALSE, FALSE, 0);
 
        gtk_widget_realize(handlebox);
-#ifdef MAEMO
-       compose->toolbar = toolbar_create(TOOLBAR_COMPOSE, window,
-                                         (gpointer)compose);
-#else
        compose->toolbar = toolbar_create(TOOLBAR_COMPOSE, handlebox,
                                          (gpointer)compose);
-#endif
 
        vbox2 = gtk_vbox_new(FALSE, 2);
        gtk_box_pack_start(GTK_BOX(vbox), vbox2, TRUE, TRUE, 0);
@@ -7663,15 +7721,8 @@ static Compose *compose_create(PrefsAccount *account,
                         G_CALLBACK(text_inserted), compose);
        g_signal_connect(G_OBJECT(text), "button_press_event",
                         G_CALLBACK(text_clicked), compose);
-#ifndef MAEMO
        g_signal_connect(G_OBJECT(text), "popup-menu",
                         G_CALLBACK(compose_popup_menu), compose);
-#else
-       gtk_widget_tap_and_hold_setup(GTK_WIDGET(text), NULL, NULL,
-                       GTK_TAP_AND_HOLD_NONE | GTK_TAP_AND_HOLD_NO_INTERNALS);
-       g_signal_connect(G_OBJECT(text), "tap-and-hold",
-                        G_CALLBACK(compose_popup_menu), compose);
-#endif
        g_signal_connect(G_OBJECT(subject_entry), "changed",
                        G_CALLBACK(compose_changed_cb), compose);
        g_signal_connect(G_OBJECT(subject_entry), "activate",
@@ -7695,12 +7746,6 @@ static Compose *compose_create(PrefsAccount *account,
        /* pane between attach clist and text */
        paned = gtk_vpaned_new();
        gtk_container_add(GTK_CONTAINER(vbox2), paned);
-#ifdef MAEMO
-       if( maemo_mainwindow_is_fullscreen(mainwindow_get_mainwindow()->window) )
-               gtk_widget_set_size_request(edit_vbox, -1, mode == COMPOSE_NEW ? 300 : 280);
-       else
-               gtk_widget_set_size_request(edit_vbox, -1, mode == COMPOSE_NEW ? 250 : 230);
-#endif
        gtk_paned_add1(GTK_PANED(paned), notebook);
        gtk_paned_add2(GTK_PANED(paned), edit_vbox);
        gtk_widget_show_all(paned);
@@ -7897,10 +7942,6 @@ static Compose *compose_create(PrefsAccount *account,
                gtk_widget_realize(window);
        } else {
                gtk_widget_show(window);
-#ifdef MAEMO
-               maemo_window_full_screen_if_needed(GTK_WINDOW(window));
-               maemo_connect_key_press_to_mainwindow(GTK_WINDOW(window));
-#endif
        }
        
        return compose;
@@ -10089,7 +10130,7 @@ static void compose_template_activate_cb(GtkWidget *widget, gpointer data)
        tmpl = g_object_get_data(G_OBJECT(widget), "template");
        cm_return_if_fail(tmpl != NULL);
 
-       msg = g_strdup_printf(_("Do you want to apply the template '%s' ?"),
+       msg = g_strdup_printf(_("Do you want to apply the template '%s'?"),
                              tmpl->name);
        val = alertpanel(_("Apply template"), msg,
                         _("_Replace"), _("_Insert"), GTK_STOCK_CANCEL);