2008-02-15 [colin] 3.3.0cvs13
[claws.git] / src / compose.c
index 6e89e971780d72b8e5ba3f11fe745777eae93c53..7bdfa49e43f7db6de303fd011e89f3037870663d 100644 (file)
@@ -235,7 +235,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,
@@ -1003,15 +1004,37 @@ Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderI
        GtkItemFactory *ifactory;
        const gchar *subject_format = NULL;
        const gchar *body_format = NULL;
-
-       if (item && item->prefs && item->prefs->enable_default_account)
+       gchar *mailto_from = NULL;
+       PrefsAccount *mailto_account = NULL;
+
+       /* 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);
+       }
+
        ifactory = gtk_item_factory_from_widget(compose->menubar);
 
        compose->replyinfo = NULL;
@@ -1033,7 +1056,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);
@@ -1043,8 +1066,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);
                }
@@ -1085,10 +1111,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();
@@ -1195,6 +1221,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);
        }
@@ -1469,7 +1499,11 @@ 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;
+       }
 
        textview = (GTK_TEXT_VIEW(compose->text));
        textbuf = gtk_text_view_get_buffer(textview);
@@ -1926,7 +1960,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:")) {
@@ -1993,7 +2027,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) {
@@ -2375,7 +2409,7 @@ 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;
@@ -2385,11 +2419,12 @@ static void compose_entries_set(Compose *compose, const gchar *mailto)
        gchar *temp = NULL;
        gsize  len = 0;
        gchar **attach = NULL;
-       
-       scan_mailto_url(mailto, &to, &cc, &bcc, &subject, &body, &attach);
+
+       /* 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)
@@ -2546,7 +2581,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;
@@ -2680,10 +2715,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();
@@ -2702,10 +2737,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;
@@ -2891,7 +2926,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 :
@@ -2901,9 +2936,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,
@@ -3755,9 +3796,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) &&
@@ -3770,18 +3811,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);
@@ -4173,7 +4216,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);
@@ -4423,8 +4466,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))) {
@@ -4457,6 +4500,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;
@@ -4488,6 +4532,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;
@@ -5886,9 +5931,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;
                }
@@ -6365,7 +6411,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);
@@ -6382,7 +6428,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;
@@ -6391,21 +6437,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 */
@@ -6481,6 +6532,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);
 }
@@ -7145,7 +7198,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);
 
@@ -7478,10 +7530,10 @@ static void compose_template_apply_fields(Compose *compose, Template *tmpl)
 
        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();
@@ -7496,10 +7548,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();
@@ -7514,10 +7566,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();
@@ -7533,10 +7585,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();
@@ -8103,14 +8155,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);
        }
 
@@ -9684,6 +9736,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);
+                       g_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?"),
@@ -9714,12 +9781,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);
                }
@@ -9907,9 +9978,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);
+                       }
                }
        }
        
@@ -9998,7 +10090,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) {
@@ -10007,7 +10099,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);
                 }
        }
        
@@ -10017,7 +10109,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);
                 }
        }