2008-04-30 [colin] 3.4.0cvs18
[claws.git] / src / compose.c
index 0a43af94a442e5276d9879d03270056f0f3cfd43..a2d475211749301e9ede5a7b05d7b96e19d41cc3 100644 (file)
@@ -152,7 +152,6 @@ typedef enum
        COMPOSE_CALL_ADVANCED_ACTION_DELETE_FORWARD_WORD,
        COMPOSE_CALL_ADVANCED_ACTION_DELETE_BACKWARD_WORD,
        COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE,
-       COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE_N,
        COMPOSE_CALL_ADVANCED_ACTION_DELETE_TO_LINE_END
 } ComposeCallAdvancedAction;
 
@@ -235,7 +234,8 @@ static void compose_template_apply          (Compose        *compose,
 static void compose_destroy                    (Compose        *compose);
 
 static void compose_entries_set                        (Compose        *compose,
-                                                const gchar    *mailto);
+                                                const gchar    *mailto,
+                                                ComposeEntryType to_type);
 static gint compose_parse_header               (Compose        *compose,
                                                 MsgInfo        *msginfo);
 static gchar *compose_parse_references         (const gchar    *ref,
@@ -546,6 +546,9 @@ static MsgInfo *compose_msginfo_new_from_compose(Compose *compose);
 static void compose_set_dictionaries_from_folder_prefs(Compose *compose,
                                                FolderItem *folder_item);
 #endif
+static void compose_attach_update_label(Compose *compose);
+
+static void compose_attach_from_list(Compose *compose, GList *file_list, gboolean free_data);
 
 static GtkItemFactoryEntry compose_popup_entries[] =
 {
@@ -653,11 +656,6 @@ static GtkItemFactoryEntry compose_entries[] =
                                        compose_advanced_action_cb,
                                        COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE,
                                        NULL},
-       {N_("/_Edit/A_dvanced/Delete entire line"),
-                                       NULL,
-                                       compose_advanced_action_cb,
-                                       COMPOSE_CALL_ADVANCED_ACTION_DELETE_LINE_N,
-                                       NULL},
        {N_("/_Edit/A_dvanced/Delete to end of line"),
                                        "<control>K",
                                        compose_advanced_action_cb,
@@ -722,81 +720,87 @@ static GtkItemFactoryEntry compose_entries[] =
                        NULL, compose_set_encoding_cb, C_AUTO, "<RadioItem>"},
        {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
 
-       {N_("/_Options/Character _encoding/7bit ascii (US-ASC_II)"),
+       {N_("/_Options/Character _encoding/7bit ASCII (US-ASC_II)"),
         ENC_ACTION(C_US_ASCII)},
        {N_("/_Options/Character _encoding/Unicode (_UTF-8)"),
         ENC_ACTION(C_UTF_8)},
        {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
 
-       {N_("/_Options/Character _encoding/Western European (ISO-8859-_1)"),
+       {N_("/_Options/Character _encoding/Western European"), NULL, NULL, 0, "<Branch>"},
+       {N_("/_Options/Character _encoding/Western European/ISO-8859-_1"),
         ENC_ACTION(C_ISO_8859_1)},
-       {N_("/_Options/Character _encoding/Western European (ISO-8859-15)"),
+       {N_("/_Options/Character _encoding/Western European/ISO-8859-15"),
         ENC_ACTION(C_ISO_8859_15)},
-       {N_("/_Options/Character _encoding/Western European (Windows-1252)"),
+       {N_("/_Options/Character _encoding/Western European/Windows-1252"),
         ENC_ACTION(C_WINDOWS_1252)},
-       {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
 
        {N_("/_Options/Character _encoding/Central European (ISO-8859-_2)"),
         ENC_ACTION(C_ISO_8859_2)},
-       {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
 
-       {N_("/_Options/Character _encoding/_Baltic (ISO-8859-13)"),
+       {N_("/_Options/Character _encoding/Baltic"), NULL, NULL, 0, "<Branch>"},
+       {N_("/_Options/Character _encoding/Baltic/ISO-8859-13"),
         ENC_ACTION(C_ISO_8859_13)},
-       {N_("/_Options/Character _encoding/Baltic (ISO-8859-_4)"),
+       {N_("/_Options/Character _encoding/Baltic/ISO-8859-_4"),
         ENC_ACTION(C_ISO_8859_4)},
-       {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
 
        {N_("/_Options/Character _encoding/Greek (ISO-8859-_7)"),
         ENC_ACTION(C_ISO_8859_7)},
-       {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
 
-       {N_("/_Options/Character _encoding/Hebrew (ISO-8859-_8)"),
+       {N_("/_Options/Character _encoding/Hebrew"), NULL, NULL, 0, "<Branch>"},
+       {N_("/_Options/Character _encoding/Hebrew/ISO-8859-_8"),
         ENC_ACTION(C_ISO_8859_8)},
-       {N_("/_Options/Character _encoding/Hebrew (Windows-1255)"),
+       {N_("/_Options/Character _encoding/Hebrew/Windows-1255"),
         ENC_ACTION(C_WINDOWS_1255)},
-       {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
 
-       {N_("/_Options/Character _encoding/Arabic (ISO-8859-_6)"),
+       {N_("/_Options/Character _encoding/Arabic"), NULL, NULL, 0, "<Branch>"},
+       {N_("/_Options/Character _encoding/Arabic/ISO-8859-_6"),
         ENC_ACTION(C_ISO_8859_6)},
-       {N_("/_Options/Character _encoding/Arabic (Windows-1256)"),
+       {N_("/_Options/Character _encoding/Arabic/Windows-1256"),
         ENC_ACTION(C_CP1256)},
-       {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
 
        {N_("/_Options/Character _encoding/Turkish (ISO-8859-_9)"),
         ENC_ACTION(C_ISO_8859_9)},
-       {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
 
-       {N_("/_Options/Character _encoding/Cyrillic (ISO-8859-_5)"),
+       {N_("/_Options/Character _encoding/Cyrillic"), NULL, NULL, 0, "<Branch>"},
+       {N_("/_Options/Character _encoding/Cyrillic/ISO-8859-_5"),
         ENC_ACTION(C_ISO_8859_5)},
-       {N_("/_Options/Character _encoding/Cyrillic (KOI8-_R)"),
+       {N_("/_Options/Character _encoding/Cyrillic/KOI8-_R"),
         ENC_ACTION(C_KOI8_R)},
-       {N_("/_Options/Character _encoding/Cyrillic (KOI8-U)"),
+       {N_("/_Options/Character _encoding/Cyrillic/KOI8-U"),
         ENC_ACTION(C_KOI8_U)},
-       {N_("/_Options/Character _encoding/Cyrillic (Windows-1251)"),
+       {N_("/_Options/Character _encoding/Cyrillic/Windows-1251"),
         ENC_ACTION(C_WINDOWS_1251)},
-       {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
 
-       {N_("/_Options/Character _encoding/Japanese (ISO-2022-_JP)"),
+       {N_("/_Options/Character _encoding/Japanese"), NULL, NULL, 0, "<Branch>"},
+       {N_("/_Options/Character _encoding/Japanese/ISO-2022-_JP"),
         ENC_ACTION(C_ISO_2022_JP)},
-       {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
-
-       {N_("/_Options/Character _encoding/Simplified Chinese (_GB2312)"),
+       {N_("/_Options/Character _encoding/Japanese/ISO-2022-JP-2"),
+        ENC_ACTION(C_ISO_2022_JP_2)},
+       {N_("/_Options/Character _encoding/Japanese/_EUC-JP"),
+        ENC_ACTION(C_EUC_JP)},
+       {N_("/_Options/Character _encoding/Japanese/_Shift__JIS"),
+        ENC_ACTION(C_SHIFT_JIS)},
+
+       {N_("/_Options/Character _encoding/Chinese"), NULL, NULL, 0, "<Branch>"},
+       {N_("/_Options/Character _encoding/Chinese/Simplified (_GB2312)"),
         ENC_ACTION(C_GB2312)},
-       {N_("/_Options/Character _encoding/Simplified Chinese (GBK)"),
+       {N_("/_Options/Character _encoding/Chinese/Simplified (GBK)"),
         ENC_ACTION(C_GBK)},
-       {N_("/_Options/Character _encoding/Traditional Chinese (_Big5)"),
+       {N_("/_Options/Character _encoding/Chinese/Traditional (_Big5)"),
         ENC_ACTION(C_BIG5)},
-       {N_("/_Options/Character _encoding/Traditional Chinese (EUC-_TW)"),
+       {N_("/_Options/Character _encoding/Chinese/Traditional (EUC-_TW)"),
         ENC_ACTION(C_EUC_TW)},
-       {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
 
-       {N_("/_Options/Character _encoding/Korean (EUC-_KR)"),
+       {N_("/_Options/Character _encoding/Korean"), NULL, NULL, 0, "<Branch>"},
+       {N_("/_Options/Character _encoding/Korean/EUC-_KR"),
         ENC_ACTION(C_EUC_KR)},
-       {N_("/_Options/Character _encoding/---"), NULL, NULL, 0, "<Separator>"},
+       {N_("/_Options/Character _encoding/Korean/ISO-2022-KR"),
+        ENC_ACTION(C_ISO_2022_KR)},
 
-       {N_("/_Options/Character _encoding/Thai (TIS-620)"),
+       {N_("/_Options/Character _encoding/Thai"), NULL, NULL, 0, "<Branch>"},
+       {N_("/_Options/Character _encoding/Thai/TIS-620"),
         ENC_ACTION(C_TIS_620)},
-       {N_("/_Options/Character _encoding/Thai (Windows-874)"),
+       {N_("/_Options/Character _encoding/Thai/Windows-874"),
         ENC_ACTION(C_WINDOWS_874)},
 
        {N_("/_Tools"),                 NULL, NULL, 0, "<Branch>"},
@@ -975,6 +979,15 @@ Compose *compose_new_with_list( PrefsAccount *account, GList *listAddress )
        return compose_generic_new( account, NULL, NULL, NULL, listAddress );
 }
 
+#define SCROLL_TO_CURSOR(compose) {                            \
+       GtkTextMark *cmark = gtk_text_buffer_get_insert(        \
+               gtk_text_view_get_buffer(                       \
+                       GTK_TEXT_VIEW(compose->text)));         \
+       gtk_text_view_scroll_mark_onscreen(                     \
+               GTK_TEXT_VIEW(compose->text),                   \
+               cmark);                                         \
+}
+
 Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderItem *item,
                             GPtrArray *attach_files, GList *listAddress )
 {
@@ -985,15 +998,71 @@ Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderI
        GtkItemFactory *ifactory;
        const gchar *subject_format = NULL;
        const gchar *body_format = NULL;
+       gchar *mailto_from = NULL;
+       PrefsAccount *mailto_account = NULL;
+       MsgInfo* dummyinfo = NULL;
 
-       if (item && item->prefs && item->prefs->enable_default_account)
+       /* check if mailto defines a from */
+       if (mailto && *mailto != '\0') {
+               scan_mailto_url(mailto, &mailto_from, NULL, NULL, NULL, NULL, NULL, NULL);
+               /* mailto defines a from, check if we can get account prefs from it,
+                  if not, the account prefs will be guessed using other ways, but we'll keep
+                  the from anyway */
+               if (mailto_from)
+                       mailto_account = account_find_from_address(mailto_from, TRUE);
+               if (mailto_account)
+                       account = mailto_account;
+       }
+
+       /* if no account prefs set from mailto, set if from folder prefs (if any) */
+       if (!mailto_account && item && item->prefs && item->prefs->enable_default_account)
                account = account_find_from_id(item->prefs->default_account);
 
+       /* if no account prefs set, fallback to the current one */
        if (!account) account = cur_account;
        g_return_val_if_fail(account != NULL, NULL);
 
        compose = compose_create(account, item, COMPOSE_NEW, FALSE);
 
+       /* override from name if mailto asked for it */
+       if (mailto_from) {
+               gtk_entry_set_text(GTK_ENTRY(compose->from_name), mailto_from);
+               g_free(mailto_from);
+       } else
+               /* override from name according to folder properties */
+               if (item && item->prefs &&
+                       item->prefs->compose_with_format &&
+                       item->prefs->compose_override_from_format &&
+                       *item->prefs->compose_override_from_format != '\0') {
+
+                       gchar *tmp = NULL;
+                       gchar *buf = NULL;
+
+                       dummyinfo = compose_msginfo_new_from_compose(compose);
+
+                       /* decode \-escape sequences in the internal representation of the quote format */
+                       tmp = malloc(strlen(item->prefs->compose_override_from_format)+1);
+                       pref_get_unescaped_pref(tmp, item->prefs->compose_override_from_format);
+
+#ifdef USE_ASPELL
+                       quote_fmt_init(dummyinfo, NULL, NULL, FALSE, compose->account, FALSE,
+                                       compose->gtkaspell);
+#else
+                       quote_fmt_init(dummyinfo, NULL, NULL, FALSE, compose->account, FALSE);
+#endif
+                       quote_fmt_scan_string(tmp);
+                       quote_fmt_parse();
+
+                       buf = quote_fmt_get_buffer();
+                       if (buf == NULL)
+                               alertpanel_error(_("New message From format error."));
+                       else
+                               gtk_entry_set_text(GTK_ENTRY(compose->from_name), buf);
+                       quote_fmt_reset_vartable();
+
+                       g_free(tmp);
+               }
+
        ifactory = gtk_item_factory_from_widget(compose->menubar);
 
        compose->replyinfo = NULL;
@@ -1015,7 +1084,7 @@ Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderI
 
        if (account->protocol != A_NNTP) {
                if (mailto && *mailto != '\0') {
-                       compose_entries_set(compose, mailto);
+                       compose_entries_set(compose, mailto, COMPOSE_TO);
 
                } else if (item && item->prefs->enable_default_to) {
                        compose_entry_append(compose, item->prefs->default_to, COMPOSE_TO);
@@ -1025,8 +1094,11 @@ Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderI
                        menu_set_active(ifactory, "/Options/Request Return Receipt", TRUE);
                }
        } else {
-               if (mailto) {
-                       compose_entry_append(compose, mailto, COMPOSE_NEWSGROUPS);
+               if (mailto && *mailto != '\0') {
+                       if (!strchr(mailto, '@'))
+                               compose_entries_set(compose, mailto, COMPOSE_NEWSGROUPS);
+                       else
+                               compose_entries_set(compose, mailto, COMPOSE_TO);
                } else if (item && FOLDER_CLASS(item->folder) == news_get_class()) {
                        compose_entry_append(compose, item->path, COMPOSE_NEWSGROUPS);
                }
@@ -1050,7 +1122,6 @@ Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderI
        }
 
        if (subject_format || body_format) {
-               MsgInfo* dummyinfo = NULL;
 
                if ( subject_format
                         && *subject_format != '\0' )
@@ -1059,7 +1130,8 @@ Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderI
                        gchar *tmp = NULL;
                        gchar *buf = NULL;
 
-                       dummyinfo = compose_msginfo_new_from_compose(compose);
+                       if (!dummyinfo)
+                               dummyinfo = compose_msginfo_new_from_compose(compose);
 
                        /* decode \-escape sequences in the internal representation of the quote format */
                        tmp = malloc(strlen(subject_format)+1);
@@ -1067,10 +1139,10 @@ Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderI
 
                        subject = gtk_editable_get_chars(GTK_EDITABLE(compose->subject_entry), 0, -1);
 #ifdef USE_ASPELL
-                       quote_fmt_init(dummyinfo, NULL, subject, FALSE, compose->account,
+                       quote_fmt_init(dummyinfo, NULL, subject, FALSE, compose->account, FALSE,
                                        compose->gtkaspell);
 #else
-                       quote_fmt_init(dummyinfo, NULL, subject, FALSE, compose->account);
+                       quote_fmt_init(dummyinfo, NULL, subject, FALSE, compose->account, FALSE);
 #endif
                        quote_fmt_scan_string(tmp);
                        quote_fmt_parse();
@@ -1080,6 +1152,7 @@ Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderI
                                alertpanel_error(_("New message subject format error."));
                        else
                                gtk_entry_set_text(GTK_ENTRY(compose->subject_entry), buf);
+                       compose_attach_from_list(compose, quote_fmt_get_attachments_list(), FALSE);
                        quote_fmt_reset_vartable();
 
                        g_free(subject);
@@ -1094,7 +1167,7 @@ Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderI
                        GtkTextIter start, end;
                        gchar *tmp = NULL;
 
-                       if ( dummyinfo == NULL )
+                       if (!dummyinfo)
                                dummyinfo = compose_msginfo_new_from_compose(compose);
 
                        text = GTK_TEXT_VIEW(compose->text);
@@ -1107,13 +1180,14 @@ Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderI
                                          body_format,
                                          NULL, tmp, FALSE, TRUE,
                                                  _("New message body format error at line %d."));
+                       compose_attach_from_list(compose, quote_fmt_get_attachments_list(), FALSE);
                        quote_fmt_reset_vartable();
 
                        g_free(tmp);
                }
 
-               procmsg_msginfo_free( dummyinfo );
        }
+       procmsg_msginfo_free( dummyinfo );
 
        if (attach_files) {
                gint i;
@@ -1145,6 +1219,8 @@ Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderI
                compose_exec_ext_editor(compose);
 
        compose->draft_timeout_tag = -1;
+       SCROLL_TO_CURSOR(compose);
+
        compose->modified = FALSE;
        compose_set_title(compose);
         return compose;
@@ -1173,6 +1249,10 @@ static void compose_force_encryption(Compose *compose, PrefsAccount *account,
        if (privacy != NULL) {
                if (compose->privacy_system == NULL)
                        compose->privacy_system = g_strdup(privacy);
+               else if (*(compose->privacy_system) == '\0') {
+                       g_free(compose->privacy_system);
+                       compose->privacy_system = g_strdup(privacy);
+               }
                compose_update_privacy_system_menu_item(compose, FALSE);
                compose_use_encryption(compose, TRUE);
        }
@@ -1293,6 +1373,10 @@ static Compose *compose_reply_mode(ComposeMode mode, GSList *msginfo_list, gchar
                g_warning("compose_reply_mode(): invalid Compose Mode: %d\n", mode);
        }
        
+       if (compose == NULL) {
+               alertpanel_error(_("Unable to reply. The original email probably doesn't exist."));
+               return NULL;
+       }
        ifactory = gtk_item_factory_from_widget(compose->menubar);
 
        compose->rmode = mode;
@@ -1443,7 +1527,43 @@ static Compose *compose_generic_reply(MsgInfo *msginfo,
                g_free(folderidentifier);
        }
 
-       if (compose_parse_header(compose, msginfo) < 0) return NULL;
+       if (compose_parse_header(compose, msginfo) < 0) {
+               compose->updating = FALSE;
+               compose_destroy(compose);
+               return NULL;
+       }
+
+       /* override from name according to folder properties */
+       if (msginfo->folder && msginfo->folder->prefs &&
+               msginfo->folder->prefs->reply_with_format &&
+               msginfo->folder->prefs->reply_override_from_format &&
+               *msginfo->folder->prefs->reply_override_from_format != '\0') {
+
+               gchar *tmp = NULL;
+               gchar *buf = NULL;
+
+               /* decode \-escape sequences in the internal representation of the quote format */
+               tmp = malloc(strlen(msginfo->folder->prefs->reply_override_from_format)+1);
+               pref_get_unescaped_pref(tmp, msginfo->folder->prefs->reply_override_from_format);
+
+#ifdef USE_ASPELL
+               quote_fmt_init(compose->replyinfo, NULL, NULL, FALSE, compose->account, FALSE,
+                               compose->gtkaspell);
+#else
+               quote_fmt_init(compose->replyinfo, NULL, NULL, FALSE, compose->account, FALSE);
+#endif
+               quote_fmt_scan_string(tmp);
+               quote_fmt_parse();
+
+               buf = quote_fmt_get_buffer();
+               if (buf == NULL)
+                       alertpanel_error(_("Message reply From format error."));
+               else
+                       gtk_entry_set_text(GTK_ENTRY(compose->from_name), buf);
+               quote_fmt_reset_vartable();
+
+               g_free(tmp);
+       }
 
        textview = (GTK_TEXT_VIEW(compose->text));
        textbuf = gtk_text_view_get_buffer(textview);
@@ -1482,6 +1602,7 @@ static Compose *compose_generic_reply(MsgInfo *msginfo,
                compose_quote_fmt(compose, compose->replyinfo,
                                  body_fmt, qmark, body, FALSE, TRUE,
                                          _("Message reply format error at line %d."));
+               compose_attach_from_list(compose, quote_fmt_get_attachments_list(), FALSE);
                quote_fmt_reset_vartable();
        }
 
@@ -1510,7 +1631,8 @@ static Compose *compose_generic_reply(MsgInfo *msginfo,
 
        compose->updating = FALSE;
        compose->draft_timeout_tag = -1; /* desinhibit auto-drafting after loading */
-
+       SCROLL_TO_CURSOR(compose);
+       
        if (compose->deferred_destroy) {
                compose_destroy(compose);
                return NULL;
@@ -1567,6 +1689,45 @@ Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
                g_free(buf2);
        }
 
+       /* override from name according to folder properties */
+       if (msginfo->folder && msginfo->folder->prefs &&
+               msginfo->folder->prefs->forward_with_format &&
+               msginfo->folder->prefs->forward_override_from_format &&
+               *msginfo->folder->prefs->forward_override_from_format != '\0') {
+
+               gchar *tmp = NULL;
+               gchar *buf = NULL;
+               MsgInfo *full_msginfo = NULL;
+
+               if (!as_attach)
+                       full_msginfo = procmsg_msginfo_get_full_info(msginfo);
+               if (!full_msginfo)
+                       full_msginfo = procmsg_msginfo_copy(msginfo);
+
+               /* decode \-escape sequences in the internal representation of the quote format */
+               tmp = malloc(strlen(msginfo->folder->prefs->forward_override_from_format)+1);
+               pref_get_unescaped_pref(tmp, msginfo->folder->prefs->forward_override_from_format);
+
+#ifdef USE_ASPELL
+               quote_fmt_init(full_msginfo, NULL, NULL, FALSE, compose->account, FALSE,
+                               compose->gtkaspell);
+#else
+               quote_fmt_init(full_msginfo, NULL, NULL, FALSE, compose->account, FALSE);
+#endif
+               quote_fmt_scan_string(tmp);
+               quote_fmt_parse();
+
+               buf = quote_fmt_get_buffer();
+               if (buf == NULL)
+                       alertpanel_error(_("Message forward From format error."));
+               else
+                       gtk_entry_set_text(GTK_ENTRY(compose->from_name), buf);
+               quote_fmt_reset_vartable();
+
+               g_free(tmp);
+               procmsg_msginfo_free(full_msginfo);
+       }
+
        textview = GTK_TEXT_VIEW(compose->text);
        textbuf = gtk_text_view_get_buffer(textview);
        compose_create_tags(textview, compose);
@@ -1616,6 +1777,7 @@ Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
                compose_quote_fmt(compose, full_msginfo,
                                  body_fmt, qmark, body, FALSE, TRUE,
                                          _("Message forward format error at line %d."));
+               compose_attach_from_list(compose, quote_fmt_get_attachments_list(), FALSE);
                quote_fmt_reset_vartable();
                compose_attach_parts(compose, msginfo);
 
@@ -1656,6 +1818,7 @@ Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
 
        compose->updating = FALSE;
        compose->draft_timeout_tag = -1; /* desinhibit auto-drafting after loading */
+       SCROLL_TO_CURSOR(compose);
 
        if (compose->deferred_destroy) {
                compose_destroy(compose);
@@ -1703,6 +1866,42 @@ static Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_
 
        compose->updating = TRUE;
 
+       /* override from name according to folder properties */
+       if (msginfo_list->data) {
+               MsgInfo *msginfo = msginfo_list->data;
+
+               if (msginfo->folder && msginfo->folder->prefs &&
+                       msginfo->folder->prefs->forward_with_format &&
+                       msginfo->folder->prefs->forward_override_from_format &&
+                       *msginfo->folder->prefs->forward_override_from_format != '\0') {
+
+                       gchar *tmp = NULL;
+                       gchar *buf = NULL;
+
+                       /* decode \-escape sequences in the internal representation of the quote format */
+                       tmp = malloc(strlen(msginfo->folder->prefs->forward_override_from_format)+1);
+                       pref_get_unescaped_pref(tmp, msginfo->folder->prefs->forward_override_from_format);
+
+#ifdef USE_ASPELL
+                       quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account, FALSE,
+                                       compose->gtkaspell);
+#else
+                       quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account, FALSE);
+#endif
+                       quote_fmt_scan_string(tmp);
+                       quote_fmt_parse();
+
+                       buf = quote_fmt_get_buffer();
+                       if (buf == NULL)
+                               alertpanel_error(_("Message forward From format error."));
+                       else
+                               gtk_entry_set_text(GTK_ENTRY(compose->from_name), buf);
+                       quote_fmt_reset_vartable();
+
+                       g_free(tmp);
+               }
+       }
+
        textview = GTK_TEXT_VIEW(compose->text);
        textbuf = gtk_text_view_get_buffer(textview);
        compose_create_tags(textview, compose);
@@ -1758,6 +1957,7 @@ static Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_
 
        compose->updating = FALSE;
        compose->draft_timeout_tag = -1; /* desinhibit auto-drafting after loading */
+       SCROLL_TO_CURSOR(compose);
 
        if (compose->deferred_destroy) {
                compose_destroy(compose);
@@ -1895,7 +2095,7 @@ Compose *compose_reedit(MsgInfo *msginfo, gboolean batch)
                }
                if (!account && !procheader_get_header_from_msginfo(msginfo, queueheader_buf, 
                                                                sizeof(queueheader_buf), "S:")) {
-                       account = account_find_from_address(queueheader_buf);
+                       account = account_find_from_address(queueheader_buf, FALSE);
                }
                if (!procheader_get_header_from_msginfo(msginfo, queueheader_buf, 
                                             sizeof(queueheader_buf), "X-Claws-Sign:")) {
@@ -1962,7 +2162,7 @@ Compose *compose_reedit(MsgInfo *msginfo, gboolean batch)
                        gchar from[BUFFSIZE];
                if (!procheader_get_header_from_msginfo(msginfo, from, sizeof(from), "FROM:")) {
                        extract_address(from);
-                       account = account_find_from_address(from);
+                       account = account_find_from_address(from, FALSE);
                 }
        }
         if (!account) {
@@ -2073,6 +2273,7 @@ Compose *compose_reedit(MsgInfo *msginfo, gboolean batch)
 
        compose->updating = FALSE;
        compose->draft_timeout_tag = -1; /* desinhibit auto-drafting after loading */
+       SCROLL_TO_CURSOR(compose);
 
        if (compose->deferred_destroy) {
                compose_destroy(compose);
@@ -2182,6 +2383,7 @@ Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo,
        compose_set_title(compose);
        compose->updating = FALSE;
        compose->draft_timeout_tag = -1; /* desinhibit auto-drafting after loading */
+       SCROLL_TO_CURSOR(compose);
 
        if (compose->deferred_destroy) {
                compose_destroy(compose);
@@ -2342,22 +2544,26 @@ void compose_toolbar_cb(gint action, gpointer data)
        }
 }
 
-static void compose_entries_set(Compose *compose, const gchar *mailto)
+static void compose_entries_set(Compose *compose, const gchar *mailto, ComposeEntryType to_type)
 {
        gchar *to = NULL;
        gchar *cc = NULL;
+       gchar *bcc = NULL;
        gchar *subject = NULL;
        gchar *body = NULL;
        gchar *temp = NULL;
        gsize  len = 0;
-       gchar *attach = NULL;
-       
-       scan_mailto_url(mailto, &to, &cc, NULL, &subject, &body, &attach);
+       gchar **attach = NULL;
+
+       /* get mailto parts but skip from */
+       scan_mailto_url(mailto, NULL, &to, &cc, &bcc, &subject, &body, &attach);
 
        if (to)
-               compose_entry_append(compose, to, COMPOSE_TO);
+               compose_entry_append(compose, to, to_type);
        if (cc)
                compose_entry_append(compose, cc, COMPOSE_CC);
+       if (bcc)
+               compose_entry_append(compose, bcc, COMPOSE_BCC);
        if (subject) {
                if (!g_utf8_validate (subject, -1, NULL)) {
                        temp = g_locale_to_utf8 (subject, -1, NULL, &len, NULL);
@@ -2394,21 +2600,38 @@ static void compose_entries_set(Compose *compose, const gchar *mailto)
        }
 
        if (attach) {
-               gchar *utf8_filename = conv_filename_to_utf8(attach);
-               if (utf8_filename) {
-                       if (compose_attach_append(compose, attach, utf8_filename, NULL)) {
-                               alertpanel_notice(_("The file '%s' has been attached."), attach);
-                       } 
-                       g_free(utf8_filename);
-               } else {
-                       alertpanel_error(_("Couldn't attach a file (charset conversion failed)."));
+               gint i = 0, att = 0;
+               gchar *warn_files = NULL;
+               while (attach[i] != NULL) {
+                       gchar *utf8_filename = conv_filename_to_utf8(attach[i]);
+                       if (utf8_filename) {
+                               if (compose_attach_append(compose, attach[i], utf8_filename, NULL)) {
+                                       gchar *tmp = g_strdup_printf("%s%s\n",
+                                                       warn_files?warn_files:"",
+                                                       utf8_filename);
+                                       g_free(warn_files);
+                                       warn_files = tmp;
+                                       att++;
+                               }
+                               g_free(utf8_filename);
+                       } else {
+                               alertpanel_error(_("Couldn't attach a file (charset conversion failed)."));
+                       }
+                       i++;
+               }
+               if (warn_files) {
+                       alertpanel_notice(ngettext(
+                       "The following file has been attached: \n%s",
+                       "The following files have been attached: \n%s", att), warn_files);
+                       g_free(warn_files);
                }
        }
        g_free(to);
        g_free(cc);
+       g_free(bcc);
        g_free(subject);
        g_free(body);
-       g_free(attach);
+       g_strfreev(attach);
 }
 
 static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
@@ -2493,7 +2716,7 @@ static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
                extract_address(hentry[H_LIST_POST].body);
                if (hentry[H_LIST_POST].body[0] != '\0') {
                        scan_mailto_url(hentry[H_LIST_POST].body,
-                                       &to, NULL, NULL, NULL, NULL, NULL);
+                                       NULL, &to, NULL, NULL, NULL, NULL, NULL);
                        if (to) {
                                g_free(compose->ml_post);
                                compose->ml_post = to;
@@ -2627,10 +2850,10 @@ static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
 
        if (qmark != NULL) {
 #ifdef USE_ASPELL
-               quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account,
+               quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account, FALSE,
                                compose->gtkaspell);
 #else
-               quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account);
+               quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account, FALSE);
 #endif
                quote_fmt_scan_string(qmark);
                quote_fmt_parse();
@@ -2649,10 +2872,10 @@ static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
                                trimmed_body++;
 
 #ifdef USE_ASPELL
-               quote_fmt_init(msginfo, quote_str, trimmed_body, FALSE, compose->account,
+               quote_fmt_init(msginfo, quote_str, trimmed_body, FALSE, compose->account, FALSE,
                                compose->gtkaspell);
 #else
-               quote_fmt_init(msginfo, quote_str, trimmed_body, FALSE, compose->account);
+               quote_fmt_init(msginfo, quote_str, trimmed_body, FALSE, compose->account, FALSE);
 #endif
                if (need_unescape) {
                        gchar *tmp = NULL;
@@ -2671,9 +2894,7 @@ static gchar *compose_quote_fmt(Compose *compose, MsgInfo *msginfo,
                buf = quote_fmt_get_buffer();
                if (buf == NULL) {
                        gint line = quote_fmt_get_line();
-                       gchar *msg = g_strdup_printf(err_msg, line);
-                       alertpanel_error(msg);
-                       g_free(msg);
+                       alertpanel_error(err_msg, line);
                        goto error;
                }
        } else
@@ -2840,7 +3061,7 @@ static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
                        Xstrdup_a(tmp1, msginfo->from, return);
                        extract_address(tmp1);
                        if (to_all || to_sender ||
-                           !account_find_from_address(tmp1))
+                           !account_find_from_address(tmp1, FALSE))
                                compose_entry_append(compose,
                                 (compose->replyto && !to_sender)
                                          ? compose->replyto :
@@ -2850,9 +3071,15 @@ static void compose_reply_set_entry(Compose *compose, MsgInfo *msginfo,
                                if (!folder_has_parent_of_type(msginfo->folder, F_QUEUE) &&
                                    !folder_has_parent_of_type(msginfo->folder, F_OUTBOX) &&
                                    !folder_has_parent_of_type(msginfo->folder, F_DRAFT)) {
-                                       compose_entry_append(compose,
-                                                 msginfo->from ? msginfo->from : "",
-                                                 COMPOSE_TO);
+                                       if (compose->replyto) {
+                                               compose_entry_append(compose,
+                                                       compose->replyto,
+                                                       COMPOSE_TO);
+                                       } else {
+                                               compose_entry_append(compose,
+                                                         msginfo->from ? msginfo->from : "",
+                                                         COMPOSE_TO);
+                                       }
                                } else {
                                        /* replying to own mail, use original recp */
                                        compose_entry_append(compose,
@@ -3333,6 +3560,7 @@ static gboolean compose_attach_append(Compose *compose, const gchar *file,
                           -1);
        
        g_auto_pointer_free(auto_ainfo);
+       compose_attach_update_label(compose);
        return TRUE;
 }
 
@@ -3703,9 +3931,9 @@ static gboolean compose_join_next_line(Compose *compose,
        gboolean keep_cursor = FALSE;
 
        if (!gtk_text_iter_forward_line(&iter_) ||
-           gtk_text_iter_ends_line(&iter_))
+           gtk_text_iter_ends_line(&iter_)) {
                return FALSE;
-
+       }
        next_quote_str = compose_get_quote_str(buffer, &iter_, &quote_len);
 
        if ((quote_str || next_quote_str) &&
@@ -3718,18 +3946,20 @@ static gboolean compose_join_next_line(Compose *compose,
        end = iter_;
        if (quote_len > 0) {
                gtk_text_iter_forward_chars(&end, quote_len);
-               if (gtk_text_iter_ends_line(&end))
+               if (gtk_text_iter_ends_line(&end)) {
                        return FALSE;
+               }
        }
 
        /* don't join itemized lines */
-       if (compose_is_itemized(buffer, &end))
+       if (compose_is_itemized(buffer, &end)) {
                return FALSE;
+       }
 
        /* don't join signature separator */
-       if (compose_is_sig_separator(compose, buffer, &iter_))
+       if (compose_is_sig_separator(compose, buffer, &iter_)) {
                return FALSE;
-
+       }
        /* delete quote str */
        if (quote_len > 0)
                gtk_text_buffer_delete(buffer, &iter_, &end);
@@ -4121,7 +4351,7 @@ colorize:
                                removed = TRUE;
                        }
                }
-               if (uri_start > 0 && uri_stop > 0) {
+               if (uri_start >= 0 && uri_stop > 0) {
                        GtkTextIter uri_start_iter, uri_end_iter, back;
                        gtk_text_buffer_get_iter_at_offset(
                                buffer, &uri_start_iter, uri_start);
@@ -4369,10 +4599,10 @@ gboolean compose_check_for_valid_recipient(Compose *compose) {
        for (list = compose->header_list; list; list = list->next) {
                gchar *header;
                gchar *entry;
-               header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
+               header = gtk_editable_get_chars(GTK_EDITABLE(GTK_BIN(((ComposeHeaderEntry *)list->data)->combo)->child), 0, -1);
                entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
-
                g_strstrip(entry);
+               g_strstrip(header);
                if (entry[0] != '\0') {
                        for (strptr = recipient_headers_mail; *strptr != NULL; strptr++) {
                                if (!strcmp(header, prefs_common_translated_header_name(*strptr))) {
@@ -4403,8 +4633,9 @@ static gboolean compose_check_for_set_recipients(Compose *compose)
                        gchar *entry;
                        gchar *header;
                        entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
-                       header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
+                       header = gtk_editable_get_chars(GTK_EDITABLE(GTK_BIN(((ComposeHeaderEntry *)list->data)->combo)->child), 0, -1);
                        g_strstrip(entry);
+                       g_strstrip(header);
                        if (strcmp(entry, compose->account->auto_cc)
                        ||  strcmp(header, prefs_common_translated_header_name("Cc:"))) {
                                found_other = TRUE;
@@ -4434,8 +4665,9 @@ static gboolean compose_check_for_set_recipients(Compose *compose)
                        gchar *entry;
                        gchar *header;
                        entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
-                       header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
+                       header = gtk_editable_get_chars(GTK_EDITABLE(GTK_BIN(((ComposeHeaderEntry *)list->data)->combo)->child), 0, -1);
                        g_strstrip(entry);
+                       g_strstrip(header);
                        if (strcmp(entry, compose->account->auto_bcc)
                        ||  strcmp(header, prefs_common_translated_header_name("Bcc:"))) {
                                found_other = TRUE;
@@ -4481,10 +4713,20 @@ static gboolean compose_check_entries(Compose *compose, gboolean check_everythin
                if (*str == '\0' && check_everything == TRUE && 
                    compose->mode != COMPOSE_REDIRECT) {
                        AlertValue aval;
+                       gchar *button_label;
+                       gchar *message;
 
-                       aval = alertpanel(_("Send"),
-                                         _("Subject is empty. Send it anyway?"),
-                                         GTK_STOCK_CANCEL, _("+_Send"), NULL);
+                       if (compose->sending)
+                               button_label = _("+_Send");
+                       else
+                               button_label = _("+_Queue");
+                       message = g_strdup_printf(_("Subject is empty. %s"),
+                                       compose->sending?_("Send it anyway?"):
+                                       _("Queue it anyway?"));
+
+                       aval = alertpanel(compose->sending?_("Send"):_("Send later"), message,
+                                         GTK_STOCK_CANCEL, button_label, NULL);
+                       g_free(message);
                        if (aval != G_ALERTALTERNATE)
                                return FALSE;
                }
@@ -4549,7 +4791,7 @@ gint compose_send(Compose *compose)
                goto bail;
        }
 
-       tmsgid = g_strdup(compose->msgid);
+       tmsgid = compose->msgid ? g_strdup(compose->msgid) : NULL;
        if (discard_window) {
                compose->sending = FALSE;
                compose_close(compose);
@@ -4575,7 +4817,7 @@ gint compose_send(Compose *compose)
                g_free(msgpath);
        } else {
                val = procmsg_send_message_queue(msgpath, &errstr, folder, msgnum, &queued_removed);
-               g_unlink(msgpath);
+               claws_unlink(msgpath);
                g_free(msgpath);
        }
        if (!discard_window) {
@@ -4615,11 +4857,9 @@ gint compose_send(Compose *compose)
                }
        } else {
                if (errstr) {
-                       gchar *tmp = g_strdup_printf(_("%s\nUse \"Send queued messages\" from "
+                       alertpanel_error_log(_("%s\nUse \"Send queued messages\" from "
                                   "the main window to retry."), errstr);
                        g_free(errstr);
-                       alertpanel_error_log(tmp);
-                       g_free(tmp);
                } else {
                        alertpanel_error_log(_("The message was queued but could not be "
                                   "sent.\nUse \"Send queued messages\" from "
@@ -4669,6 +4909,7 @@ static gint compose_redirect_write_headers_from_headerlist(Compose *compose,
        const gchar *headerentryname;
        const gchar *cc_hdr;
        const gchar *to_hdr;
+       gboolean err = FALSE;
 
        debug_print("Writing redirect header\n");
 
@@ -4678,7 +4919,7 @@ static gint compose_redirect_write_headers_from_headerlist(Compose *compose,
        first_to_address = TRUE;
        for (list = compose->header_list; list; list = list->next) {
                headerentry = ((ComposeHeaderEntry *)list->data);
-               headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
+               headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_BIN(headerentry->combo)->child));
 
                if (g_utf8_collate(headerentryname, to_hdr) == 0) {
                        const gchar *entstr = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
@@ -4690,23 +4931,23 @@ static gint compose_redirect_write_headers_from_headerlist(Compose *compose,
                                        strlen("Resent-To") + 2, TRUE);
 
                                if (first_to_address) {
-                                       fprintf(fp, "Resent-To: ");
+                                       err |= (fprintf(fp, "Resent-To: ") < 0);
                                        first_to_address = FALSE;
                                } else {
-                                       fprintf(fp, ",");
+                                       err |= (fprintf(fp, ",") < 0);
                                 }
-                               fprintf(fp, "%s", buf);
+                               err |= (fprintf(fp, "%s", buf) < 0);
                        }
                }
        }
        if (!first_to_address) {
-               fprintf(fp, "\n");
+               err |= (fprintf(fp, "\n") < 0);
        }
 
        first_cc_address = TRUE;
        for (list = compose->header_list; list; list = list->next) {
                headerentry = ((ComposeHeaderEntry *)list->data);
-               headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
+               headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_BIN(headerentry->combo)->child));
 
                if (g_utf8_collate(headerentryname, cc_hdr) == 0) {
                        const gchar *strg = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
@@ -4718,20 +4959,20 @@ static gint compose_redirect_write_headers_from_headerlist(Compose *compose,
                                        strlen("Resent-Cc") + 2, TRUE);
 
                                 if (first_cc_address) {
-                                        fprintf(fp, "Resent-Cc: ");
+                                        err |= (fprintf(fp, "Resent-Cc: ") < 0);
                                         first_cc_address = FALSE;
                                 } else {
-                                        fprintf(fp, ",");
+                                        err |= (fprintf(fp, ",") < 0);
                                 }
-                               fprintf(fp, "%s", buf);
+                               err |= (fprintf(fp, "%s", buf) < 0);
                        }
                }
        }
        if (!first_cc_address) {
-               fprintf(fp, "\n");
+               err |= (fprintf(fp, "\n") < 0);
         }
        
-       return(0);
+       return (err ? -1:0);
 }
 
 static gint compose_redirect_write_headers(Compose *compose, FILE *fp)
@@ -4740,6 +4981,7 @@ static gint compose_redirect_write_headers(Compose *compose, FILE *fp)
        gchar *str;
        const gchar *entstr;
        /* struct utsname utsbuf; */
+       gboolean err = FALSE;
 
        g_return_val_if_fail(fp != NULL, -1);
        g_return_val_if_fail(compose->account != NULL, -1);
@@ -4747,17 +4989,17 @@ static gint compose_redirect_write_headers(Compose *compose, FILE *fp)
 
        /* Resent-Date */
        get_rfc822_date(buf, sizeof(buf));
-       fprintf(fp, "Resent-Date: %s\n", buf);
+       err |= (fprintf(fp, "Resent-Date: %s\n", buf) < 0);
 
        /* Resent-From */
        if (compose->account->name && *compose->account->name) {
                compose_convert_header
                        (compose, buf, sizeof(buf), compose->account->name,
                         strlen("From: "), TRUE);
-               fprintf(fp, "Resent-From: %s <%s>\n",
-                       buf, compose->account->address);
+               err |= (fprintf(fp, "Resent-From: %s <%s>\n",
+                       buf, compose->account->address) < 0);
        } else
-               fprintf(fp, "Resent-From: %s\n", compose->account->address);
+               err |= (fprintf(fp, "Resent-From: %s\n", compose->account->address) < 0);
 
        /* Subject */
        entstr = gtk_entry_get_text(GTK_ENTRY(compose->subject_entry));
@@ -4767,23 +5009,37 @@ static gint compose_redirect_write_headers(Compose *compose, FILE *fp)
                if (*str != '\0') {
                        compose_convert_header(compose, buf, sizeof(buf), str,
                                               strlen("Subject: "), FALSE);
-                       fprintf(fp, "Subject: %s\n", buf);
+                       err |= (fprintf(fp, "Subject: %s\n", buf) < 0);
                }
        }
 
        /* Resent-Message-ID */
+       if (compose->account->set_domain && compose->account->domain) {
+               g_snprintf(buf, sizeof(buf), "%s", compose->account->domain); 
+       } else if (!strncmp(get_domain_name(), "localhost", strlen("localhost"))) {
+               g_snprintf(buf, sizeof(buf), "%s", 
+                       strchr(compose->account->address, '@') ?
+                               strchr(compose->account->address, '@')+1 :
+                               compose->account->address);
+       } else {
+               g_snprintf(buf, sizeof(buf), "%s", "");
+       }
+
        if (compose->account->gen_msgid) {
                generate_msgid(buf, sizeof(buf));
-               fprintf(fp, "Resent-Message-ID: <%s>\n", buf);
+               err |= (fprintf(fp, "Resent-Message-ID: <%s>\n", buf) < 0);
                compose->msgid = g_strdup(buf);
+       } else {
+               compose->msgid = NULL;
        }
 
-       compose_redirect_write_headers_from_headerlist(compose, fp);
+       if (compose_redirect_write_headers_from_headerlist(compose, fp))
+               return -1;
 
        /* separator between header and body */
-       fputs("\n", fp);
+       err |= (fputs("\n", fp) == EOF);
 
-       return 0;
+       return (err ? -1:0);
 }
 
 static gint compose_redirect_write_to_file(Compose *compose, FILE *fdest)
@@ -4793,6 +5049,7 @@ static gint compose_redirect_write_to_file(Compose *compose, FILE *fdest)
        gchar buf[BUFFSIZE];
        int i = 0;
        gboolean skip = FALSE;
+       gboolean err = FALSE;
        gchar *not_included[]={
                "Return-Path:",         "Delivered-To:",        "Received:",
                "Subject:",             "X-UIDL:",              "AF:",
@@ -4831,7 +5088,7 @@ static gint compose_redirect_write_to_file(Compose *compose, FILE *fdest)
                if (!prefs_common.redirect_keep_from) {
                        if (g_ascii_strncasecmp(buf, "From:",
                                          strlen("From:")) == 0) {
-                               fputs(" (by way of ", fdest);
+                               err |= (fputs(" (by way of ", fdest) == EOF);
                                if (compose->account->name
                                    && *compose->account->name) {
                                        compose_convert_header
@@ -4839,13 +5096,13 @@ static gint compose_redirect_write_to_file(Compose *compose, FILE *fdest)
                                                 compose->account->name,
                                                 strlen("From: "),
                                                 FALSE);
-                                       fprintf(fdest, "%s <%s>",
+                                       err |= (fprintf(fdest, "%s <%s>",
                                                buf,
-                                               compose->account->address);
+                                               compose->account->address) < 0);
                                } else
-                                       fprintf(fdest, "%s",
-                                               compose->account->address);
-                               fputs(")", fdest);
+                                       err |= (fprintf(fdest, "%s",
+                                               compose->account->address) < 0);
+                               err |= (fputs(")", fdest) == EOF);
                        }
                }
 
@@ -4853,7 +5110,11 @@ static gint compose_redirect_write_to_file(Compose *compose, FILE *fdest)
                        goto error;
        }
 
-       compose_redirect_write_headers(compose, fdest);
+       if (err)
+               goto error;
+
+       if (compose_redirect_write_headers(compose, fdest))
+               goto error;
 
        while ((len = fread(buf, sizeof(gchar), sizeof(buf), fp)) > 0) {
                if (fwrite(buf, sizeof(gchar), len, fdest) != len)
@@ -5009,7 +5270,7 @@ static gint compose_write_to_file(Compose *compose, FILE *fp, gint action, gbool
                encoding = ENC_QUOTED_PRINTABLE;
        }
        
-       debug_print("main text: %d bytes encoded as %s in %d\n",
+       debug_print("main text: %zd bytes encoded as %s in %d\n",
                strlen(buf), out_codeset, encoding);
 
        /* check for line length limit */
@@ -5112,7 +5373,7 @@ static gint compose_write_body_to_file(Compose *compose, const gchar *file)
                FILE_OP_ERROR(file, "fwrite");
                g_free(chars);
                fclose(fp);
-               g_unlink(file);
+               claws_unlink(file);
                return -1;
        }
 
@@ -5120,7 +5381,7 @@ static gint compose_write_body_to_file(Compose *compose, const gchar *file)
 
        if (fclose(fp) == EOF) {
                FILE_OP_ERROR(file, "fclose");
-               g_unlink(file);
+               claws_unlink(file);
                return -1;
        }
        return 0;
@@ -5209,7 +5470,8 @@ static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
        gint num;
         static gboolean lock = FALSE;
        PrefsAccount *mailac = NULL, *newsac = NULL;
-       
+       gboolean err = FALSE;
+
        debug_print("queueing message...\n");
        g_return_val_if_fail(compose->account != NULL, -1);
 
@@ -5252,8 +5514,9 @@ static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
        }
 
        /* write queue header */
-       tmp = g_strdup_printf("%s%cqueue.%p", get_tmp_dir(),
-                             G_DIR_SEPARATOR, compose);
+       tmp = g_strdup_printf("%s%cqueue.%p%08x", get_tmp_dir(),
+                             G_DIR_SEPARATOR, compose, (guint) rand());
+       debug_print("queuing to %s\n", tmp);
        if ((fp = g_fopen(tmp, "wb")) == NULL) {
                FILE_OP_ERROR(tmp, "fopen");
                g_free(tmp);
@@ -5267,61 +5530,61 @@ static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
        }
 
        /* queueing variables */
-       fprintf(fp, "AF:\n");
-       fprintf(fp, "NF:0\n");
-       fprintf(fp, "PS:10\n");
-       fprintf(fp, "SRH:1\n");
-       fprintf(fp, "SFN:\n");
-       fprintf(fp, "DSR:\n");
+       err |= (fprintf(fp, "AF:\n") < 0);
+       err |= (fprintf(fp, "NF:0\n") < 0);
+       err |= (fprintf(fp, "PS:10\n") < 0);
+       err |= (fprintf(fp, "SRH:1\n") < 0);
+       err |= (fprintf(fp, "SFN:\n") < 0);
+       err |= (fprintf(fp, "DSR:\n") < 0);
        if (compose->msgid)
-               fprintf(fp, "MID:<%s>\n", compose->msgid);
+               err |= (fprintf(fp, "MID:<%s>\n", compose->msgid) < 0);
        else
-               fprintf(fp, "MID:\n");
-       fprintf(fp, "CFG:\n");
-       fprintf(fp, "PT:0\n");
-       fprintf(fp, "S:%s\n", compose->account->address);
-       fprintf(fp, "RQ:\n");
+               err |= (fprintf(fp, "MID:\n") < 0);
+       err |= (fprintf(fp, "CFG:\n") < 0);
+       err |= (fprintf(fp, "PT:0\n") < 0);
+       err |= (fprintf(fp, "S:%s\n", compose->account->address) < 0);
+       err |= (fprintf(fp, "RQ:\n") < 0);
        if (mailac)
-               fprintf(fp, "SSV:%s\n", mailac->smtp_server);
+               err |= (fprintf(fp, "SSV:%s\n", mailac->smtp_server) < 0);
        else
-               fprintf(fp, "SSV:\n");
+               err |= (fprintf(fp, "SSV:\n") < 0);
        if (newsac)
-               fprintf(fp, "NSV:%s\n", newsac->nntp_server);
+               err |= (fprintf(fp, "NSV:%s\n", newsac->nntp_server) < 0);
        else
-               fprintf(fp, "NSV:\n");
-       fprintf(fp, "SSH:\n");
+               err |= (fprintf(fp, "NSV:\n") < 0);
+       err |= (fprintf(fp, "SSH:\n") < 0);
        /* write recepient list */
        if (compose->to_list) {
-               fprintf(fp, "R:<%s>", (gchar *)compose->to_list->data);
+               err |= (fprintf(fp, "R:<%s>", (gchar *)compose->to_list->data) < 0);
                for (cur = compose->to_list->next; cur != NULL;
                     cur = cur->next)
-                       fprintf(fp, ",<%s>", (gchar *)cur->data);
-               fprintf(fp, "\n");
+                       err |= (fprintf(fp, ",<%s>", (gchar *)cur->data) < 0);
+               err |= (fprintf(fp, "\n") < 0);
        }
        /* write newsgroup list */
        if (compose->newsgroup_list) {
-               fprintf(fp, "NG:");
-               fprintf(fp, "%s", (gchar *)compose->newsgroup_list->data);
+               err |= (fprintf(fp, "NG:") < 0);
+               err |= (fprintf(fp, "%s", (gchar *)compose->newsgroup_list->data) < 0);
                for (cur = compose->newsgroup_list->next; cur != NULL; cur = cur->next)
-                       fprintf(fp, ",%s", (gchar *)cur->data);
-               fprintf(fp, "\n");
+                       err |= (fprintf(fp, ",%s", (gchar *)cur->data) < 0);
+               err |= (fprintf(fp, "\n") < 0);
        }
        /* Sylpheed account IDs */
        if (mailac)
-               fprintf(fp, "MAID:%d\n", mailac->account_id);
+               err |= (fprintf(fp, "MAID:%d\n", mailac->account_id) < 0);
        if (newsac)
-               fprintf(fp, "NAID:%d\n", newsac->account_id);
+               err |= (fprintf(fp, "NAID:%d\n", newsac->account_id) < 0);
 
        
        if (compose->privacy_system != NULL) {
-               fprintf(fp, "X-Claws-Privacy-System:%s\n", compose->privacy_system);
-               fprintf(fp, "X-Claws-Sign:%d\n", compose->use_signing);
+               err |= (fprintf(fp, "X-Claws-Privacy-System:%s\n", compose->privacy_system) < 0);
+               err |= (fprintf(fp, "X-Claws-Sign:%d\n", compose->use_signing) < 0);
                if (compose->use_encryption) {
                        gchar *encdata;
                        if (!compose_warn_encryption(compose)) {
                                lock = FALSE;
                                fclose(fp);
-                               g_unlink(tmp);
+                               claws_unlink(tmp);
                                g_free(tmp);
                                return -6;
                        }
@@ -5335,17 +5598,17 @@ static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
                        }
                        if (encdata != NULL) {
                                if (strcmp(encdata, "_DONT_ENCRYPT_")) {
-                                       fprintf(fp, "X-Claws-Encrypt:%d\n", compose->use_encryption);
-                                       fprintf(fp, "X-Claws-Encrypt-Data:%s\n", 
-                                               encdata);
+                                       err |= (fprintf(fp, "X-Claws-Encrypt:%d\n", compose->use_encryption) < 0);
+                                       err |= (fprintf(fp, "X-Claws-Encrypt-Data:%s\n", 
+                                               encdata) < 0);
                                } /* else we finally dont want to encrypt */
                        } else {
-                               fprintf(fp, "X-Claws-Encrypt:%d\n", compose->use_encryption);
+                               err |= (fprintf(fp, "X-Claws-Encrypt:%d\n", compose->use_encryption) < 0);
                                /* and if encdata was null, it means there's been a problem in 
                                 * key selection */
                                lock = FALSE;
                                fclose(fp);
-                               g_unlink(tmp);
+                               claws_unlink(tmp);
                                g_free(tmp);
                                return -5;
                        }
@@ -5358,19 +5621,19 @@ static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
                gchar *savefolderid;
                
                savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
-               fprintf(fp, "SCF:%s\n", savefolderid);
+               err |= (fprintf(fp, "SCF:%s\n", savefolderid) < 0);
                g_free(savefolderid);
        }
        /* Save copy folder */
        if (compose->return_receipt) {
-               fprintf(fp, "RRCPT:1\n");
+               err |= (fprintf(fp, "RRCPT:1\n") < 0);
        }
        /* Message-ID of message replying to */
        if ((compose->replyinfo != NULL) && (compose->replyinfo->msgid != NULL)) {
                gchar *folderid;
                
                folderid = folder_item_get_identifier(compose->replyinfo->folder);
-               fprintf(fp, "RMID:%s\t%d\t%s\n", folderid, compose->replyinfo->msgnum, compose->replyinfo->msgid);
+               err |= (fprintf(fp, "RMID:%s\t%d\t%s\n", folderid, compose->replyinfo->msgnum, compose->replyinfo->msgid) < 0);
                g_free(folderid);
        }
        /* Message-ID of message forwarding to */
@@ -5378,18 +5641,18 @@ static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
                gchar *folderid;
                
                folderid = folder_item_get_identifier(compose->fwdinfo->folder);
-               fprintf(fp, "FMID:%s\t%d\t%s\n", folderid, compose->fwdinfo->msgnum, compose->fwdinfo->msgid);
+               err |= (fprintf(fp, "FMID:%s\t%d\t%s\n", folderid, compose->fwdinfo->msgnum, compose->fwdinfo->msgid) < 0);
                g_free(folderid);
        }
 
        /* end of headers */
-       fprintf(fp, "X-Claws-End-Special-Headers: 1\n");
+       err |= (fprintf(fp, "X-Claws-End-Special-Headers: 1\n") < 0);
 
        if (compose->redirect_filename != NULL) {
                if (compose_redirect_write_to_file(compose, fp) < 0) {
                        lock = FALSE;
                        fclose(fp);
-                       g_unlink(tmp);
+                       claws_unlink(tmp);
                        g_free(tmp);
                        return -2;
                }
@@ -5398,15 +5661,22 @@ static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
                if ((result = compose_write_to_file(compose, fp, COMPOSE_WRITE_FOR_SEND, TRUE)) < 0) {
                        lock = FALSE;
                        fclose(fp);
-                       g_unlink(tmp);
+                       claws_unlink(tmp);
                        g_free(tmp);
                        return result - 1; /* -2 for a generic error, -3 for signing error, -4 for encoding */
                }
        }
-
+       if (err == TRUE) {
+               g_warning("failed to write queue message\n");
+               fclose(fp);
+               claws_unlink(tmp);
+               g_free(tmp);
+               lock = FALSE;
+               return -2;
+       }
        if (fclose(fp) == EOF) {
                FILE_OP_ERROR(tmp, "fclose");
-               g_unlink(tmp);
+               claws_unlink(tmp);
                g_free(tmp);
                lock = FALSE;
                return -2;
@@ -5419,7 +5689,7 @@ static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
        }
        if (!queue) {
                g_warning("can't find queue folder\n");
-               g_unlink(tmp);
+               claws_unlink(tmp);
                g_free(tmp);
                lock = FALSE;
                return -1;
@@ -5427,14 +5697,14 @@ static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
        folder_item_scan(queue);
        if ((num = folder_item_add_msg(queue, tmp, NULL, FALSE)) < 0) {
                g_warning("can't queue the message\n");
-               g_unlink(tmp);
+               claws_unlink(tmp);
                g_free(tmp);
                lock = FALSE;
                return -1;
        }
        
        if (msgpath == NULL) {
-               g_unlink(tmp);
+               claws_unlink(tmp);
                g_free(tmp);
        } else
                *msgpath = tmp;
@@ -5547,7 +5817,7 @@ static void compose_add_headerfield_from_headerlist(Compose *compose,
 
        for (list = compose->header_list; list; list = list->next) {
                headerentry = ((ComposeHeaderEntry *)list->data);
-               headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
+               headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_BIN(headerentry->combo)->child));
 
                if (!g_utf8_collate(trans_fieldname, headerentryname)) {
                        str = gtk_editable_get_chars(GTK_EDITABLE(headerentry->entry), 0, -1);
@@ -5672,10 +5942,23 @@ static gchar *compose_get_header(Compose *compose)
        g_free(str);
 
        /* Message-ID */
+       if (compose->account->set_domain && compose->account->domain) {
+               g_snprintf(buf, sizeof(buf), "%s", compose->account->domain); 
+       } else if (!strncmp(get_domain_name(), "localhost", strlen("localhost"))) {
+               g_snprintf(buf, sizeof(buf), "%s", 
+                       strchr(compose->account->address, '@') ?
+                               strchr(compose->account->address, '@')+1 :
+                               compose->account->address);
+       } else {
+               g_snprintf(buf, sizeof(buf), "%s", "");
+       }
+       
        if (compose->account->gen_msgid) {
                generate_msgid(buf, sizeof(buf));
                g_string_append_printf(header, "Message-ID: <%s>\n", buf);
                compose->msgid = g_strdup(buf);
+       } else {
+               compose->msgid = NULL;
        }
 
        if (compose->remove_references == FALSE) {
@@ -5783,9 +6066,10 @@ static gchar *compose_get_header(Compose *compose)
                gboolean standard_header = FALSE;
 
                headerentry = ((ComposeHeaderEntry *)list->data);
-               
-               tmp = g_strdup(gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry)));
-               if (strchr(tmp, ' ') != NULL || strchr(tmp, '\r') != NULL || strchr(tmp, '\n') != NULL) {
+
+               tmp = g_strdup(gtk_entry_get_text(GTK_ENTRY(GTK_BIN(headerentry->combo)->child)));
+               g_strstrip(tmp);
+               if (*tmp == '\0' || strchr(tmp, ' ') != NULL || strchr(tmp, '\r') != NULL || strchr(tmp, '\n') != NULL) {
                        g_free(tmp);
                        continue;
                }
@@ -5899,7 +6183,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);
-               addressbook_add_contact(name, address, NULL);
+               addressbook_add_contact(name, address, NULL, NULL);
        }
        g_free(address);
 }
@@ -5936,25 +6220,23 @@ static void compose_create_header_entry(Compose *compose)
 
        GtkWidget *combo;
        GtkWidget *entry;
-       GList *combo_list = NULL;
        gchar **string;
        const gchar *header = NULL;
        ComposeHeaderEntry *headerentry;
        gboolean standard_header = FALSE;
-
+       
        headerentry = g_new0(ComposeHeaderEntry, 1);
 
        /* Combo box */
-       combo = gtk_combo_new();
+       combo = gtk_combo_box_entry_new_text();
        string = headers; 
        while(*string != NULL) {
-               combo_list = g_list_append(combo_list, (gchar*)prefs_common_translated_header_name(*string));
+               gtk_combo_box_append_text(GTK_COMBO_BOX(combo),
+                       (gchar*)prefs_common_translated_header_name(*string));
                string++;
        }
-       gtk_combo_set_popdown_strings(GTK_COMBO(combo), combo_list);
-       g_list_free(combo_list);
-       gtk_editable_set_editable(GTK_EDITABLE(GTK_COMBO(combo)->entry), TRUE);
-       g_signal_connect(G_OBJECT(GTK_COMBO(combo)->entry), "grab_focus",
+       gtk_combo_box_set_active(GTK_COMBO_BOX(combo), 0);
+       g_signal_connect(G_OBJECT(GTK_BIN(combo)->child), "grab_focus",
                         G_CALLBACK(compose_grab_focus_cb), compose);
        gtk_widget_show(combo);
        gtk_table_attach(GTK_TABLE(compose->header_table), combo, 0, 1,
@@ -5962,7 +6244,7 @@ static void compose_create_header_entry(Compose *compose)
                        GTK_SHRINK, GTK_FILL, 0, 0);
        if (compose->header_last) {     
                const gchar *last_header_entry = gtk_entry_get_text(
-                               GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
+                               GTK_ENTRY(GTK_BIN(compose->header_last->combo)->child));
                string = headers;
                while (*string != NULL) {
                        if (!strcmp(*string, last_header_entry))
@@ -5970,7 +6252,7 @@ static void compose_create_header_entry(Compose *compose)
                        string++;
                }
                if (standard_header)
-                       header = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry));
+                       header = gtk_entry_get_text(GTK_ENTRY(GTK_BIN(compose->header_last->combo)->child));
        }
        if (!compose->header_last || !standard_header) {
                switch(compose->account->protocol) {
@@ -5983,9 +6265,9 @@ static void compose_create_header_entry(Compose *compose)
                }                                                                   
        }
        if (header)
-               gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), header);
+               gtk_entry_set_text(GTK_ENTRY(GTK_BIN(combo)->child), header);
 
-       g_signal_connect_after(G_OBJECT(GTK_COMBO(combo)->entry), "grab_focus",
+       g_signal_connect_after(G_OBJECT(GTK_BIN(combo)->child), "grab_focus",
                         G_CALLBACK(compose_grab_focus_cb), compose);
 
        /* Entry field */
@@ -6040,7 +6322,7 @@ static void compose_add_header_entry(Compose *compose, const gchar *header, gcha
        
        last_header = compose->header_last;
 
-       gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(last_header->combo)->entry), header);
+       gtk_entry_set_text(GTK_ENTRY(GTK_BIN(last_header->combo)->child), header);
        gtk_entry_set_text(GTK_ENTRY(last_header->entry), text);
 }
 
@@ -6078,7 +6360,7 @@ static GtkWidget *compose_create_header(Compose *compose)
        gtk_widget_show(header_table);
        gtk_container_set_border_width(GTK_CONTAINER(header_table), BORDER_WIDTH);
        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);
+       gtk_viewport_set_shadow_type(GTK_VIEWPORT(GTK_BIN(header_scrolledwin)->child), GTK_SHADOW_NONE);
        count = 0;
 
        /* option menu for selecting accounts */
@@ -6264,7 +6546,7 @@ static void compose_savemsg_select_cb(GtkWidget *widget, Compose *compose)
        FolderItem *dest;
        gchar * path;
 
-       dest = foldersel_folder_sel(NULL, FOLDER_SEL_COPY, NULL);
+       dest = foldersel_folder_sel(NULL, FOLDER_SEL_COPY, NULL, FALSE);
        if (!dest) return;
 
        path = folder_item_get_identifier(dest);
@@ -6281,7 +6563,7 @@ static gboolean text_clicked(GtkWidget *text, GdkEventButton *event,
                                        Compose *compose)
 {
        gint prev_autowrap;
-       GtkTextBuffer *buffer;
+       GtkTextBuffer *buffer = GTK_TEXT_VIEW(text)->buffer;
 #if USE_ASPELL
        if (event->button == 3) {
                GtkTextIter iter;
@@ -6290,21 +6572,26 @@ static gboolean text_clicked(GtkWidget *text, GdkEventButton *event,
                gint x, y;
                /* move the cursor to allow GtkAspell to check the word
                 * under the mouse */
-               gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(text),
-                       GTK_TEXT_WINDOW_TEXT, event->x, event->y,
-                       &x, &y);
-               gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW(text),
-                       &iter, x, y);
+               if (event->x && event->y) {
+                       gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(text),
+                               GTK_TEXT_WINDOW_TEXT, event->x, event->y,
+                               &x, &y);
+                       gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW(text),
+                               &iter, x, y);
+               } else {
+                       GtkTextMark *mark = gtk_text_buffer_get_insert(buffer);
+                       gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
+               }
                /* get selection */
                stuff_selected = gtk_text_buffer_get_selection_bounds(
-                               GTK_TEXT_VIEW(text)->buffer,
+                               buffer,
                                &sel_start, &sel_end);
 
-               gtk_text_buffer_place_cursor (GTK_TEXT_VIEW(text)->buffer, &iter);
+               gtk_text_buffer_place_cursor (buffer, &iter);
                /* reselect stuff */
                if (stuff_selected 
                && gtk_text_iter_in_range(&iter, &sel_start, &sel_end)) {
-                       gtk_text_buffer_select_range(GTK_TEXT_VIEW(text)->buffer,
+                       gtk_text_buffer_select_range(buffer,
                                &sel_start, &sel_end);
                }
                return FALSE; /* pass the event so that the right-click goes through */
@@ -6380,6 +6667,8 @@ static gboolean compose_popup_menu(GtkWidget *widget, gpointer data)
        
        event.button = 3;
        event.time = gtk_get_current_event_time();
+       event.x = 0;
+       event.y = 0;
 
        return text_clicked(compose->text, &event, compose);
 }
@@ -6397,6 +6686,10 @@ static Compose *compose_create(PrefsAccount *account,
        GtkWidget *handlebox;
 
        GtkWidget *notebook;
+       
+       GtkWidget *attach_hbox;
+       GtkWidget *attach_lab1;
+       GtkWidget *attach_lab2;
 
        GtkWidget *vbox2;
 
@@ -6519,9 +6812,20 @@ static Compose *compose_create(PrefsAccount *account,
                        compose_create_header(compose),
                        gtk_label_new_with_mnemonic(_("Hea_der")));
        /* attachment list */
+       attach_hbox = gtk_hbox_new(FALSE, 0);
+       gtk_widget_show(attach_hbox);
+       
+       attach_lab1 = gtk_label_new_with_mnemonic(_("_Attachments"));
+       gtk_widget_show(attach_lab1);
+       gtk_box_pack_start(GTK_BOX(attach_hbox), attach_lab1, TRUE, TRUE, 0);
+       
+       attach_lab2 = gtk_label_new("");
+       gtk_widget_show(attach_lab2);
+       gtk_box_pack_start(GTK_BOX(attach_hbox), attach_lab2, FALSE, FALSE, 0);
+       
        gtk_notebook_append_page(GTK_NOTEBOOK(notebook),
                        compose_create_attach(compose),
-                       gtk_label_new_with_mnemonic(_("_Attachments")));
+                       attach_hbox);
        /* Others Tab */
        gtk_notebook_append_page(GTK_NOTEBOOK(notebook),
                        compose_create_others(compose),
@@ -6673,6 +6977,8 @@ static Compose *compose_create(PrefsAccount *account,
 
        compose->paned = paned;
 
+       compose->attach_label  = attach_lab2;
+
        compose->notebook      = notebook;
        compose->edit_vbox     = edit_vbox;
        compose->ruler_hbox    = ruler_hbox;
@@ -6783,10 +7089,10 @@ static Compose *compose_create(PrefsAccount *account,
        menu_set_sensitive(ifactory, "/Options/Reply mode", compose->mode == COMPOSE_REPLY);
 
        if (account->protocol != A_NNTP)
-               gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry),
+               gtk_entry_set_text(GTK_ENTRY(GTK_BIN(compose->header_last->combo)->child),
                                prefs_common_translated_header_name("To:"));
        else
-               gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(compose->header_last->combo)->entry),
+               gtk_entry_set_text(GTK_ENTRY(GTK_BIN(compose->header_last->combo)->child),
                                prefs_common_translated_header_name("Newsgroups:"));
 
        addressbook_set_target_compose(compose);
@@ -7027,7 +7333,6 @@ static void compose_update_privacy_system_menu_item(Compose * compose, gboolean
 
        if (compose->privacy_system != NULL) {
                gchar *systemid;
-
                menuitem = gtk_item_factory_get_widget(ifactory, branch_path);
                g_return_if_fail(menuitem != NULL);
 
@@ -7061,12 +7366,9 @@ static void compose_update_privacy_system_menu_item(Compose * compose, gboolean
                        gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE);
                
                if (warn && !found && strlen(compose->privacy_system)) {
-                       gchar *tmp = g_strdup_printf(
-                               _("The privacy system '%s' cannot be loaded. You "
+                       alertpanel_warning(_("The privacy system '%s' cannot be loaded. You "
                                  "will not be able to sign or encrypt this message."),
                                  compose->privacy_system);
-                       alertpanel_warning(tmp);
-                       g_free(tmp);
                }
        } 
 
@@ -7341,6 +7643,7 @@ static void compose_template_apply(Compose *compose, Template *tmpl,
        /* process the other fields */
 
        compose_template_apply_fields(compose, tmpl);
+       compose_attach_from_list(compose, quote_fmt_get_attachments_list(), FALSE);
        quote_fmt_reset_vartable();
        compose_changed_cb(NULL, compose);
 }
@@ -7360,12 +7663,30 @@ static void compose_template_apply_fields(Compose *compose, Template *tmpl)
                msginfo = dummyinfo;
        }
 
+       if (tmpl->from && *tmpl->from != '\0') {
+#ifdef USE_ASPELL
+               quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account, FALSE,
+                               compose->gtkaspell);
+#else
+               quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account, FALSE);
+#endif
+               quote_fmt_scan_string(tmpl->from);
+               quote_fmt_parse();
+
+               buf = quote_fmt_get_buffer();
+               if (buf == NULL) {
+                       alertpanel_error(_("Template From format error."));
+               } else {
+                       gtk_entry_set_text(GTK_ENTRY(compose->from_name), buf);
+               }
+       }
+
        if (tmpl->to && *tmpl->to != '\0') {
 #ifdef USE_ASPELL
-               quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account,
+               quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account, FALSE,
                                compose->gtkaspell);
 #else
-               quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account);
+               quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account, FALSE);
 #endif
                quote_fmt_scan_string(tmpl->to);
                quote_fmt_parse();
@@ -7380,10 +7701,10 @@ static void compose_template_apply_fields(Compose *compose, Template *tmpl)
 
        if (tmpl->cc && *tmpl->cc != '\0') {
 #ifdef USE_ASPELL
-               quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account,
+               quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account, FALSE,
                                compose->gtkaspell);
 #else
-               quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account);
+               quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account, FALSE);
 #endif
                quote_fmt_scan_string(tmpl->cc);
                quote_fmt_parse();
@@ -7398,10 +7719,10 @@ static void compose_template_apply_fields(Compose *compose, Template *tmpl)
 
        if (tmpl->bcc && *tmpl->bcc != '\0') {
 #ifdef USE_ASPELL
-               quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account,
+               quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account, FALSE,
                                compose->gtkaspell);
 #else
-               quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account);
+               quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account, FALSE);
 #endif
                quote_fmt_scan_string(tmpl->bcc);
                quote_fmt_parse();
@@ -7417,10 +7738,10 @@ static void compose_template_apply_fields(Compose *compose, Template *tmpl)
        /* process the subject */
        if (tmpl->subject && *tmpl->subject != '\0') {
 #ifdef USE_ASPELL
-               quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account,
+               quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account, FALSE,
                                compose->gtkaspell);
 #else
-               quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account);
+               quote_fmt_init(msginfo, NULL, NULL, FALSE, compose->account, FALSE);
 #endif
                quote_fmt_scan_string(tmpl->subject);
                quote_fmt_parse();
@@ -7524,6 +7845,30 @@ static void compose_attach_info_free(AttachInfo *ainfo)
        g_free(ainfo);
 }
 
+static void compose_attach_update_label(Compose *compose)
+{
+       GtkTreeIter iter;
+       gint i = 1;
+       gchar *text;
+       GtkTreeModel *model;
+       
+       if(compose == NULL)
+               return;
+               
+       model = gtk_tree_view_get_model(GTK_TREE_VIEW(compose->attach_clist));
+       if(!gtk_tree_model_get_iter_first(model, &iter)) {
+               gtk_label_set_text(GTK_LABEL(compose->attach_label), "");       
+               return;
+       }
+       
+       while(gtk_tree_model_iter_next(model, &iter))
+               i++;
+       
+       text = g_strdup_printf("(%d)", i);
+       gtk_label_set_text(GTK_LABEL(compose->attach_label), text);
+       g_free(text);
+}
+
 static void compose_attach_remove_selected(Compose *compose)
 {
        GtkTreeView *tree_view = GTK_TREE_VIEW(compose->attach_clist);
@@ -7558,6 +7903,7 @@ static void compose_attach_remove_selected(Compose *compose)
        }
 
        g_list_free(sel);
+       compose_attach_update_label(compose);
 }
 
 static struct _AttachProperty
@@ -7761,7 +8107,7 @@ static void compose_attach_property_create(gboolean *cancelled)
        gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, (0 + 1), 
                         GTK_FILL, 0, 0, 0); 
        gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); 
-       mimetype_entry = gtk_combo_new(); 
+       mimetype_entry = gtk_combo_box_entry_new_text(); 
        gtk_table_attach(GTK_TABLE(table), mimetype_entry, 1, 2, 0, (0 + 1), 
                         GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
                         
@@ -7781,14 +8127,14 @@ static void compose_attach_property_create(gboolean *cancelled)
                                        (GCompareFunc)strcmp2);
        }
 
-       gtk_combo_set_popdown_strings(GTK_COMBO(mimetype_entry), strlist);
-
        for (mime_type_list = strlist; mime_type_list != NULL; 
-               mime_type_list = mime_type_list->next)
+               mime_type_list = mime_type_list->next) {
+               gtk_combo_box_append_text(GTK_COMBO_BOX(mimetype_entry), mime_type_list->data);
                g_free(mime_type_list->data);
+       }
        g_list_free(strlist);
-                        
-       mimetype_entry = GTK_COMBO(mimetype_entry)->entry;                       
+       gtk_combo_box_set_active(GTK_COMBO_BOX(mimetype_entry), 0);              
+       mimetype_entry = GTK_BIN(mimetype_entry)->child;                         
 
        label = gtk_label_new(_("Encoding"));
        gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2,
@@ -7962,14 +8308,14 @@ static gint compose_exec_ext_editor_real(const gchar *file)
        if (setpgid(0, getppid()))
                perror("setpgid");
 
-       if (prefs_common.ext_editor_cmd &&
-           (p = strchr(prefs_common.ext_editor_cmd, '%')) &&
+       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.ext_editor_cmd, file);
+               g_snprintf(buf, sizeof(buf), prefs_common_get_ext_editor_cmd(), file);
        } else {
-               if (prefs_common.ext_editor_cmd)
+               if (prefs_common_get_ext_editor_cmd())
                        g_warning("External editor command line is invalid: '%s'\n",
-                                 prefs_common.ext_editor_cmd);
+                                 prefs_common_get_ext_editor_cmd());
                g_snprintf(buf, sizeof(buf), DEFAULT_EDITOR_CMD, file);
        }
 
@@ -8053,11 +8399,11 @@ static gboolean compose_input_cb(GIOChannel *source, GIOCondition condition,
                compose_insert_file(compose, compose->exteditor_file);
                compose_changed_cb(NULL, compose);
 
-               if (g_unlink(compose->exteditor_file) < 0)
+               if (claws_unlink(compose->exteditor_file) < 0)
                        FILE_OP_ERROR(compose->exteditor_file, "unlink");
        } else if (buf[0] == '1') {     /* failed */
                g_warning("Couldn't exec external editor\n");
-               if (g_unlink(compose->exteditor_file) < 0)
+               if (claws_unlink(compose->exteditor_file) < 0)
                        FILE_OP_ERROR(compose->exteditor_file, "unlink");
        } else if (buf[0] == '2') {
                g_warning("Couldn't write to file\n");
@@ -8388,7 +8734,8 @@ gboolean compose_draft (gpointer data, guint action)
        MsgInfo *newmsginfo;
        FILE *fp;
        gboolean target_locked = FALSE;
-       
+       gboolean err = FALSE;
+
        if (lock) return FALSE;
 
        if (compose->sending)
@@ -8412,7 +8759,7 @@ gboolean compose_draft (gpointer data, guint action)
                              G_DIR_SEPARATOR, compose);
        if ((fp = g_fopen(tmp, "wb")) == NULL) {
                FILE_OP_ERROR(tmp, "fopen");
-               goto unlock;
+               goto warn_err;
        }
 
        /* chmod for security */
@@ -8422,23 +8769,23 @@ gboolean compose_draft (gpointer data, guint action)
        }
 
        /* Save draft infos */
-       fprintf(fp, "X-Claws-Account-Id:%d\n", compose->account->account_id);
-       fprintf(fp, "S:%s\n", compose->account->address);
+       err |= (fprintf(fp, "X-Claws-Account-Id:%d\n", compose->account->account_id) < 0);
+       err |= (fprintf(fp, "S:%s\n", compose->account->address) < 0);
 
        if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn))) {
                gchar *savefolderid;
 
                savefolderid = gtk_editable_get_chars(GTK_EDITABLE(compose->savemsg_entry), 0, -1);
-               fprintf(fp, "SCF:%s\n", savefolderid);
+               err |= (fprintf(fp, "SCF:%s\n", savefolderid) < 0);
                g_free(savefolderid);
        }
        if (compose->return_receipt) {
-               fprintf(fp, "RRCPT:1\n");
+               err |= (fprintf(fp, "RRCPT:1\n") < 0);
        }
        if (compose->privacy_system) {
-               fprintf(fp, "X-Claws-Sign:%d\n", compose->use_signing);
-               fprintf(fp, "X-Claws-Encrypt:%d\n", compose->use_encryption);
-               fprintf(fp, "X-Claws-Privacy-System:%s\n", compose->privacy_system);
+               err |= (fprintf(fp, "X-Claws-Sign:%d\n", compose->use_signing) < 0);
+               err |= (fprintf(fp, "X-Claws-Encrypt:%d\n", compose->use_encryption) < 0);
+               err |= (fprintf(fp, "X-Claws-Privacy-System:%s\n", compose->privacy_system) < 0);
        }
 
        /* Message-ID of message replying to */
@@ -8446,7 +8793,7 @@ gboolean compose_draft (gpointer data, guint action)
                gchar *folderid;
                
                folderid = folder_item_get_identifier(compose->replyinfo->folder);
-               fprintf(fp, "RMID:%s\t%d\t%s\n", folderid, compose->replyinfo->msgnum, compose->replyinfo->msgid);
+               err |= (fprintf(fp, "RMID:%s\t%d\t%s\n", folderid, compose->replyinfo->msgnum, compose->replyinfo->msgid) < 0);
                g_free(folderid);
        }
        /* Message-ID of message forwarding to */
@@ -8454,20 +8801,25 @@ gboolean compose_draft (gpointer data, guint action)
                gchar *folderid;
                
                folderid = folder_item_get_identifier(compose->fwdinfo->folder);
-               fprintf(fp, "FMID:%s\t%d\t%s\n", folderid, compose->fwdinfo->msgnum, compose->fwdinfo->msgid);
+               err |= (fprintf(fp, "FMID:%s\t%d\t%s\n", folderid, compose->fwdinfo->msgnum, compose->fwdinfo->msgid) < 0);
                g_free(folderid);
        }
 
        /* end of headers */
-       fprintf(fp, "X-Claws-End-Special-Headers: 1\n");
+       err |= (fprintf(fp, "X-Claws-End-Special-Headers: 1\n") < 0);
+
+       if (err) {
+               fclose(fp);
+               goto warn_err;
+       }
 
        if (compose_write_to_file(compose, fp, COMPOSE_WRITE_FOR_STORE, action != COMPOSE_AUTO_SAVE) < 0) {
                fclose(fp);
-               g_unlink(tmp);
-               g_free(tmp);
-               goto unlock;
+               goto warn_err;
+       }
+       if (fclose(fp) == EOF) {
+               goto warn_err;
        }
-       fclose(fp);
        
        if (compose->targetinfo) {
                target_locked = MSG_IS_LOCKED(compose->targetinfo->flags);
@@ -8493,7 +8845,8 @@ gboolean compose_draft (gpointer data, guint action)
                debug_print("got draft msgnum %d from adding\n", msgnum);
        }
        if (msgnum < 0) {
-               g_unlink(tmp);
+warn_err:
+               claws_unlink(tmp);
                g_free(tmp);
                if (action != COMPOSE_AUTO_SAVE) {
                        if (action != COMPOSE_DRAFT_FOR_EXIT)
@@ -8594,7 +8947,7 @@ void compose_clear_exit_drafts(void)
        gchar *filepath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
                                      DRAFTED_AT_EXIT, NULL);
        if (is_file_exist(filepath))
-               g_unlink(filepath);
+               claws_unlink(filepath);
        
        g_free(filepath);
 }
@@ -8631,17 +8984,9 @@ static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
        compose_draft(data, action);
 }
 
-static void compose_attach_cb(gpointer data, guint action, GtkWidget *widget)
+static void compose_attach_from_list(Compose *compose, GList *file_list, gboolean free_data)
 {
-       Compose *compose = (Compose *)data;
-       GList *file_list;
-
-       if (compose->redirect_filename != NULL)
-               return;
-
-       file_list = filesel_select_multiple_files_open(_("Select file"));
-
-       if (file_list) {
+       if (compose && file_list) {
                GList *tmp;
 
                for ( tmp = file_list; tmp; tmp = tmp->next) {
@@ -8649,11 +8994,29 @@ static void compose_attach_cb(gpointer data, guint action, GtkWidget *widget)
                        gchar *utf8_filename = conv_filename_to_utf8(file);
                        compose_attach_append(compose, file, utf8_filename, NULL);
                        compose_changed_cb(NULL, compose);
+                       if (free_data) {
                        g_free(file);
+                               tmp->data = NULL;
+                       }
                        g_free(utf8_filename);
                }
+       }
+}
+
+static void compose_attach_cb(gpointer data, guint action, GtkWidget *widget)
+{
+       Compose *compose = (Compose *)data;
+       GList *file_list;
+
+       if (compose->redirect_filename != NULL)
+               return;
+
+       file_list = filesel_select_multiple_files_open(_("Select file"));
+
+       if (file_list) {
+               compose_attach_from_list(compose, file_list, TRUE);
                g_list_free(file_list);
-       }               
+       }
 }
 
 static void compose_insert_file_cb(gpointer data, guint action,
@@ -8730,10 +9093,18 @@ static void compose_close_cb(gpointer data, guint action, GtkWidget *widget)
 #endif
 
        if (compose->modified) {
+               if (!g_mutex_trylock(compose->mutex)) {
+                       /* we don't want to lock the mutex once it's available,
+                        * because as the only other part of compose.c locking
+                        * it is compose_close - which means once unlocked,
+                        * the compose struct will be freed */
+                       debug_print("couldn't lock mutex, probably sending\n");
+                       return;
+               }
                val = alertpanel(_("Discard message"),
                                 _("This message has been modified. Discard it?"),
                                 _("_Discard"), _("_Save to Drafts"), GTK_STOCK_CANCEL);
-
+               g_mutex_unlock(compose->mutex);
                switch (val) {
                case G_ALERTDEFAULT:
                        if (prefs_common.autosave)
@@ -8884,7 +9255,8 @@ static void entry_paste_clipboard(Compose *compose, GtkWidget *entry,
                }
        } else if (GTK_IS_EDITABLE(entry))
                gtk_editable_paste_clipboard (GTK_EDITABLE(entry));
-       
+
+       compose->modified = TRUE;
 }
 
 static void entry_allsel(GtkWidget *entry)
@@ -9212,7 +9584,6 @@ static void textview_delete_line (GtkTextView *text)
        GtkTextBuffer *buffer;
        GtkTextMark *mark;
        GtkTextIter ins, start_iter, end_iter;
-       gboolean found;
 
        g_return_if_fail(GTK_IS_TEXT_VIEW(text));
 
@@ -9224,13 +9595,13 @@ static void textview_delete_line (GtkTextView *text)
        gtk_text_iter_set_line_offset(&start_iter, 0);
 
        end_iter = ins;
-       if (gtk_text_iter_ends_line(&end_iter))
-               found = gtk_text_iter_forward_char(&end_iter);
-       else
-               found = gtk_text_iter_forward_to_line_end(&end_iter);
-
-       if (found)
-               gtk_text_buffer_delete(buffer, &start_iter, &end_iter);
+       if (gtk_text_iter_ends_line(&end_iter)){
+               if (!gtk_text_iter_forward_char(&end_iter))
+                       gtk_text_iter_backward_char(&start_iter);
+       }
+       else 
+               gtk_text_iter_forward_to_line_end(&end_iter);
+       gtk_text_buffer_delete(buffer, &start_iter, &end_iter);
 }
 
 static void textview_delete_to_line_end (GtkTextView *text)
@@ -9238,7 +9609,6 @@ static void textview_delete_to_line_end (GtkTextView *text)
        GtkTextBuffer *buffer;
        GtkTextMark *mark;
        GtkTextIter ins, end_iter;
-       gboolean found;
 
        g_return_if_fail(GTK_IS_TEXT_VIEW(text));
 
@@ -9247,11 +9617,10 @@ static void textview_delete_to_line_end (GtkTextView *text)
        gtk_text_buffer_get_iter_at_mark(buffer, &ins, mark);
        end_iter = ins;
        if (gtk_text_iter_ends_line(&end_iter))
-               found = gtk_text_iter_forward_char(&end_iter);
+               gtk_text_iter_forward_char(&end_iter);
        else
-               found = gtk_text_iter_forward_to_line_end(&end_iter);
-       if (found)
-               gtk_text_buffer_delete(buffer, &ins, &end_iter);
+               gtk_text_iter_forward_to_line_end(&end_iter);
+       gtk_text_buffer_delete(buffer, &ins, &end_iter);
 }
 
 static void compose_advanced_action_cb(Compose *compose,
@@ -9274,7 +9643,6 @@ static void compose_advanced_action_cb(Compose *compose,
                {textview_delete_forward_word},
                {textview_delete_backward_word},
                {textview_delete_line},
-               {NULL}, /* gtk_stext_delete_line_n */
                {textview_delete_to_line_end}
        };
 
@@ -9526,6 +9894,21 @@ static void compose_insert_drag_received_cb (GtkWidget           *widget,
        if (gdk_atom_name(data->type) && !strcmp(gdk_atom_name(data->type), "text/uri-list")) {
                AlertValue val = G_ALERTDEFAULT;
 
+               list = uri_list_extract_filenames((const gchar *)data->data);
+
+               if (list == NULL && strstr((gchar *)(data->data), "://")) {
+                       /* Assume a list of no files, and data has ://, is a remote link */
+                       gchar *tmpdata = g_strstrip(g_strdup((const gchar *)data->data));
+                       gchar *tmpfile = get_tmp_file();
+                       str_write_to_file(tmpdata, tmpfile);
+                       g_free(tmpdata);  
+                       compose_insert_file(compose, tmpfile);
+                       claws_unlink(tmpfile);
+                       g_free(tmpfile);
+                       gtk_drag_finish(drag_context, TRUE, FALSE, time);
+                       compose_beautify_paragraph(compose, NULL, TRUE);
+                       return;
+               }
                switch (prefs_common.compose_dnd_mode) {
                        case COMPOSE_DND_ASK:
                                val = alertpanel_full(_("Insert or attach?"),
@@ -9556,12 +9939,16 @@ static void compose_insert_drag_received_cb (GtkWidget          *widget,
 
                if (val == G_ALERTDEFAULT || val == G_ALERTCANCEL) {
                        gtk_drag_finish(drag_context, FALSE, FALSE, time);
+                       list_free_strings(list);
+                       g_list_free(list);
                        return;
                } else if (val == G_ALERTOTHER) {
                        compose_attach_drag_received_cb(widget, drag_context, x, y, data, info, time, user_data);
+                       list_free_strings(list);
+                       g_list_free(list);
                        return;
                } 
-               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);
                }
@@ -9576,7 +9963,7 @@ static void compose_insert_drag_received_cb (GtkWidget            *widget,
                gchar *tmpfile = get_tmp_file();
                str_write_to_file((const gchar *)data->data, tmpfile);
                compose_insert_file(compose, tmpfile);
-               g_unlink(tmpfile);
+               claws_unlink(tmpfile);
                g_free(tmpfile);
                gtk_drag_finish(drag_context, TRUE, FALSE, time);
 #endif
@@ -9695,6 +10082,7 @@ static void compose_show_first_last_header(Compose *compose, gboolean show_first
 
        vadj = gtk_viewport_get_vadjustment(GTK_VIEWPORT(compose->header_table->parent));
        gtk_adjustment_set_value(vadj, (show_first ? vadj->lower : vadj->upper));
+       gtk_adjustment_changed(vadj);
 }
 
 static void text_inserted(GtkTextBuffer *buffer, GtkTextIter *iter,
@@ -9712,6 +10100,8 @@ static void text_inserted(GtkTextBuffer *buffer, GtkTextIter *iter,
        if (paste_as_quotation) {
                gchar *new_text;
                const gchar *qmark;
+               guint pos = 0;
+               GtkTextIter start_iter;
 
                if (len < 0)
                        len = strlen(text);
@@ -9723,6 +10113,8 @@ static void text_inserted(GtkTextBuffer *buffer, GtkTextIter *iter,
                mark = gtk_text_buffer_create_mark(buffer, NULL, iter, FALSE);
                gtk_text_buffer_place_cursor(buffer, iter);
 
+               pos = gtk_text_iter_get_offset(iter);
+
                compose_quote_fmt(compose, NULL, "%Q", qmark, new_text, TRUE, FALSE,
                                                  _("Quote format error at line %d."));
                quote_fmt_reset_vartable();
@@ -9732,23 +10124,51 @@ static void text_inserted(GtkTextBuffer *buffer, GtkTextIter *iter,
                                  
                gtk_text_buffer_get_iter_at_mark(buffer, iter, mark);
                gtk_text_buffer_place_cursor(buffer, iter);
+               gtk_text_buffer_delete_mark(buffer, mark);
+
+               gtk_text_buffer_get_iter_at_offset(buffer, &start_iter, pos);
+               mark = gtk_text_buffer_create_mark(buffer, NULL, &start_iter, FALSE);
+               compose_beautify_paragraph(compose, &start_iter, FALSE);
+               gtk_text_buffer_get_iter_at_mark(buffer, &start_iter, mark);
+               gtk_text_buffer_delete_mark(buffer, mark);
        } else {
                if (strcmp(text, "\n") || compose->automatic_break
                || gtk_text_iter_starts_line(iter))
                        gtk_text_buffer_insert(buffer, iter, text, len);
                else {
-                       debug_print("insert nowrap \\n\n");
-                       gtk_text_buffer_insert_with_tags_by_name(buffer, 
-                               iter, text, len, "no_join", NULL);
+                       /* check if the preceding is just whitespace or quote */
+                       GtkTextIter start_line;
+                       gchar *tmp = NULL, *quote = NULL;
+                       gint quote_len = 0, is_normal = 0;
+                       start_line = *iter;
+                       gtk_text_iter_set_line_offset(&start_line, 0); 
+                       tmp = gtk_text_buffer_get_text(buffer, &start_line, iter, FALSE);
+                       g_strstrip(tmp);
+                       if (*tmp == '\0') {
+                               is_normal = 1;
+                       } else {
+                               quote = compose_get_quote_str(buffer, &start_line, &quote_len);
+                               if (quote)
+                                       is_normal = 1;
+                               g_free(quote);
+                       }
+                       g_free(tmp);
+                       
+                       if (is_normal) {
+                               gtk_text_buffer_insert(buffer, iter, text, len);
+                       } else {
+                               gtk_text_buffer_insert_with_tags_by_name(buffer, 
+                                       iter, text, len, "no_join", NULL);
+                       }
                }
        }
        
-       mark = gtk_text_buffer_create_mark(buffer, NULL, iter, FALSE);
-       
-       compose_beautify_paragraph(compose, iter, FALSE);
-
-       gtk_text_buffer_get_iter_at_mark(buffer, iter, mark);
-       gtk_text_buffer_delete_mark(buffer, mark);
+       if (!paste_as_quotation) {
+               mark = gtk_text_buffer_create_mark(buffer, NULL, iter, FALSE);
+               compose_beautify_paragraph(compose, iter, FALSE);
+               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),
@@ -9828,7 +10248,7 @@ static PrefsAccount *compose_guess_forward_account_from_msginfo(MsgInfo *msginfo
                gchar *to;
                Xstrdup_a(to, msginfo->to, return NULL);
                extract_address(to);
-               account = account_find_from_address(to);
+               account = account_find_from_address(to, FALSE);
        }
 
        if (!account && prefs_common.forward_account_autosel) {
@@ -9837,7 +10257,7 @@ static PrefsAccount *compose_guess_forward_account_from_msginfo(MsgInfo *msginfo
                        (msginfo, cc,sizeof cc , "Cc:")) { 
                        gchar *buf = cc + strlen("Cc:");
                        extract_address(buf);
-                       account = account_find_from_address(buf);
+                       account = account_find_from_address(buf, FALSE);
                 }
        }
        
@@ -9847,7 +10267,7 @@ static PrefsAccount *compose_guess_forward_account_from_msginfo(MsgInfo *msginfo
                        (msginfo, deliveredto,sizeof deliveredto , "Delivered-To:")) { 
                        gchar *buf = deliveredto + strlen("Delivered-To:");
                        extract_address(buf);
-                       account = account_find_from_address(buf);
+                       account = account_find_from_address(buf, FALSE);
                 }
        }
        
@@ -9935,7 +10355,7 @@ static void compose_reply_from_messageview_real(MessageView *msgview, GSList *ms
        } else
                compose = compose_reply_mode((ComposeMode)action, msginfo_list, body);
 
-       if (originally_enc) {
+       if (compose && originally_enc) {
                compose_force_encryption(compose, compose->account, FALSE);
        }
 
@@ -10029,7 +10449,7 @@ static MsgInfo *compose_msginfo_new_from_compose(Compose *compose)
        for (list = compose->header_list; list; list = list->next) {
                gchar *header = gtk_editable_get_chars(
                                                                GTK_EDITABLE(
-                                                               GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
+                                                               GTK_BIN(((ComposeHeaderEntry *)list->data)->combo)->child), 0, -1);
                gchar *entry = gtk_editable_get_chars(
                                                                GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);