Fix bug #2975: Implement setting -0000 timezone to hide sender localtime
[claws.git] / src / compose.c
index 285158f163ee0622e3356776f6edc16901a267a2..82220667fdb08fe84520d18d10da9d7ef4de2120 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
@@ -61,7 +60,7 @@
 #include "main.h"
 #include "mainwindow.h"
 #include "compose.h"
-#ifndef USE_NEW_ADDRBOOK
+#ifndef USE_ALT_ADDRBOOK
        #include "addressbook.h"
 #else
        #include "addressbook-dbus.h"
@@ -336,13 +335,19 @@ static gboolean attach_property_key_pressed       (GtkWidget      *widget,
 
 static void compose_exec_ext_editor            (Compose        *compose);
 #ifdef G_OS_UNIX
-static gint compose_exec_ext_editor_real       (const gchar    *file);
+static gint compose_exec_ext_editor_real       (const gchar    *file,
+                                                GdkNativeWindow socket_wid);
 static gboolean compose_ext_editor_kill                (Compose        *compose);
 static gboolean compose_input_cb               (GIOChannel     *source,
                                                 GIOCondition    condition,
                                                 gpointer        data);
 static void compose_set_ext_editor_sensitive   (Compose        *compose,
                                                 gboolean        sensitive);
+static gboolean compose_get_ext_editor_cmd_valid();
+static gboolean compose_get_ext_editor_uses_socket();
+static gboolean compose_ext_editor_plug_removed_cb
+                                               (GtkSocket      *socket,
+                                                Compose        *compose);
 #endif /* G_OS_UNIX */
 
 static void compose_undo_state_changed         (UndoMain       *undostruct,
@@ -1199,7 +1204,7 @@ Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderI
                }
 
        }
-       procmsg_msginfo_free( dummyinfo );
+       procmsg_msginfo_free( &dummyinfo );
 
        if (attach_files) {
                GList *curr;
@@ -1529,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);
        }
 }
 
@@ -1820,7 +1825,7 @@ Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
                quote_fmt_reset_vartable();
 
                g_free(tmp);
-               procmsg_msginfo_free(full_msginfo);
+               procmsg_msginfo_free(&full_msginfo);
        }
 
        textview = GTK_TEXT_VIEW(compose->text);
@@ -1879,7 +1884,7 @@ Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
                quote_fmt_reset_vartable();
                compose_attach_parts(compose, msginfo);
 
-               procmsg_msginfo_free(full_msginfo);
+               procmsg_msginfo_free(&full_msginfo);
        }
 
        SIGNAL_BLOCK(textbuf);
@@ -2063,6 +2068,9 @@ static Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_
        gtk_text_buffer_get_start_iter(textbuf, &iter);
        gtk_text_buffer_place_cursor(textbuf, &iter);
 
+       if (prefs_common.auto_exteditor)
+               compose_exec_ext_editor(compose);
+
        gtk_widget_grab_focus(compose->header_last->entry);
        undo_unblock(compose->undostruct);
        compose->modified = FALSE;
@@ -3183,7 +3191,7 @@ error:
 ok:
        SIGNAL_UNBLOCK(buffer);
 
-       procmsg_msginfo_free( dummyinfo );
+       procmsg_msginfo_free( &dummyinfo );
 
        return buf;
 }
@@ -3342,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) &&
@@ -3387,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
@@ -3608,7 +3625,7 @@ static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *fi
                                                "in the message body. Are you sure you want to do that?"),
                                                to_human_readable(file_stat.st_size));
                        aval = alertpanel_full(_("Are you sure?"), msg, GTK_STOCK_CANCEL,
-                                       _("+_Insert"), NULL, TRUE, NULL, ALERT_QUESTION, G_ALERTDEFAULT);
+                                       g_strconcat("+", _("_Insert"), NULL), NULL, TRUE, NULL, ALERT_QUESTION, G_ALERTDEFAULT);
                        g_free(msg);
 
                        /* do we ask for confirmation next time? */
@@ -3734,7 +3751,7 @@ static gboolean compose_attach_append(Compose *compose, const gchar *file,
        if (size == 0 && !compose->batch) {
                gchar * msg = g_strdup_printf(_("File %s is empty."), filename);
                AlertValue aval = alertpanel_full(_("Empty file"), msg, 
-                               GTK_STOCK_CANCEL, _("+_Attach anyway"), NULL, FALSE,
+                               GTK_STOCK_CANCEL,  g_strconcat("+", _("_Attach anyway"), NULL), NULL, FALSE,
                                NULL, ALERT_WARNING, G_ALERTDEFAULT);
                g_free(msg);
 
@@ -3772,7 +3789,7 @@ static gboolean compose_attach_append(Compose *compose, const gchar *file,
 
                        ainfo->name = g_strdup_printf(_("Message: %s"), name);
 
-                       procmsg_msginfo_free(msginfo);
+                       procmsg_msginfo_free(&msginfo);
                } else {
                        if (!g_ascii_strncasecmp(content_type, "text/", 5)) {
                                ainfo->charset = g_strdup(charset);
@@ -3868,7 +3885,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;
        }
 
@@ -3938,7 +3955,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
@@ -5024,7 +5041,7 @@ static gboolean compose_check_for_set_recipients(Compose *compose)
                        }
                        aval = alertpanel(_("Send"),
                                          _("The only recipient is the default CC address. Send anyway?"),
-                                         GTK_STOCK_CANCEL, _("+_Send"), NULL);
+                                         GTK_STOCK_CANCEL, g_strconcat("+", _("_Send"), NULL), NULL);
                        if (aval != G_ALERTALTERNATE)
                                return FALSE;
                }
@@ -5056,7 +5073,7 @@ static gboolean compose_check_for_set_recipients(Compose *compose)
                        }
                        aval = alertpanel(_("Send"),
                                          _("The only recipient is the default BCC address. Send anyway?"),
-                                         GTK_STOCK_CANCEL, _("+_Send"), NULL);
+                                         GTK_STOCK_CANCEL, g_strconcat("+", _("_Send"), NULL), NULL);
                        if (aval != G_ALERTALTERNATE)
                                return FALSE;
                }
@@ -5089,9 +5106,9 @@ static gboolean compose_check_entries(Compose *compose, gboolean check_everythin
                        gchar *message;
 
                        if (compose->sending)
-                               button_label = _("+_Send");
+                               button_label = g_strconcat("+", _("_Send"), NULL);
                        else
-                               button_label = _("+_Queue");
+                               button_label = g_strconcat("+", _("_Queue"), NULL);
                        message = g_strdup_printf(_("Subject is empty. %s"),
                                        compose->sending?_("Send it anyway?"):
                                        _("Queue it anyway?"));
@@ -5208,7 +5225,7 @@ gint compose_send(Compose *compose)
                                if (tmp) {
                                        debug_print("removing %d via %s\n", tmp->msgnum, tmsgid);
                                        folder_item_remove_msg(folder, tmp->msgnum);
-                                       procmsg_msginfo_free(tmp);
+                                       procmsg_msginfo_free(&tmp);
                                } 
                        }
                }
@@ -5224,7 +5241,7 @@ gint compose_send(Compose *compose)
                        if (tmp) {
                                debug_print("removing %d via %s\n", tmp->msgnum, tmsgid);
                                folder_item_remove_msg(folder, tmp->msgnum);
-                               procmsg_msginfo_free(tmp);
+                               procmsg_msginfo_free(&tmp);
                        }
                }
                if (!discard_window) {
@@ -5365,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 */
@@ -5612,7 +5632,8 @@ static gint compose_write_to_file(Compose *compose, FILE *fp, gint action, gbool
                        msg = g_strdup_printf(_("Can't convert the character encoding of the message \n"
                                                "to the specified %s charset.\n"
                                                "Send it as %s?"), out_codeset, src_codeset);
-                       aval = alertpanel_full(_("Error"), msg, GTK_STOCK_CANCEL, _("+_Send"), NULL, FALSE,
+                       aval = alertpanel_full(_("Error"), msg, GTK_STOCK_CANCEL,
+                                              g_strconcat("+", _("_Send"), NULL), NULL, FALSE,
                                              NULL, ALERT_ERROR, G_ALERTDEFAULT);
                        g_free(msg);
 
@@ -5785,7 +5806,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;
 }
@@ -5899,7 +5920,7 @@ static gboolean compose_warn_encryption(Compose *compose)
                return TRUE;
 
        val = alertpanel_full(_("Encryption warning"), warning,
-                 GTK_STOCK_CANCEL, _("+C_ontinue"), NULL,
+                 GTK_STOCK_CANCEL, g_strconcat("+", _("C_ontinue"), NULL), NULL,
                  TRUE, NULL, ALERT_WARNING, G_ALERTALTERNATE);
        if (val & G_ALERTDISABLE) {
                val &= ~G_ALERTDISABLE;
@@ -6291,7 +6312,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)
@@ -6441,7 +6462,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 */
@@ -6487,11 +6511,22 @@ static gchar *compose_get_header(Compose *compose)
                
                g_string_append_printf(header, "From: %s <%s>\n",
                        qname, from_address);
+               if (!IS_IN_CUSTOM_HEADER("Disposition-Notification-To") &&
+                   compose->return_receipt) {
+                       compose_convert_header(compose, buf, sizeof(buf), from_name,
+                                              strlen("Disposition-Notification-To: "),
+                                              TRUE);
+                       g_string_append_printf(header, "Disposition-Notification-To: %s <%s>\n", buf, from_address);
+               }
                if (qname != name)
                        g_free(qname);
-       } else
+       } else {
                g_string_append_printf(header, "From: %s\n", from_address);
-       
+               if (!IS_IN_CUSTOM_HEADER("Disposition-Notification-To") &&
+                   compose->return_receipt)
+                       g_string_append_printf(header, "Disposition-Notification-To: %s\n", from_address);
+
+       }
        g_free(from_name);
        g_free(from_address);
 
@@ -6647,21 +6682,6 @@ static gchar *compose_get_header(Compose *compose)
                                     compose->priority);
        }
 
-       /* Request Return Receipt */
-       if (!IS_IN_CUSTOM_HEADER("Disposition-Notification-To")) {
-               if (compose->return_receipt) {
-                       if (compose->account->name
-                           && *compose->account->name) {
-                               compose_convert_header(compose, buf, sizeof(buf), 
-                                                      compose->account->name, 
-                                                      strlen("Disposition-Notification-To: "),
-                                                      TRUE);
-                               g_string_append_printf(header, "Disposition-Notification-To: %s <%s>\n", buf, compose->account->address);
-                       } else
-                               g_string_append_printf(header, "Disposition-Notification-To: %s\n", compose->account->address);
-               }
-       }
-
        /* get special headers */
        for (list = compose->header_list; list; list = list->next) {
                ComposeHeaderEntry *headerentry;
@@ -6791,7 +6811,7 @@ static void compose_add_to_addressbook_cb(GtkMenuItem *menuitem, gpointer user_d
        if (*address != '\0') {
                gchar *name = procheader_get_fromname(address);
                extract_address(address);
-#ifndef USE_NEW_ADDRBOOK
+#ifndef USE_ALT_ADDRBOOK
                addressbook_add_contact(name, address, NULL, NULL);
 #else
                debug_print("%s: %s\n", name, address);
@@ -7112,21 +7132,14 @@ static void compose_remove_header_entries(Compose *compose)
 static GtkWidget *compose_create_header(Compose *compose) 
 {
        GtkWidget *from_optmenu_hbox;
-       GtkWidget *header_scrolledwin_main;
        GtkWidget *header_table_main;
        GtkWidget *header_scrolledwin;
        GtkWidget *header_table;
 
        /* parent with account selection and from header */
-       header_scrolledwin_main = gtk_scrolled_window_new(NULL, NULL);
-       gtk_widget_show(header_scrolledwin_main);
-       gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(header_scrolledwin_main), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
-
        header_table_main = gtk_table_new(2, 2, FALSE);
        gtk_widget_show(header_table_main);
        gtk_container_set_border_width(GTK_CONTAINER(header_table_main), BORDER_WIDTH);
-       gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(header_scrolledwin_main), header_table_main);
-       gtk_viewport_set_shadow_type(GTK_VIEWPORT(gtk_bin_get_child(GTK_BIN((header_scrolledwin_main)))), GTK_SHADOW_NONE);
 
        from_optmenu_hbox = compose_account_option_menu_create(compose);
        gtk_table_attach(GTK_TABLE(header_table_main), from_optmenu_hbox,
@@ -7156,7 +7169,7 @@ static GtkWidget *compose_create_header(Compose *compose)
 
        compose->table = NULL;
 
-       return header_scrolledwin_main;
+       return header_table_main;
 }
 
 static gboolean popup_attach_button_pressed(GtkWidget *widget, gpointer data)
@@ -8012,6 +8025,7 @@ static Compose *compose_create(PrefsAccount *account,
        compose->exteditor_file    = NULL;
        compose->exteditor_pid     = -1;
        compose->exteditor_tag     = -1;
+       compose->exteditor_socket  = NULL;
        compose->draft_timeout_tag = COMPOSE_DRAFT_TIMEOUT_FORBIDDEN; /* inhibit auto-drafting while loading */
 
        compose->folder_update_callback_id =
@@ -8074,7 +8088,7 @@ static Compose *compose_create(PrefsAccount *account,
                gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN((compose->header_last->combo)))),
                                prefs_common_translated_header_name("Newsgroups:"));
 
-#ifndef USE_NEW_ADDRBOOK
+#ifndef USE_ALT_ADDRBOOK
        addressbook_set_target_compose(compose);
 #endif 
        if (mode != COMPOSE_REDIRECT)
@@ -8147,7 +8161,7 @@ static GtkWidget *compose_account_option_menu_create(Compose *compose)
 
                if (ac == compose->account) def_menu = num;
 
-               name = g_markup_printf_escaped(_("<i>%s</i>"),
+               name = g_markup_printf_escaped("<i>%s</i>",
                                       ac->account_name);
                
                if (ac == compose->account) {
@@ -8611,7 +8625,7 @@ static void compose_template_apply(Compose *compose, Template *tmpl,
 
                        parsed_str = compose_quote_fmt(compose, dummyinfo,
                                                           tmpl->value, qmark, tmp, FALSE, FALSE, err_msg);
-                       procmsg_msginfo_free( dummyinfo );
+                       procmsg_msginfo_free( &dummyinfo );
 
                        g_free( tmp );
                } 
@@ -8777,7 +8791,7 @@ static void compose_template_apply_fields(Compose *compose, Template *tmpl)
                }
        }
 
-       procmsg_msginfo_free( dummyinfo );
+       procmsg_msginfo_free( &dummyinfo );
 }
 
 static void compose_destroy(Compose *compose)
@@ -8812,9 +8826,9 @@ static void compose_destroy(Compose *compose)
        hooks_unregister_hook(FOLDER_UPDATE_HOOKLIST,
                        compose->folder_update_callback_id);
 
-       procmsg_msginfo_free(compose->targetinfo);
-       procmsg_msginfo_free(compose->replyinfo);
-       procmsg_msginfo_free(compose->fwdinfo);
+       procmsg_msginfo_free(&(compose->targetinfo));
+       procmsg_msginfo_free(&(compose->replyinfo));
+       procmsg_msginfo_free(&(compose->fwdinfo));
 
        g_free(compose->replyto);
        g_free(compose->cc);
@@ -8842,7 +8856,7 @@ static void compose_destroy(Compose *compose)
        g_free(compose->privacy_system);
        g_free(compose->encdata);
 
-#ifndef USE_NEW_ADDRBOOK
+#ifndef USE_ALT_ADDRBOOK
        if (addressbook_get_target_compose() == compose)
                addressbook_set_target_compose(NULL);
 #endif
@@ -9277,12 +9291,37 @@ static void compose_exec_ext_editor(Compose *compose)
 {
 #ifdef G_OS_UNIX
        gchar *tmp;
+       GtkWidget *socket;
+       GdkNativeWindow socket_wid = 0;
        pid_t pid;
        gint pipe_fds[2];
 
        tmp = g_strdup_printf("%s%ctmpmsg.%p", get_tmp_dir(),
                              G_DIR_SEPARATOR, compose);
 
+       if (compose_get_ext_editor_uses_socket()) {
+               /* Only allow one socket */
+               if (compose->exteditor_socket != NULL) {
+                       if (gtk_widget_is_focus(compose->exteditor_socket)) {
+                               /* Move the focus off of the socket */
+                               gtk_widget_child_focus(compose->window, GTK_DIR_TAB_BACKWARD);
+                       }
+                       g_free(tmp);
+                       return;
+               }
+               /* Create the receiving GtkSocket */
+               socket = gtk_socket_new ();
+               g_signal_connect (GTK_OBJECT(socket), "plug-removed",
+                                 G_CALLBACK(compose_ext_editor_plug_removed_cb),
+                                 compose);
+               gtk_box_pack_start(GTK_BOX(compose->edit_vbox), socket, TRUE, TRUE, 0);
+               gtk_widget_set_size_request(socket, prefs_common.compose_width, -1);
+               /* Realize the socket so that we can use its ID */
+               gtk_widget_realize(socket);
+               socket_wid = gtk_socket_get_id(GTK_SOCKET (socket));
+               compose->exteditor_socket = socket;
+       }
+
        if (pipe(pipe_fds) < 0) {
                perror("pipe");
                g_free(tmp);
@@ -9327,7 +9366,7 @@ static void compose_exec_ext_editor(Compose *compose)
                        _exit(1);
                }
 
-               pid_ed = compose_exec_ext_editor_real(tmp);
+               pid_ed = compose_exec_ext_editor_real(tmp, socket_wid);
                if (pid_ed < 0) {
                        fd_write_all(pipe_fds[1], "1\n", 2);
                        _exit(1);
@@ -9347,10 +9386,34 @@ static void compose_exec_ext_editor(Compose *compose)
 }
 
 #ifdef G_OS_UNIX
-static gint compose_exec_ext_editor_real(const gchar *file)
+static gboolean compose_get_ext_editor_cmd_valid()
+{
+       gboolean has_s = FALSE;
+       gboolean has_w = FALSE;
+       const gchar *p = prefs_common_get_ext_editor_cmd();
+       if (!p)
+               return FALSE;
+       while ((p = strchr(p, '%'))) {
+               p++;
+               if (*p == 's') {
+                       if (has_s)
+                               return FALSE;
+                       has_s = TRUE;
+               } else if (*p == 'w') {
+                       if (has_w)
+                               return FALSE;
+                       has_w = TRUE;
+               } else {
+                       return FALSE;
+               }
+       }
+       return TRUE;
+}
+
+static gint compose_exec_ext_editor_real(const gchar *file, GdkNativeWindow socket_wid)
 {
        gchar buf[1024];
-       gchar *p;
+       gchar *p, *s;
        gchar **cmdline;
        pid_t pid;
 
@@ -9368,10 +9431,20 @@ static gint compose_exec_ext_editor_real(const gchar *file)
        if (setpgid(0, getppid()))
                perror("setpgid");
 
-       if (prefs_common_get_ext_editor_cmd() &&
-           (p = strchr(prefs_common_get_ext_editor_cmd(), '%')) &&
-           *(p + 1) == 's' && !strchr(p + 2, '%')) {
-               g_snprintf(buf, sizeof(buf), prefs_common_get_ext_editor_cmd(), file);
+       if (compose_get_ext_editor_cmd_valid()) {
+               if (compose_get_ext_editor_uses_socket()) {
+                       p = g_strdup(prefs_common_get_ext_editor_cmd());
+                       s = strstr(p, "%w");
+                       s[1] = 'u';
+                       if (strstr(p, "%s") < s)
+                               g_snprintf(buf, sizeof(buf), p, file, socket_wid);
+                       else
+                               g_snprintf(buf, sizeof(buf), p, socket_wid, file);
+                       g_free(p);
+               } else {
+                       g_snprintf(buf, sizeof(buf),
+                                  prefs_common_get_ext_editor_cmd(), file);
+               }
        } else {
                if (prefs_common_get_ext_editor_cmd())
                        g_warning("External editor command-line is invalid: '%s'",
@@ -9443,7 +9516,10 @@ static gboolean compose_input_cb(GIOChannel *source, GIOCondition condition,
 
        debug_print("Compose: input from monitoring process\n");
 
-       g_io_channel_read_chars(source, buf, sizeof(buf), &bytes_read, NULL);
+       if (g_io_channel_read_chars(source, buf, sizeof(buf), &bytes_read, NULL) != G_IO_STATUS_NORMAL) {
+               bytes_read = 0;
+               buf[0] = '\0';
+       }
 
        g_io_channel_shutdown(source, FALSE, NULL);
        g_io_channel_unref(source);
@@ -9488,23 +9564,66 @@ static gboolean compose_input_cb(GIOChannel *source, GIOCondition condition,
        compose->exteditor_pid     = -1;
        compose->exteditor_ch      = NULL;
        compose->exteditor_tag     = -1;
+       if (compose->exteditor_socket) {
+               gtk_widget_destroy(compose->exteditor_socket);
+               compose->exteditor_socket = NULL;
+       }
+
 
        return FALSE;
 }
 
+static char *ext_editor_menu_entries[] = {
+       "Menu/Message/Send",
+       "Menu/Message/SendLater",
+       "Menu/Message/InsertFile",
+       "Menu/Message/InsertSig",
+       "Menu/Message/ReplaceSig",
+       "Menu/Message/Save",
+       "Menu/Message/Print",
+       "Menu/Edit",
+#if USE_ENCHANT
+       "Menu/Spelling",
+#endif
+       "Menu/Tools/ShowRuler",
+       "Menu/Tools/Actions",
+       "Menu/Help",
+       NULL
+};
+
 static void compose_set_ext_editor_sensitive(Compose *compose,
                                             gboolean sensitive)
 {
-       cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Message/Send", sensitive);
-       cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Message/SendLater", sensitive);
-       cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Message/InsertFile", sensitive);
-       cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Message/InsertSig", sensitive);
-       cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Message/ReplaceSig", sensitive);
-       cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Edit/WrapPara", sensitive);
-       cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Edit/WrapAllLines", sensitive);
-       cm_menu_set_sensitive_full(compose->ui_manager, "Menu/Edit/ExtEditor", sensitive);
+       int i;
 
-       gtk_widget_set_sensitive(compose->text,                       sensitive);
+       for (i = 0; ext_editor_menu_entries[i]; ++i) {
+               cm_menu_set_sensitive_full(compose->ui_manager,
+                       ext_editor_menu_entries[i], sensitive);
+       }
+
+       if (compose_get_ext_editor_uses_socket()) {
+               if (sensitive) {
+                       if (compose->exteditor_socket)
+                               gtk_widget_hide(compose->exteditor_socket);
+                       gtk_widget_show(compose->scrolledwin);
+                       if (prefs_common.show_ruler)
+                               gtk_widget_show(compose->ruler_hbox);
+                       /* Fix the focus, as it doesn't go anywhere when the
+                        * socket is hidden or destroyed */
+                       gtk_widget_child_focus(compose->window, GTK_DIR_TAB_BACKWARD);
+               } else {
+                       g_assert (compose->exteditor_socket != NULL);
+                       /* Fix the focus, as it doesn't go anywhere when the
+                        * edit box is hidden */
+                       if (gtk_widget_is_focus(compose->text))
+                               gtk_widget_child_focus(compose->window, GTK_DIR_TAB_BACKWARD);
+                       gtk_widget_hide(compose->scrolledwin);
+                       gtk_widget_hide(compose->ruler_hbox);
+                       gtk_widget_show(compose->exteditor_socket);
+               }
+       } else {
+               gtk_widget_set_sensitive(compose->text,                   sensitive);
+       }
        if (compose->toolbar->send_btn)
                gtk_widget_set_sensitive(compose->toolbar->send_btn,      sensitive);
        if (compose->toolbar->sendl_btn)
@@ -9522,6 +9641,19 @@ static void compose_set_ext_editor_sensitive(Compose *compose,
        if (compose->toolbar->linewrap_all_btn)
                gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, sensitive);
 }
+
+static gboolean compose_get_ext_editor_uses_socket()
+{
+       return (prefs_common_get_ext_editor_cmd() &&
+               strstr(prefs_common_get_ext_editor_cmd(), "%w"));
+}
+
+static gboolean compose_ext_editor_plug_removed_cb(GtkSocket *socket, Compose *compose)
+{
+       compose->exteditor_socket = NULL;
+       /* returning FALSE allows destruction of the socket */
+       return FALSE;
+}
 #endif /* G_OS_UNIX */
 
 /**
@@ -9822,6 +9954,12 @@ static void compose_send_cb(GtkAction *action, gpointer data)
 {
        Compose *compose = (Compose *)data;
 
+#ifdef G_OS_UNIX
+       if (compose->exteditor_tag != -1) {
+               debug_print("ignoring send: external editor still open\n");
+               return;
+       }
+#endif
        if (prefs_common.work_offline && 
            !inc_offline_should_override(TRUE,
                _("Claws Mail needs network access in order "
@@ -10016,7 +10154,7 @@ gboolean compose_draft (gpointer data, guint action)
                }
                if (tmpinfo) {
                        msgnum = tmpinfo->msgnum;
-                       procmsg_msginfo_free(tmpinfo);
+                       procmsg_msginfo_free(&tmpinfo);
                        debug_print("got draft msgnum %d from scanning\n", msgnum);
                } else {
                        debug_print("didn't get draft msgnum after scanning\n");
@@ -10074,7 +10212,7 @@ warn_err:
                if (action == COMPOSE_DRAFT_FOR_EXIT) {
                        compose_register_draft(newmsginfo);
                }
-               procmsg_msginfo_free(newmsginfo);
+               procmsg_msginfo_free(&newmsginfo);
        }
        
        folder_item_scan(draft);
@@ -10100,7 +10238,7 @@ warn_err:
                }
                g_free(path);
 
-               procmsg_msginfo_free(compose->targetinfo);
+               procmsg_msginfo_free(&(compose->targetinfo));
                compose->targetinfo = procmsg_msginfo_new();
                compose->targetinfo->msgnum = msgnum;
                compose->targetinfo->size = (goffset)s.st_size;
@@ -10320,7 +10458,8 @@ static void compose_close_cb(GtkAction *action, gpointer data)
                } else {
                        val = alertpanel(_("Save changes"),
                                 _("This message has been modified. Save the latest changes?"),
-                                _("_Don't save"), _("+_Save to Drafts"), GTK_STOCK_CANCEL);
+                                _("_Don't save"), g_strconcat("+", _("_Save to Drafts"), NULL),
+                               GTK_STOCK_CANCEL);
                }
                g_mutex_unlock(compose->mutex);
                switch (val) {
@@ -10362,7 +10501,7 @@ static void compose_address_cb(GtkAction *action, gpointer data)
 {
        Compose *compose = (Compose *)data;
 
-#ifndef USE_NEW_ADDRBOOK
+#ifndef USE_ALT_ADDRBOOK
        addressbook_open(compose);
 #else
        GError* error = NULL;
@@ -11254,7 +11393,7 @@ static void compose_insert_drag_received_cb (GtkWidget          *widget,
                                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?"),
-                                         GTK_STOCK_CANCEL, _("+_Insert"), _("_Attach"),
+                                         GTK_STOCK_CANCEL, g_strconcat("+", _("_Insert"), NULL), _("_Attach"),
                                          TRUE, NULL, ALERT_QUESTION, G_ALERTALTERNATE);
                                break;
                        case COMPOSE_DND_INSERT:
@@ -11743,7 +11882,7 @@ static void compose_reply_from_messageview_real(MessageView *msgview, GSList *ms
 
        if (new_msglist) {
                compose = compose_reply_mode((ComposeMode)action, new_msglist, body);
-               procmsg_msginfo_free(tmp_msginfo);
+               procmsg_msginfo_free(&tmp_msginfo);
                g_slist_free(new_msglist);
        } else
                compose = compose_reply_mode((ComposeMode)action, msginfo_list, body);