2005-02-10 [paul] 1.0.1cvs4.1
[claws.git] / src / compose.c
index 3bfee2f2fee62814abbb9cad2fcdacdbdbae82bf..f3789f0ace9144c66362768b676426a700e1dc72 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2004 Hiroyuki Yamamoto
+ * Copyright (C) 1999-2005 Hiroyuki Yamamoto
  *
  * 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
@@ -24,6 +24,7 @@
 #include "defs.h"
 
 #include <glib.h>
+#include <glib/gi18n.h>
 #include <gdk/gdkkeysyms.h>
 #include <gtk/gtkmain.h>
 #include <gtk/gtkmenu.h>
@@ -51,6 +52,7 @@
 #include <gtk/gtktreemodel.h>
 
 #include <gtk/gtkdnd.h>
+#include <gtk/gtkclipboard.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -71,7 +73,6 @@
 #  include <wctype.h>
 #endif
 
-#include "intl.h"
 #include "main.h"
 #include "mainwindow.h"
 #include "compose.h"
@@ -452,7 +453,19 @@ static void compose_insert_drag_received_cb (GtkWidget             *widget,
                                             guint               info,
                                             guint               time,
                                             gpointer            user_data);
+static void compose_header_drag_received_cb (GtkWidget         *widget,
+                                            GdkDragContext     *drag_context,
+                                            gint                x,
+                                            gint                y,
+                                            GtkSelectionData   *data,
+                                            guint               info,
+                                            guint               time,
+                                            gpointer            user_data);
 
+static gboolean compose_drag_drop          (GtkWidget *widget,
+                                            GdkDragContext *drag_context,
+                                            gint x, gint y,
+                                            guint time, gpointer user_data);
 #if 0
 static void to_activated               (GtkWidget      *widget,
                                         Compose        *compose);
@@ -470,8 +483,6 @@ static void subject_activated               (GtkWidget      *widget,
                                         Compose        *compose);
 #endif
 
-static void text_activated             (GtkWidget      *widget,
-                                        Compose        *compose);
 static void text_inserted              (GtkTextBuffer  *buffer,
                                         GtkTextIter    *iter,
                                         const gchar    *text,
@@ -500,7 +511,6 @@ static void compose_check_backwards    (Compose *compose);
 static void compose_check_forwards_go     (Compose *compose);
 #endif
 
-static gboolean compose_send_control_enter     (Compose        *compose);
 static gint compose_defer_auto_save_draft      (Compose        *compose);
 static PrefsAccount *compose_guess_forward_account_from_msginfo        (MsgInfo *msginfo);
 
@@ -666,7 +676,9 @@ static GtkItemFactoryEntry compose_entries[] =
 
 static GtkTargetEntry compose_mime_types[] =
 {
-       {"text/uri-list", 0, 0}
+       {"text/uri-list", 0, 0},
+       {"text/plain", 0, 0},
+       {"STRING", 0, 0}
 };
 
 static gboolean compose_put_existing_to_front(MsgInfo *info)
@@ -1321,26 +1333,18 @@ void compose_reedit(MsgInfo *msginfo)
                                        G_CALLBACK(compose_changed_cb),
                                        compose);
                                        
-       g_signal_handlers_block_by_func(G_OBJECT(textbuf),
-                                       G_CALLBACK(text_inserted),
-                                       compose);
-
        if ((fp = procmime_get_first_text_content(msginfo)) == NULL)
                g_warning("Can't get text part\n");
        else {
                while (fgets(buf, sizeof(buf), fp) != NULL) {
                        strcrchomp(buf);
                        gtk_text_buffer_insert(textbuf, &iter, buf, -1);
-                       gtk_text_buffer_get_iter_at_mark(textbuf, &iter, mark);
                }
                fclose(fp);
        }
        
        compose_attach_parts(compose, msginfo);
 
-       g_signal_handlers_unblock_by_func(G_OBJECT(textbuf),
-                                       G_CALLBACK(text_inserted),
-                                       compose);
        g_signal_handlers_unblock_by_func(G_OBJECT(textbuf),
                                        G_CALLBACK(compose_changed_cb),
                                        compose);
@@ -1375,7 +1379,7 @@ Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo)
 
        gtk_widget_grab_focus(compose->header_last->entry);
 
-       filename = procmsg_get_message_file(msginfo);
+       filename = procmsg_get_message_file_path(msginfo);
        if (filename == NULL)
                return NULL;
 
@@ -1400,12 +1404,12 @@ Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo)
        gtk_editable_set_editable(GTK_EDITABLE(compose->subject_entry), FALSE);
 
        compose_quote_fmt(compose, msginfo, "%M", NULL, NULL);
-       gtk_text_view_set_editable(GTK_TEXT_VIEW(compose->text), TRUE);
+       gtk_text_view_set_editable(GTK_TEXT_VIEW(compose->text), FALSE);
 
        ifactory = gtk_item_factory_from_widget(compose->popupmenu);
        menu_set_sensitive(ifactory, "/Add...", FALSE);
        menu_set_sensitive(ifactory, "/Remove", FALSE);
-       menu_set_sensitive(ifactory, "/Property...", FALSE);
+       menu_set_sensitive(ifactory, "/Properties...", FALSE);
 
        ifactory = gtk_item_factory_from_widget(compose->menubar);
        menu_set_sensitive(ifactory, "/Message/Save", FALSE);
@@ -1413,10 +1417,7 @@ Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo)
        menu_set_sensitive(ifactory, "/Message/Attach file", FALSE);
        menu_set_sensitive(ifactory, "/Message/Insert signature", FALSE);
        menu_set_sensitive(ifactory, "/Edit", FALSE);
-       menu_set_sensitive(ifactory, "/Options/Sign", FALSE);
-       menu_set_sensitive(ifactory, "/Options/Encrypt", FALSE);
-       menu_set_sensitive(ifactory, "/Options/Priority", FALSE);
-       menu_set_sensitive(ifactory, "/Options/Request Return Receipt", FALSE);
+       menu_set_sensitive(ifactory, "/Options", FALSE);
        menu_set_sensitive(ifactory, "/Tools/Show ruler", FALSE);
        menu_set_sensitive(ifactory, "/Tools/Actions", FALSE);
        
@@ -1581,6 +1582,8 @@ static void compose_entries_set(Compose *compose, const gchar *mailto)
        gchar *bcc = NULL;
        gchar *subject = NULL;
        gchar *body = NULL;
+       gchar *temp = NULL;
+       gint  len = 0;
 
        scan_mailto_url(mailto, &to, &cc, &bcc, &subject, &body);
 
@@ -1591,7 +1594,13 @@ static void compose_entries_set(Compose *compose, const gchar *mailto)
        if (bcc)
                compose_entry_append(compose, bcc, COMPOSE_BCC);
        if (subject)
-               gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject);
+               if (!g_utf8_validate (subject, -1, NULL)) {
+                       temp = g_locale_to_utf8 (subject, -1, NULL, &len, NULL);
+                       gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), temp);
+                       g_free(temp);
+               } else {
+                       gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), subject);
+               }
        if (body) {
                GtkTextView *text = GTK_TEXT_VIEW(compose->text);
                GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
@@ -1601,7 +1610,13 @@ static void compose_entries_set(Compose *compose, const gchar *mailto)
                mark = gtk_text_buffer_get_insert(buffer);
                gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
 
-               gtk_text_buffer_insert(buffer, &iter, body, -1);
+               if (!g_utf8_validate (body, -1, NULL)) {
+                       temp = g_locale_to_utf8 (body, -1, NULL, &len, NULL);
+                       gtk_text_buffer_insert(buffer, &iter, temp, -1);
+                       g_free(temp);
+               } else {
+                       gtk_text_buffer_insert(buffer, &iter, body, -1);
+               }
                gtk_text_buffer_insert(buffer, &iter, "\n", 1);
        }
 
@@ -2141,6 +2156,7 @@ static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *fi
        GtkTextBuffer *buffer;
        GtkTextMark *mark;
        GtkTextIter iter;
+       const gchar *cur_encoding;
        gchar buf[BUFFSIZE];
        gint len;
        FILE *fp;
@@ -2162,14 +2178,12 @@ static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *fi
                                        G_CALLBACK(text_inserted),
                                        compose);
 
+       cur_encoding = conv_get_locale_charset_str();
+
        while (fgets(buf, sizeof(buf), fp) != NULL) {
-               const gchar *cur_encoding = conv_get_current_charset_str();
-               gchar *str = NULL;
-               if (!g_utf8_validate(buf, -1, NULL))
-                       str = conv_codeset_strdup(buf, cur_encoding, CS_UTF_8);
-               else
-                       str = g_strdup(buf);
+               gchar *str;
 
+               str = conv_codeset_strdup(buf, cur_encoding, CS_INTERNAL);
                if (!str) continue;
 
                /* strip <CR> if DOS/Windows file,
@@ -2180,9 +2194,9 @@ static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *fi
                        while (--len >= 0)
                                if (str[len] == '\r') str[len] = '\n';
                }
-               gtk_text_buffer_insert(buffer, &iter, str, -1);
 
-               g_free (str);
+               gtk_text_buffer_insert(buffer, &iter, str, -1);
+               g_free(str);
        }
 
        g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
@@ -2425,37 +2439,22 @@ static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
 #define CHAR_BUF_SIZE 8
 #undef NEXT_PART_NOT_CHILD
 
-#define GET_CHAR(iter_p, buf, len)                                          \
-{                                                                           \
-       GtkTextIter end_iter;                                                \
-       gchar *tmp;                                                          \
-       end_iter = *iter_p;                                                  \
-       gtk_text_iter_forward_char(&end_iter);                               \
-       tmp = gtk_text_buffer_get_text(textbuf, iter_p, &end_iter, FALSE);   \
-       if (tmp) {                                                           \
-               glong items_read, items_witten;                              \
-               GError *error = NULL;                                        \
-               gunichar *wide_char;                                         \
-               strncpy2(buf, tmp, CHAR_BUF_SIZE);                           \
-               wide_char = g_utf8_to_ucs4(tmp, -1,                          \
-                                          &items_read, &items_witten,       \
-                                          &error);                          \
-               if (error != NULL) {                                         \
-                       g_warning("%s\n", error->message);                   \
-                       g_error_free(error);                                 \
-               }                                                            \
-               len = wide_char && g_unichar_iswide(*wide_char) ? 2 : 1;     \
-               g_free(wide_char);                                           \
-       } else {                                                             \
-               buf[0] = '\0';                                               \
-               len = 1;                                                     \
-       }                                                                    \
-       g_free(tmp);                                                         \
-}
 
+#define GET_CHAR(iter_p, buf, len)                             \
+{                                                              \
+       gunichar uc;                                            \
+                                                               \
+       uc = gtk_text_iter_get_char(iter_p);                    \
+       if (uc != 0)                                            \
+               len = g_unichar_to_utf8(uc, buf) > 1 ? 2 : 1;   \
+       else {                                                  \
+               buf[0] = '\0';                                  \
+               len = 1;                                        \
+       }                                                       \
+}
 #define DISP_WIDTH(len) \
-       ((len > 2 && conv_get_current_charset() == C_UTF_8) ? 2 : \
-        (len == 2 && conv_get_current_charset() == C_UTF_8) ? 1 : len)
+       ((len > 2 && conv_get_locale_charset() == C_UTF_8) ? 2 : \
+        (len == 2 && conv_get_locale_charset() == C_UTF_8) ? 1 : len)
 
 #define SPACE_CHARS    " \t"
 
@@ -2638,15 +2637,15 @@ static void compose_wrap_line(Compose *compose)
 /* Darko: used when I debug wrapping */
 void dump_text(GtkTextBuffer *textbuf, int pos, int tlen, int breakoncr)
 {
-       gint i, clen;
-       gchar cbuf[CHAR_BUF_SIZE];
        GtkTextIter iter, end_iter;
+       gint clen;
+       gchar cbuf[CHAR_BUF_SIZE];
 
        printf("%d [", pos);
        gtk_text_buffer_get_iter_at_offset(textbuf, &iter, pos);
        gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter, pos + tlen);
        for (; gtk_text_iter_forward_char(&iter) &&
-                    gtk_text_iter_compare(&iter, &end_iter) < 0;) {
+            gtk_text_iter_compare(&iter, &end_iter) < 0; ) {
                GET_CHAR(&iter, cbuf, clen);
                if (clen < 0) break;
                if (breakoncr && clen == 1 && cbuf[0] == '\n')
@@ -2669,23 +2668,25 @@ typedef enum {
    uppercase characters immediately followed by >,
    and the repeating sequences of the above */
 /* return indent length */
-static guint get_indent_length(GtkTextBuffer *textbuf, guint start_pos, guint text_len)
+static guint get_indent_length(GtkTextBuffer *textbuf, guint start_pos,
+                              guint text_len)
 {
+       GtkTextIter iter;
        guint i_len = 0;
-       guint i, ch_len, alnum_cnt = 0;
+       guint ch_len, alnum_cnt = 0;
        IndentState state = WAIT_FOR_INDENT_CHAR;
        gchar cbuf[CHAR_BUF_SIZE];
        gboolean is_space;
        gboolean is_indent;
+       gboolean iter_next = TRUE;
 
        if (prefs_common.quote_chars == NULL) {
                return 0 ;
        }
 
-       for (i = start_pos; i < text_len; i++) {
-               GtkTextIter iter;
+       gtk_text_buffer_get_iter_at_offset(textbuf, &iter, start_pos);
 
-               gtk_text_buffer_get_iter_at_offset(textbuf, &iter, i);
+       while (iter_next == TRUE) {
                GET_CHAR(&iter, cbuf, ch_len);
                if (ch_len > 1)
                        break;
@@ -2733,6 +2734,7 @@ static guint get_indent_length(GtkTextBuffer *textbuf, guint start_pos, guint te
                }
 
                i_len++;
+               iter_next = gtk_text_iter_forward_char(&iter);
        }
 
 out:
@@ -3220,11 +3222,11 @@ static void compose_select_account(Compose *compose, PrefsAccount *account,
 
 #endif
 
-       if (account->default_sign)
+       if (account->default_sign && compose->mode != COMPOSE_REDIRECT)
                menu_set_active(ifactory, "/Options/Sign", TRUE);
        else
                menu_set_active(ifactory, "/Options/Sign", FALSE);
-       if (account->default_encrypt)
+       if (account->default_encrypt && compose->mode != COMPOSE_REDIRECT)
                menu_set_active(ifactory, "/Options/Encrypt", TRUE);
        else
                menu_set_active(ifactory, "/Options/Encrypt", FALSE);
@@ -3293,7 +3295,7 @@ static gboolean compose_check_entries(Compose *compose, gboolean check_subject)
 
                aval = alertpanel(_("Send"),
                                  _("Subject is empty. Send it anyway?"),
-                                 _("Yes"), _("No"), NULL);
+                                 GTK_STOCK_YES, GTK_STOCK_NO, NULL);
                if (aval != G_ALERTDEFAULT)
                        return FALSE;
        }
@@ -3612,7 +3614,7 @@ static gint compose_write_to_file(Compose *compose, FILE *fp, gint action)
                else
                        encoding = procmime_get_encoding_for_charset(out_codeset);
 
-               src_codeset = CS_UTF_8;
+               src_codeset = CS_INTERNAL;
                /* if current encoding is US-ASCII, set it the same as
                   outgoing one to prevent code conversion failure */
                if (!g_ascii_strcasecmp(src_codeset, CS_US_ASCII))
@@ -3661,7 +3663,10 @@ static gint compose_write_to_file(Compose *compose, FILE *fp, gint action)
        /* protect trailing spaces when signing message */
        if (action == COMPOSE_WRITE_FOR_SEND && compose->use_signing && 
            privacy_system_can_sign(compose->privacy_system))
-               encoding = ENC_QUOTED_PRINTABLE;
+               if (encoding == ENC_7BIT)
+                       encoding = ENC_QUOTED_PRINTABLE;
+               else if (encoding == ENC_8BIT)
+                       encoding = ENC_BASE64;
        if (encoding != ENC_UNKNOWN)
                procmime_encode_content(mimetext, encoding);
 
@@ -3721,9 +3726,9 @@ static gint compose_write_body_to_file(Compose *compose, const gchar *file)
        gtk_text_buffer_get_end_iter(buffer, &end);
        tmp = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
 
-       src_codeset = CS_UTF_8;
-       dest_codeset = conv_get_current_charset_str();
-       chars = conv_codeset_strdup(tmp, src_codeset, dest_codeset);
+       chars = conv_codeset_strdup
+               (tmp, CS_INTERNAL, conv_get_locale_charset_str());
+
        g_free(tmp);
        if (!chars) return -1;
 
@@ -4439,12 +4444,22 @@ static void compose_create_header_entry(Compose *compose)
        g_signal_connect(G_OBJECT(entry), "changed", 
                         G_CALLBACK(compose_headerentry_changed_cb), 
                         headerentry);
-       g_signal_connect(G_OBJECT(entry), "activate", 
-                        G_CALLBACK(text_activated), compose);
        g_signal_connect(G_OBJECT(entry), "grab_focus",
                         G_CALLBACK(compose_grab_focus_before_cb), compose);
        g_signal_connect_after(G_OBJECT(entry), "grab_focus",
                         G_CALLBACK(compose_grab_focus_cb), compose);
+                        
+       /* email dnd */
+       gtk_drag_dest_set(entry, GTK_DEST_DEFAULT_ALL, compose_mime_types, 
+                         sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
+                         GDK_ACTION_COPY | GDK_ACTION_MOVE);
+       g_signal_connect(G_OBJECT(entry), "drag_data_received",
+                        G_CALLBACK(compose_header_drag_received_cb),
+                        entry);
+       g_signal_connect(G_OBJECT(entry), "drag-drop",
+                        G_CALLBACK(compose_drag_drop),
+                        compose);
+       
        address_completion_register_entry(GTK_ENTRY(entry));
 
         headerentry->compose = compose;
@@ -4662,11 +4677,15 @@ GtkWidget *compose_create_attach(Compose *compose)
 
        /* drag and drop */
        gtk_drag_dest_set(attach_clist,
-                         GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
+                         GTK_DEST_DEFAULT_ALL, compose_mime_types, 
+                         sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
                          GDK_ACTION_COPY | GDK_ACTION_MOVE);
        g_signal_connect(G_OBJECT(attach_clist), "drag_data_received",
                         G_CALLBACK(compose_attach_drag_received_cb),
                         compose);
+       g_signal_connect(G_OBJECT(attach_clist), "drag-drop",
+                        G_CALLBACK(compose_drag_drop),
+                        compose);
 
        compose->attach_scrwin = attach_scrwin;
        compose->attach_clist  = attach_clist;
@@ -4784,7 +4803,6 @@ static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
 
        gchar *titles[N_ATTACH_COLS];
        guint n_menu_entries;
-       GtkStyle  *style, *new_style;
        GdkColormap *cmap;
        GdkColor color[1];
        gboolean success[1];
@@ -4889,8 +4907,6 @@ static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
 
        subject_entry = gtk_entry_new();
        gtk_box_pack_start(GTK_BOX(subject), subject_entry, TRUE, TRUE, 2);
-       g_signal_connect(G_OBJECT(subject_entry), "activate", 
-                        G_CALLBACK(text_activated), compose);
        g_signal_connect(G_OBJECT(subject_entry), "grab_focus",
                         G_CALLBACK(compose_grab_focus_before_cb), compose);
        g_signal_connect_after(G_OBJECT(subject_entry), "grab_focus",
@@ -4910,13 +4926,14 @@ static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
        ruler = gtk_shruler_new();
        gtk_ruler_set_range(GTK_RULER(ruler), 0.0, 100.0, 1.0, 100.0);
        gtk_box_pack_start(GTK_BOX(ruler_hbox), ruler, TRUE, TRUE,
-                          BORDER_WIDTH + 1);
-       gtk_widget_set_size_request(ruler_hbox, 1, -1);
+                          BORDER_WIDTH);
 
        /* text widget */
        scrolledwin = gtk_scrolled_window_new(NULL, NULL);
        gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
                                       GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
+       gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwin),
+                                           GTK_SHADOW_IN);
        gtk_box_pack_start(GTK_BOX(edit_vbox), scrolledwin, TRUE, TRUE, 0);
        gtk_widget_set_size_request(scrolledwin, prefs_common.compose_width, -1);
 
@@ -4926,6 +4943,10 @@ static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
        gtk_text_view_set_editable(GTK_TEXT_VIEW(text), TRUE);
        clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
        gtk_text_buffer_add_selection_clipboard(buffer, clipboard);
+       clipboard = gtk_clipboard_get(GDK_SELECTION_SECONDARY);
+       gtk_text_buffer_add_selection_clipboard(buffer, clipboard);
+       clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);
+       gtk_text_buffer_add_selection_clipboard(buffer, clipboard);
        
        gtk_container_add(GTK_CONTAINER(scrolledwin), text);
 
@@ -4936,15 +4957,19 @@ static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
                         G_CALLBACK(compose_changed_cb), compose);
        g_signal_connect(G_OBJECT(text), "grab_focus",
                         G_CALLBACK(compose_grab_focus_cb), compose);
-       g_signal_connect(G_OBJECT(buffer), "insert-text",
+       g_signal_connect(G_OBJECT(buffer), "insert_text",
                         G_CALLBACK(text_inserted), compose);
 
        /* drag and drop */
-       gtk_drag_dest_set(text, GTK_DEST_DEFAULT_ALL, compose_mime_types, 1,
+       gtk_drag_dest_set(text, GTK_DEST_DEFAULT_ALL, compose_mime_types, 
+                         sizeof(compose_mime_types)/sizeof(compose_mime_types[0]),
                          GDK_ACTION_COPY | GDK_ACTION_MOVE);
        g_signal_connect(G_OBJECT(text), "drag_data_received",
                         G_CALLBACK(compose_insert_drag_received_cb),
                         compose);
+       g_signal_connect(G_OBJECT(text), "drag-drop",
+                        G_CALLBACK(compose_drag_drop),
+                        compose);
        gtk_widget_show_all(vbox);
 
        /* pane between attach clist and text */
@@ -4955,29 +4980,24 @@ static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
        gtk_paned_add2(GTK_PANED(paned), edit_vbox);
        gtk_widget_show_all(paned);
 
-       style = gtk_widget_get_style(text);
-
-       new_style = gtk_style_copy(style);
 
        if (prefs_common.textfont) {
                PangoFontDescription *font_desc;
 
                font_desc = pango_font_description_from_string
-                                       (prefs_common.textfont);
+                       (prefs_common.textfont);
                if (font_desc) {
-                       if (new_style->font_desc)
-                               pango_font_description_free
-                                       (new_style->font_desc);
-                       new_style->font_desc = font_desc;
+                       gtk_widget_modify_font(text, font_desc);
+                       pango_font_description_free(font_desc);
                }
        }
 
-       gtk_widget_set_style(text, new_style);
-
        color[0] = quote_color;
        cmap = gdk_window_get_colormap(window->window);
        gdk_colormap_alloc_colors(cmap, color, 1, FALSE, TRUE, success);
        if (success[0] == FALSE) {
+               GtkStyle *style;
+
                g_warning("Compose: color allocation failed.\n");
                style = gtk_widget_get_style(text);
                quote_color = style->black;
@@ -5072,7 +5092,7 @@ static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
                    strcmp(prefs_common.dictionary, _("None"))) {
                        gtkaspell = gtkaspell_new(prefs_common.aspell_path,
                                                  prefs_common.dictionary,
-                                                 conv_get_current_charset_str(),
+                                                 conv_get_locale_charset_str(),
                                                  prefs_common.misspelled_col,
                                                  prefs_common.check_while_typing,
                                                  prefs_common.use_alternate,
@@ -5853,8 +5873,8 @@ static void compose_attach_property_create(gboolean *cancelled)
        SET_LABEL_AND_ENTRY(_("Path"),      path_entry,     2);
        SET_LABEL_AND_ENTRY(_("File name"), filename_entry, 3);
 
-       gtkut_button_set_create_stock(&hbbox, &ok_btn, GTK_STOCK_OK,
-                                     &cancel_btn, GTK_STOCK_CANCEL, 
+       gtkut_stock_button_set_create(&hbbox, &ok_btn, GTK_STOCK_OK,
+                                     &cancel_btn, GTK_STOCK_CANCEL,
                                      NULL, NULL);
        gtk_box_pack_end(GTK_BOX(vbox), hbbox, FALSE, FALSE, 0);
        gtk_widget_grab_default(ok_btn);
@@ -6494,9 +6514,11 @@ static void compose_attach_cb(gpointer data, guint action, GtkWidget *widget)
 
                for ( tmp = file_list; tmp; tmp = tmp->next) {
                        gchar *file = (gchar *) tmp->data;
-                       compose_attach_append(compose, file, file, NULL);
+                       gchar *utf8_filename = conv_filename_to_utf8(file);
+                       compose_attach_append(compose, file, utf8_filename, NULL);
                        compose_changed_cb(NULL, compose);
                        g_free(file);
+                       g_free(utf8_filename);
                }
                g_list_free(file_list);
        }               
@@ -6571,7 +6593,7 @@ static void compose_close_cb(gpointer data, guint action, GtkWidget *widget)
        if (compose->modified) {
                val = alertpanel(_("Discard message"),
                                 _("This message has been modified. discard it?"),
-                                _("Discard"), _("to Draft"), _("Cancel"));
+                                _("Discard"), _("to Draft"), GTK_STOCK_CANCEL);
 
                switch (val) {
                case G_ALERTDEFAULT:
@@ -6609,7 +6631,7 @@ static void compose_template_activate_cb(GtkWidget *widget, gpointer data)
        msg = g_strdup_printf(_("Do you want to apply the template `%s' ?"),
                              tmpl->name);
        val = alertpanel(_("Apply template"), msg,
-                        _("Replace"), _("Insert"), _("Cancel"));
+                        _("Replace"), _("Insert"), GTK_STOCK_CANCEL);
        g_free(msg);
 
        if (val == G_ALERTDEFAULT)
@@ -7132,15 +7154,27 @@ static void compose_attach_drag_received_cb (GtkWidget          *widget,
 {
        Compose *compose = (Compose *)user_data;
        GList *list, *tmp;
+       
+       if (gdk_atom_name(data->type) && !strcmp(gdk_atom_name(data->type), "text/uri-list")) {
+               list = uri_list_extract_filenames((const gchar *)data->data);
+               for (tmp = list; tmp != NULL; tmp = tmp->next)
+                       compose_attach_append
+                               (compose, (const gchar *)tmp->data,
+                                (const gchar *)tmp->data, NULL);
+               if (list) compose_changed_cb(NULL, compose);
+               list_free_strings(list);
+               g_list_free(list);
+       }
+}
 
-       list = uri_list_extract_filenames((const gchar *)data->data);
-       for (tmp = list; tmp != NULL; tmp = tmp->next)
-               compose_attach_append
-                       (compose, (const gchar *)tmp->data,
-                        (const gchar *)tmp->data, NULL);
-       if (list) compose_changed_cb(NULL, compose);
-       list_free_strings(list);
-       g_list_free(list);
+static gboolean compose_drag_drop(GtkWidget *widget,
+                                 GdkDragContext *drag_context,
+                                 gint x, gint y,
+                                 guint time, gpointer user_data)
+{
+       /* not handling this signal makes compose_insert_drag_received_cb
+        * called twice */
+       return TRUE;                                     
 }
 
 static void compose_insert_drag_received_cb (GtkWidget         *widget,
@@ -7155,11 +7189,56 @@ static void compose_insert_drag_received_cb (GtkWidget          *widget,
        Compose *compose = (Compose *)user_data;
        GList *list, *tmp;
 
-       list = uri_list_extract_filenames((const gchar *)data->data);
-       for (tmp = list; tmp != NULL; tmp = tmp->next)
-               compose_insert_file(compose, (const gchar *)tmp->data);
-       list_free_strings(list);
-       g_list_free(list);
+       /* strangely, testing data->type == gdk_atom_intern("text/uri-list", TRUE)
+        * does not work */
+       if (gdk_atom_name(data->type) && !strcmp(gdk_atom_name(data->type), "text/uri-list")) {
+               list = uri_list_extract_filenames((const gchar *)data->data);
+               for (tmp = list; tmp != NULL; tmp = tmp->next) {
+                               compose_insert_file(compose, (const gchar *)tmp->data);
+               }
+               list_free_strings(list);
+               g_list_free(list);
+               gtk_drag_finish(drag_context, TRUE, FALSE, time);
+               return;
+       } else {
+               gchar *tmpfile = get_tmp_file();
+               str_write_to_file((const gchar *)data->data, tmpfile);
+               compose_insert_file(compose, tmpfile);
+               unlink(tmpfile);
+               g_free(tmpfile);
+               gtk_drag_finish(drag_context, TRUE, FALSE, time);
+               return;
+       }
+       gtk_drag_finish(drag_context, TRUE, FALSE, time);
+}
+
+static void compose_header_drag_received_cb (GtkWidget         *widget,
+                                            GdkDragContext     *drag_context,
+                                            gint                x,
+                                            gint                y,
+                                            GtkSelectionData   *data,
+                                            guint               info,
+                                            guint               time,
+                                            gpointer            user_data)
+{
+       GtkEditable *entry = (GtkEditable *)user_data;
+       gchar *email = (gchar *)data->data;
+
+       /* strangely, testing data->type == gdk_atom_intern("text/plain", TRUE)
+        * does not work */
+
+       if (!strncmp(email, "mailto:", strlen("mailto:"))) {
+               gchar decoded[strlen(email)];
+               int start = 0;
+
+               email += strlen("mailto:");
+               decode_uri(decoded, email); /* will fit */
+               gtk_editable_delete_text(entry, 0, -1);
+               gtk_editable_insert_text(entry, decoded, strlen(decoded), &start);
+               gtk_drag_finish(drag_context, TRUE, FALSE, time);
+               return;
+       }
+       gtk_drag_finish(drag_context, TRUE, FALSE, time);
 }
 
 #if 0 /* NEW COMPOSE GUI */
@@ -7312,18 +7391,19 @@ static void compose_show_first_last_header(Compose *compose, gboolean show_first
        gtk_adjustment_set_value(vadj, (show_first ? vadj->lower : vadj->upper));
 }
 
-static void text_activated(GtkWidget *widget, Compose *compose)
-{
-       compose_send_control_enter(compose);
-}
-
 static void text_inserted(GtkTextBuffer *buffer, GtkTextIter *iter,
                          const gchar *text, gint len, Compose *compose)
 {
        gint paste_as_quotation = GPOINTER_TO_INT(g_object_get_data
                                (G_OBJECT(compose->text), "paste_as_quotation"));
+       GtkTextMark *mark;
+
+       /* CLAWS: pass to default handler only if not pasting as quotation, and 
+        * no autowrap */
+       if (!paste_as_quotation && !compose->autowrap) 
+               return;
 
-       g_return_if_fail(text);
+       g_return_if_fail(text != NULL);
 
        g_signal_handlers_block_by_func(G_OBJECT(buffer),
                                        G_CALLBACK(text_inserted),
@@ -7348,8 +7428,10 @@ static void text_inserted(GtkTextBuffer *buffer, GtkTextIter *iter,
        } else
                gtk_text_buffer_insert(buffer, iter, text, len);
 
-       if (compose->autowrap)
-               compose_wrap_line_all_full(compose, TRUE);
+       mark = gtk_text_buffer_create_mark(buffer, NULL, iter, FALSE);
+       compose_wrap_line_all_full(compose, TRUE);
+       gtk_text_buffer_get_iter_at_mark(buffer, iter, mark);
+       gtk_text_buffer_delete_mark(buffer, mark);
 
        g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
                                          G_CALLBACK(text_inserted),
@@ -7361,7 +7443,6 @@ static void text_inserted(GtkTextBuffer *buffer, GtkTextIter *iter,
                compose->draft_timeout_tag = gtk_timeout_add
                        (500, (GtkFunction) compose_defer_auto_save_draft, compose);
 }
-
 static gint compose_defer_auto_save_draft(Compose *compose)
 {
        compose->draft_timeout_tag = -1;
@@ -7369,45 +7450,6 @@ static gint compose_defer_auto_save_draft(Compose *compose)
        return FALSE;
 }
 
-static gboolean compose_send_control_enter(Compose *compose)
-{
-       GdkEvent *ev;
-       GdkEventKey *kev;
-       GtkItemFactory *ifactory;
-       GtkAccelKey *accel;
-       GtkWidget *send_menu;
-       GSList *list;
-       GdkModifierType ignored_mods =
-               (GDK_LOCK_MASK | GDK_MOD2_MASK | GDK_MOD3_MASK |
-                GDK_MOD4_MASK | GDK_MOD5_MASK);
-
-       ev = gtk_get_current_event();
-       if (ev->type != GDK_KEY_PRESS) return FALSE;
-
-       kev = (GdkEventKey *)ev;
-       if (!(kev->keyval == GDK_Return && (kev->state & GDK_CONTROL_MASK)))
-               return FALSE;
-
-       if (compose->exteditor_tag != -1)
-               return FALSE;
-
-       ifactory = gtk_item_factory_from_widget(compose->menubar);
-       send_menu = gtk_item_factory_get_widget(ifactory, "/Message/Send");
-       list = gtk_accel_groups_from_object(G_OBJECT(send_menu));
-       if (!list)
-               return FALSE;
-
-       accel = (GtkAccelKey *)list->data;
-       if (accel && accel->accel_key == kev->keyval &&
-           (accel->accel_mods & ~ignored_mods) ==
-           (kev->state & ~ignored_mods)) {
-               compose_send_cb(compose, 0, NULL);
-               return TRUE;
-       }
-
-       return FALSE;
-}
-
 #if USE_ASPELL
 static void compose_check_all(Compose *compose)
 {
@@ -7510,7 +7552,44 @@ static void compose_add_field_list( Compose *compose, GList *listAddress ) {
        }
 }
 
+void compose_reply_from_messageview(MessageView *msgview, GSList *msginfo_list, 
+                                   guint action)
+{
+       gchar *body;
+       GSList *new_msglist = NULL;
+       MsgInfo *tmp_msginfo = NULL;
+       
+       g_return_if_fail(msgview != NULL);
+
+       g_return_if_fail(msginfo_list != NULL);
+
+       if (g_slist_length(msginfo_list) == 1) {
+               MimeInfo *mimeinfo = messageview_get_selected_mime_part(msgview);
+               MsgInfo *orig_msginfo = (MsgInfo *)msginfo_list->data;
+               
+               if (mimeinfo != NULL && mimeinfo->type == MIMETYPE_MESSAGE && 
+                   !g_ascii_strcasecmp(mimeinfo->subtype, "rfc822")) {
+                       
+                       tmp_msginfo = procmsg_msginfo_new_from_mimeinfo(
+                                               orig_msginfo, mimeinfo);
+                       if (tmp_msginfo != NULL) {
+                               new_msglist = g_slist_append(NULL, tmp_msginfo);
+                       } 
+               }
+       }
+
+       body = messageview_get_selection(msgview);
+
+       if (new_msglist) {
+               compose_reply_mode((ComposeMode)action, new_msglist, body);
+               procmsg_msginfo_free(tmp_msginfo);
+               g_slist_free(new_msglist);
+       } else
+               compose_reply_mode((ComposeMode)action, msginfo_list, body);
+
+       g_free(body);
+}
+
 /*
  * End of Source.
  */
-