Sync with hiro's cvs 10 to 17.
[claws.git] / src / compose.c
index aad24df71b6171c73b74d1c2d185d2dd3132ee49..5332fa4f48f8aa272a28a3a7b0a953420513a925 100644 (file)
@@ -53,6 +53,8 @@
 #include <stdlib.h>
 #include <string.h>
 #include <ctype.h>
+#include <sys/types.h>
+#include <sys/stat.h>
 #include <unistd.h>
 #include <time.h>
 /* #include <sys/utsname.h> */
 #  include <wctype.h>
 #endif
 
-
-#include "gtkstext.h"
-
 #include "intl.h"
 #include "main.h"
 #include "mainwindow.h"
 #include "compose.h"
+#include "gtkstext.h"
 #include "addressbook.h"
 #include "folderview.h"
 #include "procmsg.h"
@@ -426,6 +426,10 @@ void compose_headerentry_key_press_event_cb(GtkWidget             *entry,
                                            GdkEventKey        *event,
                                            ComposeHeaderEntry *headerentry);
 
+static void compose_show_first_last_header (Compose *compose, gboolean show_first);
+
+static void compose_ctl_enter_send_shortcut_cb(GtkWidget *w, Compose *compose);
+
 static GtkItemFactoryEntry compose_popup_entries[] =
 {
        {N_("/_Add..."),        NULL, compose_attach_cb, 0, NULL},
@@ -443,21 +447,34 @@ static GtkItemFactoryEntry compose_entries[] =
        {N_("/_File/---"),                      NULL, NULL, 0, "<Separator>"},
        {N_("/_File/_Close"),                   "<alt>W", compose_close_cb, 0, NULL},
 
-       {N_("/_Edit"),             NULL, NULL, 0, "<Branch>"},
-       {N_("/_Edit/_Undo"),       "<control>Z", compose_undo_cb, 0, NULL},
-       {N_("/_Edit/_Redo"),       "<control>Y", compose_redo_cb, 0, NULL},
-       {N_("/_Edit/---"),         NULL, NULL, 0, "<Separator>"},
-       {N_("/_Edit/Cu_t"),        "<control>X", compose_cut_cb,    0, NULL},
-       {N_("/_Edit/_Copy"),       "<control>C", compose_copy_cb,   0, NULL},
-       {N_("/_Edit/_Paste"),      "<control>V", compose_paste_cb,  0, NULL},
-       {N_("/_Edit/Select _all"), "<control>A", compose_allsel_cb, 0, NULL},
-       {N_("/_Edit/---"),         NULL, NULL, 0, "<Separator>"},
-       {N_("/_Edit/_Wrap current paragraph"), "<alt>L", compose_wrap_line, 0, NULL},
+       {N_("/_Edit"),                  NULL, NULL, 0, "<Branch>"},
+       {N_("/_Edit/_Undo"),            "<control>Z", compose_undo_cb, 0, NULL},
+       {N_("/_Edit/_Redo"),            "<control>Y", compose_redo_cb, 0, NULL},
+       {N_("/_Edit/---"),              NULL, NULL, 0, "<Separator>"},
+       {N_("/_Edit/Cu_t"),             "<control>X", compose_cut_cb,    0, NULL},
+       {N_("/_Edit/_Copy"),            "<control>C", compose_copy_cb,   0, NULL},
+       {N_("/_Edit/_Paste"),           "<control>V", compose_paste_cb,  0, NULL},
+       {N_("/_Edit/Select _all"),      "<control>A", compose_allsel_cb, 0, NULL},
+       {N_("/_Edit/---"),              NULL, NULL, 0, "<Separator>"},
+       {N_("/_Edit/_Wrap current paragraph"),
+                                       "<alt>L", compose_wrap_line, 0, NULL},
        {N_("/_Edit/Wrap all long _lines"),
-                       "<shift><alt>L", compose_wrap_line_all, 0, NULL},
+                                       "<shift><alt>L", compose_wrap_line_all, 0, NULL},
        {N_("/_Edit/Edit with e_xternal editor"),
-                       "<alt>X", compose_ext_editor_cb, 0, NULL},
-
+                                       "<alt>X", compose_ext_editor_cb, 0, NULL},
+#if 0 /* NEW COMPOSE GUI */
+       {N_("/_View"),                  NULL, NULL, 0, "<Branch>"},
+       {N_("/_View/_To"),              NULL, compose_toggle_to_cb     , 0, "<ToggleItem>"},
+       {N_("/_View/_Cc"),              NULL, compose_toggle_cc_cb     , 0, "<ToggleItem>"},
+       {N_("/_View/_Bcc"),             NULL, compose_toggle_bcc_cb    , 0, "<ToggleItem>"},
+       {N_("/_View/_Reply to"),        NULL, compose_toggle_replyto_cb, 0, "<ToggleItem>"},
+       {N_("/_View/---"),              NULL, NULL, 0, "<Separator>"},
+       {N_("/_View/_Followup to"),     NULL, compose_toggle_followupto_cb, 0, "<ToggleItem>"},
+       {N_("/_View/---"),              NULL, NULL, 0, "<Separator>"},
+       {N_("/_View/R_uler"),           NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
+       {N_("/_View/---"),              NULL, NULL, 0, "<Separator>"},
+       {N_("/_View/_Attachment"),      NULL, compose_toggle_attach_cb, 0, "<ToggleItem>"},
+#endif
        {N_("/_Message"),               NULL, NULL, 0, "<Branch>"},
        {N_("/_Message/_Send"),         "<control>Return",
                                        compose_send_cb, 0, NULL},
@@ -465,6 +482,8 @@ static GtkItemFactoryEntry compose_entries[] =
                                        compose_send_later_cb,  0, NULL},
        {N_("/_Message/Save to _draft folder"),
                                        "<alt>D", compose_draft_cb, 0, NULL},
+       {N_("/_Message/Save and _keep editing"),
+                                       "<control>S", compose_draft_cb, 1, NULL},
 #if 0 /* NEW COMPOSE GUI */
        {N_("/_Message/---"),           NULL, NULL, 0, "<Separator>"},
        {N_("/_Message/_To"),           NULL, compose_toggle_to_cb     , 0, "<ToggleItem>"},
@@ -487,7 +506,7 @@ static GtkItemFactoryEntry compose_entries[] =
        {N_("/_Tool/Show _ruler"),      NULL, compose_toggle_ruler_cb, 0, "<ToggleItem>"},
        {N_("/_Tool/_Address book"),    "<alt>A", compose_address_cb , 0, NULL},
        {N_("/_Tool/_Template"),        NULL, NULL, 0, "<Branch>"},
-       {N_("/_Help"),                  NULL, NULL, 0, "<LastBranch>"},
+       {N_("/_Help"),                  NULL, NULL, 0, "<Branch>"},
        {N_("/_Help/_About"),           NULL, about_show, 0, NULL}
 };
 
@@ -599,6 +618,7 @@ Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderI
                        compose_entry_append(compose, mailto, COMPOSE_NEWSGROUPS);
                }
        }
+       compose_show_first_last_header(compose, TRUE);
 
        /* Set save folder */
        if(item && item->prefs && item->prefs->save_copy_to_folder) {
@@ -610,7 +630,7 @@ Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderI
                g_free(folderidentifier);
        }
 
-       gtk_widget_grab_focus(compose->subject_entry);
+       gtk_widget_grab_focus(compose->header_last->entry);
 
        if (prefs_common.auto_exteditor)
                compose_exec_ext_editor(compose);
@@ -684,6 +704,9 @@ static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
        
        /* select the account for the whole folder (IMAP / NNTP) */
        if (!account)
+               /* FIXME: this is not right, because folder may be nested. we should
+                * ascend the tree until we find a parent with proper account 
+                * information */
                account = msginfo->folder->folder->account;
 
        /* select account by to: and cc: header if enabled */
@@ -755,6 +778,7 @@ static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
        if (compose_parse_header(compose, msginfo) < 0) return;
        compose_reply_set_entry(compose, msginfo, to_all, ignore_replyto,
                                followup_and_reply_to);
+       compose_show_first_last_header(compose, TRUE);
 
        text = GTK_STEXT(compose->text);
        gtk_stext_freeze(text);
@@ -860,7 +884,7 @@ static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
 #if USE_GPGME
        for (;;) {
                if ((fp = procmsg_open_message(msginfo)) == NULL) return;
-               mimeinfo = procmime_scan_mime_header(fp);
+               mimeinfo = procmime_scan_mime_header(fp, MIME_TEXT);
                if (!mimeinfo) break;
 
                if (!MSG_IS_ENCRYPTED(msginfo->flags) &&
@@ -882,7 +906,7 @@ static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
        }
 #else /* !USE_GPGME */
        if ((fp = procmsg_open_message(msginfo)) == NULL) return;
-       mimeinfo = procmime_scan_mime_header(fp);
+       mimeinfo = procmime_scan_mime_header(fp, MIME_TEXT);
 #endif /* USE_GPGME */
 
        fclose(fp);
@@ -927,7 +951,7 @@ static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
 
                prev_fpos = fpos;
 
-               partinfo = procmime_scan_mime_header(fp);
+               partinfo = procmime_scan_mime_header(fp, MIME_TEXT);
                if (!partinfo) break;
 
                if (npart != 0)
@@ -1689,13 +1713,15 @@ static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
        SET_ADDRESS(COMPOSE_BCC, compose->bcc);
        SET_ADDRESS(COMPOSE_REPLYTO, compose->replyto);
 
+       compose_show_first_last_header(compose, TRUE);
+
 #if 0 /* NEW COMPOSE GUI */
        if (compose->bcc) {
                GtkItemFactory *ifactory;
                GtkWidget *menuitem;
 
                ifactory = gtk_item_factory_from_widget(compose->menubar);
-               menuitem = gtk_item_factory_get_item(ifactory, "/Message/Bcc");
+               menuitem = gtk_item_factory_get_item(ifactory, "/View/Bcc");
                gtk_check_menu_item_set_active
                        (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
        }
@@ -1705,7 +1731,7 @@ static void compose_reedit_set_entry(Compose *compose, MsgInfo *msginfo)
 
                ifactory = gtk_item_factory_from_widget(compose->menubar);
                menuitem = gtk_item_factory_get_item
-                       (ifactory, "/Message/Reply to");
+                       (ifactory, "/View/Reply to");
                gtk_check_menu_item_set_active
                        (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
        }
@@ -1818,8 +1844,7 @@ static void compose_insert_file(Compose *compose, const gchar *file)
                        while (--len >= 0)
                                if (buf[len] == '\r') buf[len] = '\n';
                }
-
-               gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
+               gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
        }
 
        gtk_stext_thaw(text);
@@ -1921,7 +1946,7 @@ static void compose_attach_append(Compose *compose, const gchar *file,
 
                ifactory = gtk_item_factory_from_widget(compose->menubar);
                menuitem = gtk_item_factory_get_item(ifactory,
-                                                    "/Message/Attach");
+                                                    "/View/Attachment");
                gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
                                               TRUE);
        }
@@ -1950,7 +1975,7 @@ static void compose_attach_append(Compose *compose, const gchar *file,
 #define GET_CHAR(pos, buf, len)                                                     \
 {                                                                           \
        if (text->use_wchar)                                                 \
-               len = wctomb(buf, (wchar_t)GTK_STEXT_INDEX(text, (pos)));     \
+               len = wctomb(buf, (wchar_t)GTK_STEXT_INDEX(text, (pos)));    \
        else {                                                               \
                buf[0] = GTK_STEXT_INDEX(text, (pos));                       \
                len = 1;                                                     \
@@ -1969,7 +1994,6 @@ static void compose_wrap_line(Compose *compose)
        gint line_pos, cur_pos;
        gint line_len, cur_len;
 
-
        gtk_stext_freeze(text);
 
        text_len = gtk_stext_get_length(text);
@@ -2204,7 +2228,7 @@ static void compose_wrap_line_all(Compose *compose)
                /* mark position of new line - needed for quotation wrap */
                if (is_new_line) {
                        if (linewrap_quote) {
-                               qlen = gtkut_text_str_compare
+                               qlen = gtkut_stext_str_compare
                                        (text, cur_pos, tlen, qfmt);
                                if (qlen)
                                        i_len = get_indent_length
@@ -2253,7 +2277,7 @@ static void compose_wrap_line_all(Compose *compose)
                        /* if it's just quotation + newline skip it */
                        if (i_len && (cur_pos + 1 < tlen)) {
                                /* check if text at new line matches indent */
-                               ilen =  gtkut_text_str_compare_n
+                               ilen =  gtkut_stext_str_compare_n
                                        (text, cur_pos + 1, p_pos, i_len, tlen);
                                if (cur_pos + ilen < tlen) {
                                        GET_CHAR(cur_pos + ilen + 1, cb, clen);
@@ -2283,16 +2307,16 @@ static void compose_wrap_line_all(Compose *compose)
                                /* if text starts with quote fmt or with
                                   indent string, delete them */
                                if (i_len) {
-                                       ilen =  gtkut_text_str_compare_n
+                                       ilen =  gtkut_stext_str_compare_n
                                                (text, cur_pos, p_pos, i_len,
                                                 tlen);
                                        if (ilen) {
-                                               gtk_stext_forward_delete(text,
-                                                                        ilen);
+                                               gtk_stext_forward_delete
+                                                       (text, ilen);
                                                tlen -= ilen;
                                        }
                                } else if (qlen) {
-                                       if (gtkut_text_str_compare
+                                       if (gtkut_stext_str_compare
                                            (text, cur_pos, tlen, qfmt)) {
                                                gtk_stext_forward_delete
                                                        (text, qlen);
@@ -2307,7 +2331,7 @@ static void compose_wrap_line_all(Compose *compose)
                                    ((clen > 1) || isalnum(cb[0]))) {
                                        gtk_stext_insert(text, NULL, NULL,
                                                        NULL, " ", 1);
-                                       /* gtk_text_compact_buffer(text); */
+                                       /* gtk_stext_compact_buffer(text); */
                                        tlen++;
                                }
 
@@ -2355,8 +2379,8 @@ static void compose_wrap_line_all(Compose *compose)
                        dump_text(text, line_pos, tlen, 1);
 #endif
                        /* force wrapping if it is one long word but not URL */
-                       if (p_pos + i_len == line_pos)
-                               if (!gtkut_text_is_uri_string
+                       if (line_pos - p_pos <= i_len)
+                               if (!gtkut_stext_is_uri_string
                                    (text, line_pos, tlen))
                                        line_pos = cur_pos - 1;
 #ifdef WRAP_DEBUG
@@ -2368,7 +2392,7 @@ static void compose_wrap_line_all(Compose *compose)
                        /* if next character is space delete it */
                         if (clen == 1 && isspace(*cbuf)) {
                                if (p_pos + i_len != line_pos ||
-                                   !gtkut_text_is_uri_string
+                                   !gtkut_stext_is_uri_string
                                        (text, line_pos, tlen)) {
                                        gtk_stext_set_point(text, line_pos);
                                        gtk_stext_backward_delete(text, 1);
@@ -2382,7 +2406,7 @@ static void compose_wrap_line_all(Compose *compose)
 
                        /* if it is URL at beginning of line don't wrap */
                        if (p_pos + i_len == line_pos &&
-                           gtkut_text_is_uri_string(text, line_pos, tlen)) {
+                           gtkut_stext_is_uri_string(text, line_pos, tlen)) {
 #ifdef WRAP_DEBUG
                                printf("found URL at ");
                                dump_text(text, line_pos, tlen, 1);
@@ -2412,7 +2436,7 @@ static void compose_wrap_line_all(Compose *compose)
                        /* should we insert quotation ? */
                        if (linewrap_quote && qlen) {
                                /* only if line is not already quoted  */
-                               if (!gtkut_text_str_compare
+                               if (!gtkut_stext_str_compare
                                        (text, line_pos, tlen, qfmt)) {
                                        guint ins_len;
 
@@ -2443,6 +2467,7 @@ static void compose_wrap_line_all(Compose *compose)
 
        gtk_stext_thaw(text);
 }
+
 #undef GET_CHAR
 
 static void compose_set_title(Compose *compose)
@@ -3723,7 +3748,6 @@ static void compose_generate_msgid(Compose *compose, gchar *buf, gint len)
        g_free(addr);
 }
 
-
 static void compose_add_entry_field(GtkWidget *table, GtkWidget **hbox,
                                    GtkWidget **entry, gint *count,
                                    const gchar *label_str,
@@ -3799,6 +3823,7 @@ static void compose_create_header_entry(Compose *compose)
 
         gtk_signal_connect(GTK_OBJECT(entry), "key-press-event", GTK_SIGNAL_FUNC(compose_headerentry_key_press_event_cb), headerentry);
        gtk_signal_connect(GTK_OBJECT(entry), "changed", GTK_SIGNAL_FUNC(compose_headerentry_changed_cb), headerentry);
+       gtk_signal_connect(GTK_OBJECT(entry), "activate", GTK_SIGNAL_FUNC(compose_ctl_enter_send_shortcut_cb), compose);
 
        address_completion_register_entry(GTK_ENTRY(entry));
 
@@ -3824,6 +3849,7 @@ static void compose_add_header_entry(Compose *compose, gchar *header, gchar *tex
 static GtkWidget *compose_create_header(Compose *compose) 
 {
        GtkWidget *label;
+       GtkWidget *hbox;
        GtkWidget *from_optmenu_hbox;
 #if 0 /* NEW COMPOSE GUI */
        GtkWidget *to_entry;
@@ -3833,7 +3859,6 @@ static GtkWidget *compose_create_header(Compose *compose)
 #endif
        GtkWidget *header_scrolledwin;
        GtkWidget *header_table;
-       GtkWidget *subject_entry;
 #if 0 /* NEW COMPOSE GUI */
        GtkWidget *cc_entry;
        GtkWidget *cc_hbox;
@@ -3844,7 +3869,6 @@ static GtkWidget *compose_create_header(Compose *compose)
        GtkWidget *followup_entry;
        GtkWidget *followup_hbox;
 #endif
-       GtkWidget *hbox;
 
        gint count = 0;
 
@@ -3857,6 +3881,7 @@ static GtkWidget *compose_create_header(Compose *compose)
        gtk_widget_show(header_table);
        gtk_container_set_border_width(GTK_CONTAINER(header_table), 2);
        gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(header_scrolledwin), header_table);
+       gtk_viewport_set_shadow_type(GTK_VIEWPORT(GTK_BIN(header_scrolledwin)->child), GTK_SHADOW_ETCHED_IN);
        count = 0;
 
        /* option menu for selecting accounts */
@@ -3873,10 +3898,6 @@ static GtkWidget *compose_create_header(Compose *compose)
 #endif
        count++;
 
-       /* Subject */
-       compose_add_entry_field(header_table, &hbox, &subject_entry, &count,
-                               "Subject:", FALSE);
-
        compose->header_table = header_table;
        compose->header_list = NULL;
        compose->header_nextrow = count;
@@ -3947,7 +3968,6 @@ static GtkWidget *compose_create_header(Compose *compose)
        compose->newsgroups_hbox  = newsgroups_hbox;
        compose->newsgroups_entry = newsgroups_entry;
 #endif
-       compose->subject_entry    = subject_entry;
 #if 0 /* NEW COMPOSE GUI */
        compose->cc_hbox          = cc_hbox;
        compose->cc_entry         = cc_entry;
@@ -4097,8 +4117,11 @@ static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
 
        GtkWidget *vbox2;
 
-       GtkWidget *table_vbox;
-
+       GtkWidget *label;
+       GtkWidget *subject_hbox;
+       GtkWidget *subject_frame;
+       GtkWidget *subject_entry;
+       GtkWidget *subject;
        GtkWidget *paned;
 
        GtkWidget *edit_vbox;
@@ -4168,15 +4191,10 @@ static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
        vbox2 = gtk_vbox_new(FALSE, 2);
        gtk_box_pack_start(GTK_BOX(vbox), vbox2, TRUE, TRUE, 0);
        gtk_container_set_border_width(GTK_CONTAINER(vbox2), BORDER_WIDTH);
-
-       table_vbox = gtk_vbox_new(FALSE, 0);
-       gtk_box_pack_start(GTK_BOX(vbox2), table_vbox, FALSE, TRUE, 0);
-       gtk_container_set_border_width(GTK_CONTAINER(table_vbox),
-                                      BORDER_WIDTH * 2);
-
+       
        /* Notebook */
        notebook = gtk_notebook_new();
-       gtk_widget_set_usize(notebook, -1, 180);
+       gtk_widget_set_usize(notebook, -1, 130);
        gtk_widget_show(notebook);
 
        /* header labels and entries */
@@ -4186,11 +4204,37 @@ static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
        /* Others Tab */
        gtk_notebook_append_page(GTK_NOTEBOOK(notebook), compose_create_others(compose), gtk_label_new(_("Others")));
 
+       /* Subject */
+       subject_hbox = gtk_hbox_new(FALSE, 0);
+       gtk_widget_show(subject_hbox);
+
+       subject_frame = gtk_frame_new(NULL);
+       gtk_frame_set_shadow_type(GTK_FRAME(subject_frame), GTK_SHADOW_OUT);
+       gtk_box_pack_start(GTK_BOX(subject_hbox), subject_frame, TRUE, TRUE, BORDER_WIDTH+1);
+       gtk_widget_show(subject_frame);
+
+       subject = gtk_hbox_new(FALSE, 0);
+       gtk_container_set_border_width(GTK_CONTAINER(subject), BORDER_WIDTH);
+       gtk_widget_show(subject);
+
+       label = gtk_label_new(_("Subject:"));
+       gtk_box_pack_start(GTK_BOX(subject), label, FALSE, FALSE, 4);
+       gtk_widget_show(label);
+
+       subject_entry = gtk_entry_new();
+       gtk_box_pack_start(GTK_BOX(subject), subject_entry, TRUE, TRUE, 2);
+       gtk_signal_connect(GTK_OBJECT(subject_entry), "activate", GTK_SIGNAL_FUNC(compose_ctl_enter_send_shortcut_cb), compose);
+       gtk_widget_show(subject_entry);
+       compose->subject_entry = subject_entry;
+       gtk_container_add(GTK_CONTAINER(subject_frame), subject);
+       
        edit_vbox = gtk_vbox_new(FALSE, 0);
 #if 0 /* NEW COMPOSE GUI */
        gtk_box_pack_start(GTK_BOX(vbox2), edit_vbox, TRUE, TRUE, 0);
 #endif
 
+       gtk_box_pack_start(GTK_BOX(edit_vbox), subject_hbox, FALSE, FALSE, 0);
+
        /* ruler */
        ruler_hbox = gtk_hbox_new(FALSE, 0);
        gtk_box_pack_start(GTK_BOX(edit_vbox), ruler_hbox, FALSE, FALSE, 0);
@@ -4216,7 +4260,7 @@ static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
        gtk_stext_set_editable(GTK_STEXT(text), TRUE);
 
        if (prefs_common.block_cursor) {
-               GTK_STEXT(text)->cursor_type = STEXT_CURSOR_BLOCK;
+               GTK_STEXT(text)->cursor_type = GTK_STEXT_CURSOR_BLOCK;
        }
        
        if (prefs_common.smart_wrapping) {      
@@ -4230,9 +4274,11 @@ static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
                           GTK_SIGNAL_FUNC(compose_changed_cb), compose);
        gtk_signal_connect(GTK_OBJECT(text), "grab_focus",
                           GTK_SIGNAL_FUNC(compose_grab_focus_cb), compose);
+       gtk_signal_connect(GTK_OBJECT(text), "activate",
+                          GTK_SIGNAL_FUNC(compose_ctl_enter_send_shortcut_cb), compose);
        gtk_signal_connect_after(GTK_OBJECT(text), "button_press_event",
                                 GTK_SIGNAL_FUNC(compose_button_press_cb),
-                                compose);
+                                edit_vbox);
 #if 0
        gtk_signal_connect_after(GTK_OBJECT(text), "key_press_event",
                                 GTK_SIGNAL_FUNC(compose_key_press_cb),
@@ -4253,7 +4299,7 @@ static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
                gtkpspell = gtkpspell_new_with_config(gtkpspellconfig,
                                                      prefs_common.pspell_path,
                                                      prefs_common.dictionary,
-                                                     PSPELL_FASTMODE,
+                                                     prefs_common.pspell_sugmode,
                                                      conv_get_current_charset_str());
                if (gtkpspell == NULL)
                        prefs_common.enable_pspell = FALSE;
@@ -4265,6 +4311,8 @@ static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
 
        /* pane between attach clist and text */
        paned = gtk_vpaned_new();
+       gtk_paned_set_gutter_size(GTK_PANED(paned), 12);
+       gtk_paned_set_handle_size(GTK_PANED(paned), 12);
        gtk_container_add(GTK_CONTAINER(vbox2), paned);
        gtk_paned_add1(GTK_PANED(paned), notebook);
        gtk_paned_add2(GTK_PANED(paned), edit_vbox);
@@ -4272,7 +4320,7 @@ static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
 
        style = gtk_widget_get_style(text);
 
-       /* workaround for the slow down of GtkText when using Pixmap theme */
+       /* workaround for the slow down of GtkSText when using Pixmap theme */
        if (style->engine) {
                GtkThemeEngine *engine;
 
@@ -4325,6 +4373,17 @@ static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
 
        tmpl_menu = gtk_item_factory_get_item(ifactory, "/Tool/Template");
 #if 0 /* NEW COMPOSE GUI */
+       gtk_widget_hide(bcc_hbox);
+       gtk_widget_hide(bcc_entry);
+       gtk_widget_hide(reply_hbox);
+       gtk_widget_hide(reply_entry);
+       gtk_widget_hide(followup_hbox);
+       gtk_widget_hide(followup_entry);
+       gtk_widget_hide(ruler_hbox);
+       gtk_table_set_row_spacing(GTK_TABLE(table), 4, 0);
+       gtk_table_set_row_spacing(GTK_TABLE(table), 5, 0);
+       gtk_table_set_row_spacing(GTK_TABLE(table), 6, 0);
+
        if (account->protocol == A_NNTP) {
                gtk_widget_hide(to_hbox);
                gtk_widget_hide(to_entry);
@@ -4336,8 +4395,7 @@ static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
                gtk_widget_hide(newsgroups_hbox);
                gtk_widget_hide(newsgroups_entry);
                gtk_table_set_row_spacing(GTK_TABLE(table), 2, 0);
-
-               menu_set_sensitive(ifactory, "/Message/Followup to", FALSE);
+               menu_set_sensitive(ifactory, "/View/Followup to", FALSE);
        }
 #endif
 
@@ -4374,8 +4432,6 @@ static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
 
        compose->vbox2         = vbox2;
 
-       compose->table_vbox       = table_vbox;
-
        compose->paned = paned;
 
        compose->edit_vbox     = edit_vbox;
@@ -4440,11 +4496,11 @@ static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
 
 #if 0 /* NEW COMPOSE GUI */
        if (account->protocol != A_NNTP) {
-               menuitem = gtk_item_factory_get_item(ifactory, "/Message/To");
+               menuitem = gtk_item_factory_get_item(ifactory, "/View/To");
                gtk_check_menu_item_set_active
                        (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
                gtk_widget_set_sensitive(menuitem, FALSE);
-               menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
+               menuitem = gtk_item_factory_get_item(ifactory, "/View/Cc");
                gtk_check_menu_item_set_active
                        (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
                gtk_widget_set_sensitive(menuitem, FALSE);
@@ -4455,7 +4511,7 @@ static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
 #if 0 /* NEW COMPOSE GUI */
                compose->use_cc = TRUE;
                gtk_entry_set_text(GTK_ENTRY(cc_entry), account->auto_cc);
-               menuitem = gtk_item_factory_get_item(ifactory, "/Message/Cc");
+               menuitem = gtk_item_factory_get_item(ifactory, "/View/Cc");
                gtk_check_menu_item_set_active
                        (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
 #endif
@@ -4463,8 +4519,7 @@ static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
        if (account->set_autobcc) {
                compose_entry_append(compose, account->auto_bcc, COMPOSE_BCC);
 #if 0 /* NEW COMPOSE GUI */
-               compose->use_bcc = TRUE;
-               menuitem = gtk_item_factory_get_item(ifactory, "/Message/Bcc");
+               menuitem = gtk_item_factory_get_item(ifactory, "/View/Bcc");
                gtk_check_menu_item_set_active
                        (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
                if (account->auto_bcc && mode != COMPOSE_REEDIT)
@@ -4477,7 +4532,7 @@ static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
 #if 0 /* NEW COMPOSE GUI */
                compose->use_replyto = TRUE;
                menuitem = gtk_item_factory_get_item(ifactory,
-                                                    "/Message/Reply to");
+                                                    "/View/Reply to");
                gtk_check_menu_item_set_active
                        (GTK_CHECK_MENU_ITEM(menuitem), TRUE);
                gtk_entry_set_text(GTK_ENTRY(reply_entry),
@@ -4491,9 +4546,11 @@ static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
                gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry), prefs_common.trans_hdr ? _("Newsgroups:") : "Newsgroups:");
        }
 
-       menuitem = gtk_item_factory_get_item(ifactory, "/Tool/Show ruler");
+#if 0 /* NEW COMPOSE GUI */
+       menuitem = gtk_item_factory_get_item(ifactory, "/View/Ruler");
        gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem),
                                       prefs_common.show_ruler);
+#endif                                
 
 #if USE_GPGME
        menuitem = gtk_item_factory_get_item(ifactory, "/Message/Sign");
@@ -4540,23 +4597,6 @@ static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
        return compose;
 }
 
-#include "pixmaps/stock_mail_send.xpm"
-#include "pixmaps/stock_mail_send_queue.xpm"
-#include "pixmaps/stock_mail.xpm"
-#include "pixmaps/stock_paste.xpm"
-#include "pixmaps/stock_mail_attach.xpm"
-#include "pixmaps/stock_mail_compose.xpm"
-#include "pixmaps/linewrap.xpm"
-#include "pixmaps/tb_address_book.xpm"
-
-#define CREATE_TOOLBAR_ICON(xpm_d) \
-{ \
-       icon = gdk_pixmap_create_from_xpm_d(container->window, &mask, \
-                                           &container->style->white, \
-                                           xpm_d); \
-       icon_wid = gtk_pixmap_new(icon, mask); \
-}
-
 static void compose_toolbar_create(Compose *compose, GtkWidget *container)
 {
        GtkWidget *toolbar;
@@ -4756,7 +4796,7 @@ static void compose_template_apply(Compose *compose, Template *tmpl)
        if (!tmpl || !tmpl->value) return;
 
        gtk_stext_freeze(GTK_STEXT(compose->text));
-        
+
        if (tmpl->subject && *tmpl->subject != '\0')
                gtk_entry_set_text(GTK_ENTRY(compose->subject_entry),
                                   tmpl->subject);
@@ -4913,7 +4953,7 @@ static void compose_attach_property(Compose *compose)
                GtkWidget *menuitem;
 
                cancelled = FALSE;
-                gtk_main();
+               gtk_main();
 
                if (cancelled == TRUE) {
                        gtk_widget_hide(attach_prop.window);
@@ -5681,6 +5721,7 @@ static void compose_send_cb(gpointer data, guint action, GtkWidget *widget)
        gint val;
 
        val = compose_send(compose);
+
        if (val == 0) gtk_widget_destroy(compose->window);
 }
 
@@ -5699,24 +5740,34 @@ static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
        Compose *compose = (Compose *)data;
        FolderItem *draft;
        gchar *tmp;
+       gint msgnum;
+       static gboolean lock = FALSE;
+
+       if (lock) return;
 
        draft = folder_get_default_draft();
+       g_return_if_fail(draft != NULL);
+
+       lock = TRUE;
 
-        tmp = g_strdup_printf("%s%cdraft.%d", g_get_tmp_dir(),
+       tmp = g_strdup_printf("%s%cdraft.%d", g_get_tmp_dir(),
                              G_DIR_SEPARATOR, (gint)compose);
 
        if (compose_write_to_file(compose, tmp, TRUE) < 0) {
                g_free(tmp);
+               lock = FALSE;
                return;
        }
 
        folder_item_scan(draft);
-       if (folder_item_add_msg(draft, tmp, TRUE) < 0) {
+       if ((msgnum = folder_item_add_msg(draft, tmp, TRUE)) <= 0) {
                unlink(tmp);
                g_free(tmp);
+               lock = FALSE;
                return;
        }
        g_free(tmp);
+       draft->mtime = 0;       /* force updating */
 
        if (compose->mode == COMPOSE_REEDIT) {
                compose_remove_reedit_target(compose);
@@ -5729,7 +5780,33 @@ static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
        folder_item_scan(draft);
        folderview_update_item(draft, TRUE);
 
-       gtk_widget_destroy(compose->window);
+       lock = FALSE;
+
+       /* 0: quit editing  1: keep editing */
+       if (action == 0)
+               gtk_widget_destroy(compose->window);
+       else {
+               struct stat s;
+               gchar *path;
+
+               path = folder_item_fetch_msg(draft, msgnum);
+               g_return_if_fail(path != NULL);
+               if (stat(path, &s) < 0) {
+                       FILE_OP_ERROR(path, "stat");
+                       g_free(path);
+                       lock = FALSE;
+                       return;
+               }
+               g_free(path);
+
+               procmsg_msginfo_free(compose->targetinfo);
+               compose->targetinfo = g_new0(MsgInfo, 1);
+               compose->targetinfo->msgnum = msgnum;
+               compose->targetinfo->size = s.st_size;
+               compose->targetinfo->mtime = s.st_mtime;
+               compose->targetinfo->folder = draft;
+               compose->mode = COMPOSE_REEDIT;
+       }
 }
 
 static void compose_attach_cb(gpointer data, guint action, GtkWidget *widget)
@@ -6232,7 +6309,16 @@ void compose_headerentry_key_press_event_cb(GtkWidget *entry,
                        g_slist_remove(headerentry->compose->header_list,
                                       headerentry);
                g_free(headerentry);
+       } else  if (event->keyval == GDK_Tab) {
+               if (headerentry->compose->header_last == headerentry) {
+                       /* Override default next focus, and give it to subject_entry
+                        * instead of notebook tabs
+                        */
+                       gtk_signal_emit_stop_by_name(GTK_OBJECT(entry), "key-press-event"); 
+                       gtk_widget_grab_focus(headerentry->compose->subject_entry);
+               }
        }
+
 }
 
 void compose_headerentry_changed_cb(GtkWidget *entry,
@@ -6247,5 +6333,41 @@ void compose_headerentry_changed_cb(GtkWidget *entry,
                        (GTK_OBJECT(entry),
                         GTK_SIGNAL_FUNC(compose_headerentry_changed_cb),
                         headerentry);
+               /* Automatically scroll down */
+               compose_show_first_last_header(headerentry->compose, FALSE);
+               
        }
 }
+
+static void compose_show_first_last_header(Compose *compose, gboolean show_first)
+{
+       GtkAdjustment *vadj;
+
+       g_return_if_fail(compose);
+       g_return_if_fail(GTK_IS_WIDGET(compose->header_table));
+       g_return_if_fail(GTK_IS_VIEWPORT(compose->header_table->parent));
+
+       vadj = gtk_viewport_get_vadjustment(GTK_VIEWPORT(compose->header_table->parent));
+       gtk_adjustment_set_value(vadj, (show_first ? vadj->lower : vadj->upper));
+}
+
+static void compose_ctl_enter_send_shortcut_cb(GtkWidget *w, Compose *compose)
+{
+       GtkItemFactory *ifactory;
+       GtkAccelEntry  *accel;
+       GtkWidget      *send_button;
+       GSList *list;
+       GdkEvent *e= gtk_get_current_event();
+       
+       if (e->type != GDK_KEY_PRESS || 
+           !( ((GdkEventKey *)e)->state & GDK_CONTROL_MASK) )
+               return;
+
+       ifactory = gtk_item_factory_from_widget(compose->menubar);
+       send_button = gtk_item_factory_get_widget(ifactory, "/Message/Send");
+       list = gtk_accel_group_entries_from_object(GTK_OBJECT(send_button));
+       accel = (GtkAccelEntry *) list->data;
+       if (accel->accelerator_key == GDK_Return && 
+           accel->accelerator_mods == GDK_CONTROL_MASK)
+               compose_send_cb(compose, 0, NULL);
+}