2008-04-30 [colin] 3.4.0cvs18
[claws.git] / src / compose.c
index e0909325b6ce9e93e7c0d5337afef9c0ab60a721..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,
@@ -548,6 +548,8 @@ static void compose_set_dictionaries_from_folder_prefs(Compose *compose,
 #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[] =
 {
        {N_("/_Add..."),        NULL, compose_attach_cb, 0, NULL},
@@ -654,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,
@@ -1001,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;
@@ -1031,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);
@@ -1041,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);
                }
@@ -1066,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' )
@@ -1075,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);
@@ -1083,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();
@@ -1096,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);
@@ -1110,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);
@@ -1123,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;
@@ -1191,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);
        }
@@ -1465,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);
@@ -1504,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();
        }
 
@@ -1590,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);
@@ -1639,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);
 
@@ -1727,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);
@@ -1920,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:")) {
@@ -1987,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) {
@@ -2369,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);
@@ -2421,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)
@@ -2520,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;
@@ -2654,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();
@@ -2676,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;
@@ -2865,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 :
@@ -2875,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,
@@ -3729,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) &&
@@ -3744,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);
@@ -4147,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);
@@ -4397,8 +4601,8 @@ gboolean compose_check_for_valid_recipient(Compose *compose) {
                gchar *entry;
                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))) {
@@ -4431,6 +4635,7 @@ static gboolean compose_check_for_set_recipients(Compose *compose)
                        entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->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;
@@ -4462,6 +4667,7 @@ static gboolean compose_check_for_set_recipients(Compose *compose)
                        entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->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;
@@ -4514,8 +4720,9 @@ static gboolean compose_check_entries(Compose *compose, gboolean check_everythin
                                button_label = _("+_Send");
                        else
                                button_label = _("+_Queue");
-                       message = g_strdup_printf(_("Subject is empty. %s it anyway?"),
-                                       compose->sending?_("Send"):_("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);
@@ -4584,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);
@@ -4610,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) {
@@ -4817,9 +5024,14 @@ static gint compose_redirect_write_headers(Compose *compose, FILE *fp)
        } else {
                g_snprintf(buf, sizeof(buf), "%s", "");
        }
-       generate_msgid(buf, sizeof(buf));
-       err |= (fprintf(fp, "Resent-Message-ID: <%s>\n", buf) < 0);
-       compose->msgid = g_strdup(buf);
+
+       if (compose->account->gen_msgid) {
+               generate_msgid(buf, sizeof(buf));
+               err |= (fprintf(fp, "Resent-Message-ID: <%s>\n", buf) < 0);
+               compose->msgid = g_strdup(buf);
+       } else {
+               compose->msgid = NULL;
+       }
 
        if (compose_redirect_write_headers_from_headerlist(compose, fp))
                return -1;
@@ -5161,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;
        }
 
@@ -5169,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;
@@ -5372,7 +5584,7 @@ static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
                        if (!compose_warn_encryption(compose)) {
                                lock = FALSE;
                                fclose(fp);
-                               g_unlink(tmp);
+                               claws_unlink(tmp);
                                g_free(tmp);
                                return -6;
                        }
@@ -5396,7 +5608,7 @@ static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
                                 * key selection */
                                lock = FALSE;
                                fclose(fp);
-                               g_unlink(tmp);
+                               claws_unlink(tmp);
                                g_free(tmp);
                                return -5;
                        }
@@ -5440,7 +5652,7 @@ static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
                if (compose_redirect_write_to_file(compose, fp) < 0) {
                        lock = FALSE;
                        fclose(fp);
-                       g_unlink(tmp);
+                       claws_unlink(tmp);
                        g_free(tmp);
                        return -2;
                }
@@ -5449,7 +5661,7 @@ 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 */
                }
@@ -5457,14 +5669,14 @@ static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
        if (err == TRUE) {
                g_warning("failed to write queue message\n");
                fclose(fp);
-               g_unlink(tmp);
+               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;
@@ -5477,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;
@@ -5485,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;
@@ -5740,9 +5952,14 @@ static gchar *compose_get_header(Compose *compose)
        } else {
                g_snprintf(buf, sizeof(buf), "%s", "");
        }
-       generate_msgid(buf, sizeof(buf));
-       g_string_append_printf(header, "Message-ID: <%s>\n", buf);
-       compose->msgid = g_strdup(buf);
+       
+       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) {
                /* In-Reply-To */
@@ -5849,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_BIN(headerentry->combo)->child)));
-               if (strchr(tmp, ' ') != NULL || strchr(tmp, '\r') != NULL || strchr(tmp, '\n') != NULL) {
+               g_strstrip(tmp);
+               if (*tmp == '\0' || strchr(tmp, ' ') != NULL || strchr(tmp, '\r') != NULL || strchr(tmp, '\n') != NULL) {
                        g_free(tmp);
                        continue;
                }
@@ -6328,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);
@@ -6345,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;
@@ -6354,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 */
@@ -6444,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);
 }
@@ -7108,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);
 
@@ -7419,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);
 }
@@ -7438,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();
@@ -7458,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();
@@ -7476,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();
@@ -7495,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();
@@ -8065,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);
        }
 
@@ -8156,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");
@@ -8603,7 +8846,7 @@ gboolean compose_draft (gpointer data, guint action)
        }
        if (msgnum < 0) {
 warn_err:
-               g_unlink(tmp);
+               claws_unlink(tmp);
                g_free(tmp);
                if (action != COMPOSE_AUTO_SAVE) {
                        if (action != COMPOSE_DRAFT_FOR_EXIT)
@@ -8704,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);
 }
@@ -8741,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) {
@@ -8759,9 +8994,27 @@ 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);
        }
 }
@@ -8840,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)
@@ -8994,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)
@@ -9322,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));
 
@@ -9334,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)
@@ -9348,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));
 
@@ -9357,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,
@@ -9384,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}
        };
 
@@ -9636,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?"),
@@ -9666,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);
                }
@@ -9686,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
@@ -9859,9 +10136,30 @@ static void text_inserted(GtkTextBuffer *buffer, GtkTextIter *iter,
                || 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);
+                       }
                }
        }
        
@@ -9950,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) {
@@ -9959,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);
                 }
        }
        
@@ -9969,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);
                 }
        }