2005-03-04 [colin] 1.0.1cvs22.2
[claws.git] / src / compose.c
index fde2a2bf702b889be2d876256c78713463d9ae63..674b2f239817181b0f90fdf33be4e556b63e62fa 100644 (file)
 
 #include "defs.h"
 
+#ifndef PANGO_ENABLE_ENGINE
+#  define PANGO_ENABLE_ENGINE
+#endif
+
 #include <glib.h>
 #include <glib/gi18n.h>
 #include <gdk/gdkkeysyms.h>
@@ -53,6 +57,7 @@
 
 #include <gtk/gtkdnd.h>
 #include <gtk/gtkclipboard.h>
+#include <pango/pango-break.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -220,21 +225,26 @@ static void compose_reply_set_entry               (Compose        *compose,
                                                 followup_and_reply_to);
 static void compose_reedit_set_entry           (Compose        *compose,
                                                 MsgInfo        *msginfo);
+
 static void compose_insert_sig                 (Compose        *compose,
                                                 gboolean        replace);
 static gchar *compose_get_signature_str                (Compose        *compose);
 static ComposeInsertResult compose_insert_file (Compose        *compose,
                                                 const gchar    *file);
+
 static void compose_attach_append              (Compose        *compose,
                                                 const gchar    *file,
                                                 const gchar    *type,
                                                 const gchar    *content_type);
 static void compose_attach_parts               (Compose        *compose,
                                                 MsgInfo        *msginfo);
-static void compose_wrap_line                  (Compose        *compose);
-static void compose_wrap_line_all              (Compose        *compose);
-static void compose_wrap_line_all_full         (Compose        *compose,
+
+static void compose_wrap_paragraph             (Compose        *compose,
+                                                GtkTextIter    *par_iter);
+static void compose_wrap_all                   (Compose        *compose);
+static void compose_wrap_all_full              (Compose        *compose,
                                                 gboolean        autowrap);
+
 static void compose_set_title                  (Compose        *compose);
 static void compose_select_account             (Compose        *compose,
                                                 PrefsAccount   *account,
@@ -385,6 +395,9 @@ static void compose_grab_focus_before_cb(GtkWidget  *widget,
 static void compose_changed_cb         (GtkTextBuffer  *textbuf,
                                         Compose        *compose);
 
+static void compose_wrap_cb            (gpointer        data,
+                                        guint           action,
+                                        GtkWidget      *widget);
 static void compose_toggle_autowrap_cb (gpointer        data,
                                         guint           action,
                                         GtkWidget      *widget);
@@ -625,9 +638,9 @@ static GtkItemFactoryEntry compose_entries[] =
                                        NULL},
        {N_("/_Edit/---"),              NULL, NULL, 0, "<Separator>"},
        {N_("/_Edit/_Wrap current paragraph"),
-                                       "<control>L", compose_wrap_line, 0, NULL},
+                                       "<control>L", compose_wrap_cb, 0, NULL},
        {N_("/_Edit/Wrap all long _lines"),
-                                       "<control><alt>L", compose_wrap_line_all, 0, NULL},
+                                       "<control><alt>L", compose_wrap_cb, 1, NULL},
        {N_("/_Edit/Aut_o wrapping"),   "<shift><control>L", compose_toggle_autowrap_cb, 0, "<ToggleItem>"},
        {N_("/_Edit/---"),              NULL, NULL, 0, "<Separator>"},
        {N_("/_Edit/Edit with e_xternal editor"),
@@ -1031,7 +1044,7 @@ static void compose_generic_reply(MsgInfo *msginfo, gboolean quote,
        gtk_text_buffer_place_cursor(textbuf, &iter);
        
        if (quote && prefs_common.linewrap_quote)
-               compose_wrap_line_all(compose);
+               compose_wrap_all(compose);
 
        gtk_widget_grab_focus(compose->text);
 
@@ -1125,7 +1138,7 @@ Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
                compose_insert_sig(compose, FALSE);
 
        if (prefs_common.linewrap_quote)
-               compose_wrap_line_all(compose);
+               compose_wrap_all(compose);
 
        gtk_text_buffer_get_start_iter(textbuf, &iter);
        gtk_text_buffer_place_cursor(textbuf, &iter);
@@ -1203,7 +1216,7 @@ Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_list)
                compose_insert_sig(compose, FALSE);
 
        if (prefs_common.linewrap_quote)
-               compose_wrap_line_all(compose);
+               compose_wrap_all(compose);
 
        gtk_text_buffer_get_start_iter(textbuf, &iter);
        gtk_text_buffer_place_cursor(textbuf, &iter);
@@ -1553,10 +1566,10 @@ void compose_toolbar_cb(gint action, gpointer data)
                compose_ext_editor_cb(compose, 0, NULL);
                break;
        case A_LINEWRAP_CURRENT:
-               compose_wrap_line(compose);
+               compose_wrap_paragraph(compose, NULL);
                break;
        case A_LINEWRAP_ALL:
-               compose_wrap_line_all(compose);
+               compose_wrap_all(compose);
                break;
        case A_ADDRBOOK:
                compose_address_cb(compose, 0, NULL);
@@ -2096,8 +2109,8 @@ static void compose_insert_sig(Compose *compose, gboolean replace)
        if (cur_pos > gtk_text_buffer_get_char_count (buffer))
                cur_pos = gtk_text_buffer_get_char_count (buffer);
 
-       gtk_text_buffer_get_iter_at_offset (buffer, &iter, cur_pos);
-       gtk_text_buffer_place_cursor (buffer, &iter);
+       gtk_text_buffer_get_iter_at_offset(buffer, &iter, cur_pos);
+       gtk_text_buffer_place_cursor(buffer, &iter);
 
        g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
                                        G_CALLBACK(compose_changed_cb),
@@ -2109,6 +2122,7 @@ static gchar *compose_get_signature_str(Compose *compose)
 {
        gchar *sig_body = NULL;
        gchar *sig_str = NULL;
+       gchar *utf8_sig_str = NULL;
 
        g_return_val_if_fail(compose->account != NULL, NULL);
 
@@ -2135,15 +2149,23 @@ static gchar *compose_get_signature_str(Compose *compose)
                g_free(tmp);
        }
 
-       if (compose->account->sig_sep)
+       if (compose->account->sig_sep) {
                sig_str = g_strconcat("\n\n", compose->account->sig_sep, "\n", sig_body,
                                      NULL);
-       else
+               g_free(sig_body);
+       } else
                sig_str = g_strconcat("\n\n", sig_body, NULL);
 
-       g_free(sig_body);
-       
-       return sig_str;
+       if (sig_str) {
+               if (!g_utf8_validate(sig_str,1, NULL)) {
+                       utf8_sig_str = conv_codeset_strdup
+                               (sig_str, conv_get_locale_charset_str(), CS_INTERNAL);
+                       g_free(sig_str);
+               } else
+                       utf8_sig_str = sig_str;
+       }
+
+       return utf8_sig_str;
 }
 
 static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *file)
@@ -2156,6 +2178,7 @@ static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *fi
        gchar buf[BUFFSIZE];
        gint len;
        FILE *fp;
+       gboolean prev_autowrap;
        gboolean badtxt = FALSE;
 
        g_return_val_if_fail(file != NULL, COMPOSE_INSERT_NO_FILE);
@@ -2176,6 +2199,9 @@ static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *fi
 
        cur_encoding = conv_get_locale_charset_str();
 
+       prev_autowrap = compose->autowrap;
+       compose->autowrap = FALSE;
+
        while (fgets(buf, sizeof(buf), fp) != NULL) {
                gchar *str;
 
@@ -2198,6 +2224,9 @@ static ComposeInsertResult compose_insert_file(Compose *compose, const gchar *fi
        g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
                                          G_CALLBACK(text_inserted),
                                          compose);
+       compose->autowrap = prev_autowrap;
+       if (compose->autowrap)
+               compose_wrap_all(compose);
 
        fclose(fp);
 
@@ -2431,361 +2460,205 @@ static void compose_attach_parts(Compose *compose, MsgInfo *msginfo)
        procmime_mimeinfo_free_all(mimeinfo);
 }
 
-  
-#define CHAR_BUF_SIZE 8
 #undef NEXT_PART_NOT_CHILD
 
 
-#define GET_CHAR(iter_p, buf, len)                             \
-{                                                              \
-       gunichar uc;                                            \
-                                                               \
-       uc = gtk_text_iter_get_char(iter_p);                    \
-       if (uc != 0) {                                          \
-               len = g_unichar_to_utf8(uc, buf) > 1 ? 2 : 1;   \
-               buf[len]='\0';                                  \
-       } else {                                                \
-               buf[0] = '\0';                                  \
-               len = 1;                                        \
-       }                                                       \
-}
-#define DISP_WIDTH(len) \
-       ((len > 2) ? 2 : \
-        (len == 2) ? 1 : len)
-
-#define SPACE_CHARS    " \t"
-
-static void compose_wrap_line(Compose *compose)
-{
-       GtkTextView *text = GTK_TEXT_VIEW(compose->text);
-       GtkTextBuffer *textbuf = gtk_text_view_get_buffer(text);
-       GtkTextMark *mark;
-       GtkTextIter insert_iter, iter;
-       gint ch_len, last_ch_len;
-       gchar cbuf[CHAR_BUF_SIZE], last_ch;
-       guint text_len;
-       gint p_start, p_end;
-       gint line_pos, cur_pos;
-       gint line_len, cur_len;
-       gboolean line_end, quoted;
-
-       text_len = gtk_text_buffer_get_char_count(textbuf);
-       mark = gtk_text_buffer_get_insert(textbuf);
-       gtk_text_buffer_get_iter_at_mark(textbuf, &insert_iter, mark);
-       cur_pos = gtk_text_iter_get_offset(&insert_iter);
-       GET_CHAR(&insert_iter, cbuf, ch_len);
-       if ((ch_len == 1 && *cbuf == '\n') || cur_pos == text_len) {
-               GtkTextIter prev_iter;
-               if (cur_pos == 0)
-                       return; /* on the paragraph mark */
-               prev_iter = insert_iter;
-               gtk_text_iter_backward_char(&prev_iter);
-               GET_CHAR(&prev_iter, cbuf, ch_len);
-               if (ch_len == 1 && *cbuf == '\n')
-                       return; /* on the paragraph mark */
-       }
-
-       /* find paragraph start. */
-       line_end = quoted = FALSE;
-       for (iter = insert_iter; gtk_text_iter_backward_char(&iter);) {
-               GET_CHAR(&iter, cbuf, ch_len);
-               if (ch_len == 1 && *cbuf == '\n') {
-                       if (quoted)
-                               return; /* quoted part */
-                       if (line_end) {
-                               gtk_text_iter_forward_chars(&iter, 2);
-                               break;
-                       }
-                       line_end = TRUE;
-               } else {
-                       if (ch_len == 1 
-                           && strchr(prefs_common.quote_chars, *cbuf))
-                               quoted = 1;
-                       else if (ch_len != 1 || !isspace(*(guchar *)cbuf))
-                               quoted = 0;
-
-                       line_end = FALSE;
-               }
-       }
-       p_start = gtk_text_iter_get_offset(&iter);
-
-       /* find paragraph end. */
-       line_end = FALSE;
-       for (iter = insert_iter; gtk_text_iter_forward_char(&iter);) {
-               GET_CHAR(&iter, cbuf, ch_len);
-               if (ch_len == 1 && *cbuf == '\n') {
-                       if (line_end) {
-                               p_end -= 1;
-                               gtk_text_iter_backward_char(&iter);
-                               break;
-                       }
-                       line_end = TRUE;
-               } else {
-                       if (line_end && ch_len == 1 &&
-                           strchr(prefs_common.quote_chars, *cbuf))
-                               return; /* quoted part */
-
-                       line_end = FALSE;
-               }
-       }
-       p_end = gtk_text_iter_get_offset(&iter);
-
-       if (p_end >= text_len)
-               p_end = text_len;
-
-       if (p_start >= p_end)
-               return;
-
-       line_len = cur_len = 0;
-       last_ch_len = 0;
-       last_ch = '\0';
-       line_pos = p_start;
-       for (cur_pos = p_start; cur_pos < p_end; cur_pos++) {
-               gboolean space = FALSE;
-
-               gtk_text_buffer_get_iter_at_offset(textbuf, &iter, cur_pos);
-
-               GET_CHAR(&iter, cbuf, ch_len);
-
-               if (ch_len < 0) {
-                       cbuf[0] = '\0';
-                       ch_len = 1;
-               }
-
-               if (ch_len == 1 && isspace(*(guchar *)cbuf))
-                       space = 1;
-
-               if (ch_len == 1 && *cbuf == '\n') {
-                       gboolean replace = FALSE;
-                       GtkTextIter next_iter = iter;
-
-                       gtk_text_iter_forward_char(&next_iter);
-
-                       if (last_ch_len == 1 && !isspace((guchar)last_ch)) {
-                               if (cur_pos + 1 < p_end) {
-                                       GET_CHAR(&next_iter, cbuf, ch_len);
-                                       if (ch_len == 1 &&
-                                           !isspace(*(guchar *)cbuf))
-                                               replace = TRUE;
-                               }
-                       }
-                       gtk_text_buffer_delete(textbuf, &iter, &next_iter);
-                       if (replace) {
-                               gtk_text_buffer_insert(textbuf, &iter, " ", 1);
-                               space = TRUE;
-                       }
-                       else {
-                               p_end--;
-                               cur_pos--;
-                               gtk_text_buffer_get_iter_at_offset
-                                       (textbuf, &iter, cur_pos);
-                               continue;
-                       }
-               }
-
-               last_ch_len = ch_len;
-               last_ch = *cbuf;
-
-               if (space) {
-                       line_pos = cur_pos + 1;
-                       line_len = cur_len + DISP_WIDTH(ch_len);
-               }
-
-               gtk_text_buffer_get_iter_at_offset(textbuf, &iter, line_pos);
-
-               if (cur_len + ch_len > prefs_common.linewrap_len &&
-                   line_len > 0) {
-                       gint tlen = ch_len;
-                       GtkTextIter prev_iter = iter;
-
-                       gtk_text_iter_backward_char(&prev_iter);
-
-                       GET_CHAR(&prev_iter, cbuf, ch_len);
-                       if (ch_len == 1 && isspace(*(guchar *)cbuf)) {
-                               gtk_text_buffer_delete(textbuf, &prev_iter, &iter);
-                               iter = prev_iter;
-                               p_end--;
-                               cur_pos--;
-                               line_pos--;
-                               cur_len--;
-                               line_len--;
-                       }
-                       ch_len = tlen;
-
-                       gtk_text_buffer_insert(textbuf, &iter, "\n", 1);
-                       p_end++;
-                       cur_pos++;
-                       line_pos++;
-                       cur_len = cur_len - line_len + DISP_WIDTH(ch_len);
-                       line_len = 0;
-                       continue;
-               }
-
-               cur_len += DISP_WIDTH(ch_len);
-       }
-}
-
-#undef WRAP_DEBUG
-#ifdef WRAP_DEBUG
-/* Darko: used when I debug wrapping */
-void dump_text(GtkTextBuffer *textbuf, int pos, int tlen, int breakoncr)
-{
-       GtkTextIter iter, end_iter;
-       gint clen;
-       gchar cbuf[CHAR_BUF_SIZE];
-
-       printf("%d [", pos);
-       gtk_text_buffer_get_iter_at_offset(textbuf, &iter, pos);
-       gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter, pos + tlen);
-       for (; gtk_text_iter_forward_char(&iter) &&
-            gtk_text_iter_compare(&iter, &end_iter) < 0; ) {
-               GET_CHAR(&iter, cbuf, clen);
-               if (clen < 0) break;
-               if (breakoncr && clen == 1 && cbuf[0] == '\n')
-                       break;
-               fwrite(cbuf, clen, 1, stdout);
-       }
-       printf("]\n");
-}
-#endif
 
 typedef enum {
-       WAIT_FOR_SPACE,
        WAIT_FOR_INDENT_CHAR,
-       WAIT_FOR_INDENT_CHAR_OR_SPACE
+       WAIT_FOR_INDENT_CHAR_OR_SPACE,
 } IndentState;
 
 /* return indent length, we allow:
-   > followed by spaces/tabs
-   | followed by spaces/tabs
-   uppercase characters immediately followed by >,
-   and the repeating sequences of the above */
-/* return indent length */
-static guint get_indent_length(GtkTextBuffer *textbuf, guint start_pos,
-                              guint text_len)
-{
-       GtkTextIter iter;
-       guint i_len = 0;
-       guint ch_len, alnum_cnt = 0;
+   indent characters followed by indent characters or spaces/tabs,
+   alphabets and numbers immediately followed by indent characters,
+   and the repeating sequences of the above
+   If quote ends with multiple spaces, only the first one is included. */
+static gchar *compose_get_quote_str(GtkTextBuffer *buffer,
+                                   const GtkTextIter *start, gint *len)
+{
+       GtkTextIter iter = *start;
+       gunichar wc;
+       gchar ch[6];
+       gint clen;
        IndentState state = WAIT_FOR_INDENT_CHAR;
-       gchar cbuf[CHAR_BUF_SIZE];
        gboolean is_space;
        gboolean is_indent;
-       gboolean iter_next = TRUE;
+       gint alnum_count = 0;
+       gint space_count = 0;
+       gint quote_len = 0;
 
        if (prefs_common.quote_chars == NULL) {
                return 0 ;
        }
 
-       gtk_text_buffer_get_iter_at_offset(textbuf, &iter, start_pos);
-
-       while (iter_next == TRUE) {
-               GET_CHAR(&iter, cbuf, ch_len);
-               if (ch_len > 1)
+       while (!gtk_text_iter_ends_line(&iter)) {
+               wc = gtk_text_iter_get_char(&iter);
+               if (g_unichar_iswide(wc))
                        break;
-
-               if (cbuf[0] == '\n')
+               clen = g_unichar_to_utf8(wc, ch);
+               if (clen != 1)
                        break;
 
-               is_indent = strchr(prefs_common.quote_chars, cbuf[0]) ? TRUE : FALSE;
-               is_space = strchr(SPACE_CHARS, cbuf[0]) ? TRUE : FALSE;
+               is_indent = strchr(prefs_common.quote_chars, ch[0]) ? TRUE : FALSE;
+               is_space = g_unichar_isspace(wc);
 
-               switch (state) {
-               case WAIT_FOR_SPACE:
-                       if (is_space == FALSE)
-                               goto out;
-                       state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
-                       break;
-               case WAIT_FOR_INDENT_CHAR_OR_SPACE:
-                       if (is_indent == FALSE && is_space == FALSE &&
-                           !isupper((guchar)cbuf[0]))
-                               goto out;
-                       if (is_space == TRUE) {
-                               alnum_cnt = 0;
+               if (state == WAIT_FOR_INDENT_CHAR) {
+                       if (!is_indent && !g_unichar_isalnum(wc))
+                               break;
+                       if (is_indent) {
+                               quote_len += alnum_count + space_count + 1;
+                               alnum_count = space_count = 0;
                                state = WAIT_FOR_INDENT_CHAR_OR_SPACE;
-                       } else if (is_indent == TRUE) {
-                               alnum_cnt = 0;
-                               state = WAIT_FOR_SPACE;
+                       } else
+                               alnum_count++;
+               } else if (state == WAIT_FOR_INDENT_CHAR_OR_SPACE) {
+                       if (!is_indent && !is_space && !g_unichar_isalnum(wc))
+                               break;
+                       if (is_space)
+                               space_count++;
+                       else if (is_indent) {
+                               quote_len += alnum_count + space_count + 1;
+                               alnum_count = space_count = 0;
                        } else {
-                               alnum_cnt++;
+                               alnum_count++;
                                state = WAIT_FOR_INDENT_CHAR;
                        }
-                       break;
-               case WAIT_FOR_INDENT_CHAR:
-                       if (is_indent == FALSE && !isupper((guchar)cbuf[0]))
-                               goto out;
-                       if (is_indent == TRUE) {
-                               if (alnum_cnt > 0 
-                                   && !strchr(prefs_common.quote_chars, cbuf[0]))
-                                       goto out;
-                               alnum_cnt = 0;
-                               state = WAIT_FOR_SPACE;
-                       } else {
-                               alnum_cnt++;
-                       }
-                       break;
                }
 
-               i_len++;
-               iter_next = gtk_text_iter_forward_char(&iter);
+               gtk_text_iter_forward_char(&iter);
        }
 
-out:
-       if ((i_len > 0) && (state == WAIT_FOR_INDENT_CHAR))
-               i_len -= alnum_cnt;
+       if (quote_len > 0 && space_count > 0)
+               quote_len++;
+
+       if (len)
+               *len = quote_len;
+
+       if (quote_len > 0) {
+               iter = *start;
+               gtk_text_iter_forward_chars(&iter, quote_len);
+               return gtk_text_buffer_get_text(buffer, start, &iter, FALSE);
+       }
 
-       return i_len;
+       return NULL;
 }
 
-/* insert quotation string when line was wrapped */
-static guint ins_quote(GtkTextBuffer *textbuf, GtkTextIter *iter,
-                      guint indent_len,
-                      guint prev_line_pos, guint text_len,
-                      gchar *quote_fmt)
+static gboolean compose_get_line_break_pos(GtkTextBuffer *buffer,
+                                          const GtkTextIter *start,
+                                          GtkTextIter *break_pos,
+                                          gint max_col,
+                                          gint quote_len)
 {
-       guint ins_len = 0;
+       GtkTextIter iter = *start, line_end = *start;
+       PangoLogAttr *attrs;
+       gchar *str;
+       gchar *p;
+       gint len;
+       gint i;
+       gint col = 0;
+       gint pos = 0;
+       gboolean can_break = FALSE;
+       gboolean do_break = FALSE;
 
-       if (indent_len) {
-               GtkTextIter iter1, iter2;
-               gchar *text;
+       gtk_text_iter_forward_to_line_end(&line_end);
+       str = gtk_text_buffer_get_text(buffer, &iter, &line_end, FALSE);
+       len = g_utf8_strlen(str, -1);
+       /* g_print("breaking line: %d: %s (len = %d)\n",
+               gtk_text_iter_get_line(&iter), str, len); */
+       attrs = g_new(PangoLogAttr, len + 1);
+
+       pango_default_break(str, -1, NULL, attrs, len + 1);
+
+       p = str;
+
+       /* skip quote and leading spaces */
+       for (i = 0; *p != '\0' && i < len; i++) {
+               gunichar wc;
 
-               gtk_text_buffer_get_iter_at_offset(textbuf, &iter1,
-                                                  prev_line_pos);
-               gtk_text_buffer_get_iter_at_offset(textbuf, &iter2,
-                                                  prev_line_pos + indent_len);
-               text = gtk_text_buffer_get_text(textbuf, &iter1, &iter2, FALSE);
-               if (!text) return 0;
+               wc = g_utf8_get_char(p);
+               if (i >= quote_len && !g_unichar_isspace(wc))
+                       break;
+               if (g_unichar_iswide(wc))
+                       col += 2;
+               else if (*p == '\t')
+                       col += 8;
+               else
+                       col++;
+               p = g_utf8_next_char(p);
+       }
+
+       for (; *p != '\0' && i < len; i++) {
+               PangoLogAttr *attr = attrs + i;
+               gunichar wc;
+               gint uri_len;
+
+               if (attr->is_line_break && can_break)
+                       pos = i;
+
+               /* don't wrap URI */
+               if ((uri_len = get_uri_len(p)) > 0) {
+                       col += uri_len;
+                       if (pos > 0 && col > max_col) {
+                               do_break = TRUE;
+                               break;
+                       }
+                       i += uri_len - 1;
+                       p += uri_len;
+                       can_break = TRUE;
+                       continue;
+               }
 
-               gtk_text_buffer_insert(textbuf, iter, text, -1);
-               ins_len = g_utf8_strlen(text, -1);
+               wc = g_utf8_get_char(p);
+               if (g_unichar_iswide(wc))
+                       col += 2;
+               else if (*p == '\t')
+                       col += 8;
+               else
+                       col++;
+               if (pos > 0 && col > max_col) {
+                       do_break = TRUE;
+                       break;
+               }
 
-               g_free(text);
+               p = g_utf8_next_char(p);
+               can_break = TRUE;
        }
 
-       return ins_len;
+       debug_print("compose_get_line_break_pos(): do_break = %d, pos = %d, col = %d\n", do_break, pos, col);
+
+       g_free(attrs);
+       g_free(str);
+
+       *break_pos = *start;
+       gtk_text_iter_set_line_offset(break_pos, pos);
+
+       return do_break;
 }
 
-static gboolean is_sig_separator(Compose *compose, GtkTextBuffer *textbuf, guint start_pos
+static gboolean is_sig_separator(Compose *compose, GtkTextBuffer *textbuf, GtkTextIter *iter
 {
        char *text = NULL;
-       GtkTextIter iter; 
+       GtkTextIter start = *iter;
        GtkTextIter end_iter;
+       int start_pos = gtk_text_iter_get_offset(&start);
+
        if (!compose->account->sig_sep)
                return FALSE;
        
-       gtk_text_buffer_get_iter_at_offset(textbuf, &iter, start_pos+1);
        gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter,
-               start_pos+strlen(compose->account->sig_sep)+1);
+               start_pos+strlen(compose->account->sig_sep));
 
-       if (!strcmp(gtk_text_iter_get_text(&iter, &end_iter),
+       /* check sig separator */
+       if (!strcmp(gtk_text_iter_get_text(&start, &end_iter),
                        compose->account->sig_sep)) {
-               /* check \n */
-               gtk_text_buffer_get_iter_at_offset(textbuf, &iter,
-                       start_pos+strlen(compose->account->sig_sep)+1);
+               /* check end of line (\n) */
+               gtk_text_buffer_get_iter_at_offset(textbuf, &start,
+                       start_pos+strlen(compose->account->sig_sep));
                gtk_text_buffer_get_iter_at_offset(textbuf, &end_iter,
-                       start_pos+strlen(compose->account->sig_sep)+2);
+                       start_pos+strlen(compose->account->sig_sep)+1);
 
-               if (!strcmp(gtk_text_iter_get_text(&iter, &end_iter),"\n"));
+               if (!strcmp(gtk_text_iter_get_text(&start, &end_iter),"\n"));
                        return TRUE;
                
 
@@ -2794,320 +2667,212 @@ static gboolean is_sig_separator(Compose *compose, GtkTextBuffer *textbuf, guint
        return FALSE;
 }
 
-/* check if we should join the next line */
-static gboolean join_next_line_is_needed(GtkTextBuffer *textbuf,
-                                        guint start_pos, guint tlen,
-                                        guint prev_ilen, gboolean autowrap)
+static gboolean compose_join_next_line(Compose *compose,
+                                      GtkTextBuffer *buffer,
+                                      GtkTextIter *iter,
+                                      const gchar *quote_str)
 {
-       guint indent_len, ch_len;
-       gboolean do_join = FALSE;
-       gchar cbuf[CHAR_BUF_SIZE];
+       GtkTextIter iter_ = *iter, cur, prev, next;
+       PangoLogAttr attrs[3];
+       gchar *str;
+       gchar *next_quote_str;
+       gunichar wc1, wc2;
+       gint quote_len;
+       gboolean keep_cursor = FALSE;
 
-       indent_len = get_indent_length(textbuf, start_pos, tlen);
+       if (!gtk_text_iter_forward_line(&iter_) ||
+           gtk_text_iter_ends_line(&iter_))
+               return FALSE;
 
-       if ((autowrap || indent_len > 0) && indent_len == prev_ilen) {
-               GtkTextIter iter;
-               gtk_text_buffer_get_iter_at_offset(textbuf, &iter,
-                                                  start_pos + indent_len);
-               GET_CHAR(&iter, cbuf, ch_len);
-               
-               if (ch_len > 0 && (cbuf[0] != '\n'))
-                       do_join = TRUE;
+       next_quote_str = compose_get_quote_str(buffer, &iter_, &quote_len);
+
+       if ((quote_str || next_quote_str) &&
+           strcmp2(quote_str, next_quote_str) != 0) {
+               g_free(next_quote_str);
+               return FALSE;
        }
+       g_free(next_quote_str);
 
-       return do_join;
-}
+       /* delete quote str */
+       if (quote_len > 0) {
+               GtkTextIter end = iter_;
 
-static void compose_wrap_line_all(Compose *compose)
-{
-       compose_wrap_line_all_full(compose, FALSE);
-}
+               gtk_text_iter_forward_chars(&end, quote_len);
+               if (gtk_text_iter_ends_line(&end))
+                       return FALSE;
+               gtk_text_buffer_delete(buffer, &iter_, &end);
+       }
 
-static void compose_wrap_line_all_full(Compose *compose, gboolean autowrap)
-{
-       GtkTextView *text = GTK_TEXT_VIEW(compose->text);
-       GtkTextBuffer *textbuf = gtk_text_view_get_buffer(text);
-       GtkTextIter iter, end_iter;
-       guint tlen;
-       guint line_pos = 0, cur_pos = 0, p_pos = 0;
-       gint line_len = 0, cur_len = 0;
-       gint ch_len;
-       gboolean is_new_line = TRUE, do_delete = FALSE;
-       guint i_len = 0;
-       gboolean linewrap_quote = prefs_common.linewrap_quote;
-       gboolean set_editable_pos = FALSE;
-       gint editable_pos = 0;
-       guint linewrap_len = prefs_common.linewrap_len;
-       gchar *qfmt = prefs_common.quotemark;
-       gchar cbuf[CHAR_BUF_SIZE];
-       GtkTextMark *cursor_mark = gtk_text_buffer_get_insert(textbuf);
-       
-       tlen = gtk_text_buffer_get_char_count(textbuf);
+       /* don't join if next line is sig separator */
+       if (is_sig_separator(compose, buffer, &iter_))
+               return FALSE;
 
-       for (; cur_pos < tlen; cur_pos++) {
-               /* mark position of new line - needed for quotation wrap */
-               if (is_new_line) {
-                       if (linewrap_quote)
-                               i_len = get_indent_length(textbuf, cur_pos, tlen);
+       /* delete linebreak and extra spaces */
+       prev = cur = iter_;
+       while (gtk_text_iter_backward_char(&cur)) {
+               wc1 = gtk_text_iter_get_char(&cur);
+               if (!g_unichar_isspace(wc1))
+                       break;
+               prev = cur;
+       }
+       next = cur = iter_;
+       while (!gtk_text_iter_ends_line(&cur)) {
+               wc1 = gtk_text_iter_get_char(&cur);
+               if (!g_unichar_isspace(wc1))
+                       break;
+               gtk_text_iter_forward_char(&cur);
+               next = cur;
+       }
+       
+       if (!gtk_text_iter_equal(&prev, &next)) {
+               GtkTextMark *mark;
 
-                       is_new_line = FALSE;
-                       p_pos = cur_pos;
+               mark = gtk_text_buffer_get_insert(buffer);
+               gtk_text_buffer_get_iter_at_mark(buffer, &cur, mark);
+               if (gtk_text_iter_equal(&prev, &cur))
+                       keep_cursor = TRUE;
+               gtk_text_buffer_delete(buffer, &prev, &next);
+       }
+       iter_ = prev;
+
+       /* insert space if required */
+       gtk_text_iter_backward_char(&prev);
+       wc1 = gtk_text_iter_get_char(&prev);
+       wc2 = gtk_text_iter_get_char(&next);
+       gtk_text_iter_forward_char(&next);
+       str = gtk_text_buffer_get_text(buffer, &prev, &next, FALSE);
+       pango_default_break(str, -1, NULL, attrs, 3);
+       if (!attrs[1].is_line_break ||
+           (!g_unichar_iswide(wc1) || !g_unichar_iswide(wc2))) {
+               gtk_text_buffer_insert(buffer, &iter_, " ", 1);
+               if (keep_cursor) {
+                       gtk_text_iter_backward_char(&iter_);
+                       gtk_text_buffer_place_cursor(buffer, &iter_);
                }
+       }
+       g_free(str);
 
-               gtk_text_buffer_get_iter_at_offset(textbuf, &iter, cur_pos);
-               GET_CHAR(&iter, cbuf, ch_len);
+       *iter = iter_;
+       return TRUE;
+}
 
-               /* fix line length for tabs */
-               if (ch_len == 1 && *cbuf == '\t') {
-                       guint tab_width = 8;
-                       guint tab_offset = line_len % tab_width;
+static void compose_wrap_paragraph(Compose *compose, GtkTextIter *par_iter)
+{
+       GtkTextView *text = GTK_TEXT_VIEW(compose->text);
+       GtkTextBuffer *buffer;
+       GtkTextIter iter, break_pos;
+       gchar *quote_str = NULL;
+       gint quote_len;
+       gboolean wrap_quote = prefs_common.linewrap_quote;
 
-                       line_len += tab_width - tab_offset - 1;
-                       cur_len = line_len;
-               }
+       buffer = gtk_text_view_get_buffer(text);
 
-               /* we have encountered line break */
-               if (ch_len == 1 && *cbuf == '\n') {
-                       gint clen;
-                       gchar cb[CHAR_BUF_SIZE];
-
-                       /* should we join the next line */
-                       if ((autowrap || i_len != cur_len) && do_delete &&
-                       !is_sig_separator(compose, textbuf, cur_pos+i_len) &&
-                           join_next_line_is_needed
-                               (textbuf, cur_pos + 1, tlen, i_len, autowrap)) {
-                               do_delete = TRUE;
-                       } else
-                               do_delete = FALSE;
-
-                       /* skip delete if it is continuous URL */
-                       if (do_delete && (line_pos - p_pos <= i_len) &&
-                           gtkut_text_buffer_is_uri_string(textbuf, line_pos,
-                                                           tlen))
-                               do_delete = FALSE;
-
-                       /* should we delete to perform smart wrapping */
-                       if (line_len < linewrap_len && do_delete) {
-                               /* get rid of newline */
-                               gtk_text_buffer_get_iter_at_offset(textbuf,
-                                                                  &iter,
-                                                                  cur_pos);
-                               end_iter = iter;
-                               gtk_text_iter_forward_char(&end_iter);
-                               gtk_text_buffer_delete(textbuf, &iter, &end_iter);
-                               tlen--;
-
-                               /* if text starts with quote fmt or with
-                                  indent string, delete them */
-                               if (i_len) {
-                                       guint ilen;
-                                       ilen =  gtkut_text_buffer_str_compare_n
-                                               (textbuf, cur_pos, p_pos, i_len,
-                                                tlen);
-                                       if (ilen) {
-                                               end_iter = iter;
-                                               gtk_text_iter_forward_chars
-                                                       (&end_iter, ilen);
-                                               gtk_text_buffer_delete(textbuf,
-                                                                      &iter,
-                                                                      &end_iter);
-                                               tlen -= ilen;
-                                       }
-                               }
+       if (par_iter) {
+               iter = *par_iter;
+       } else {
+               GtkTextMark *mark;
+               mark = gtk_text_buffer_get_insert(buffer);
+               gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
+       }
 
-                               gtk_text_buffer_get_iter_at_offset(textbuf,
-                                                                  &iter,
-                                                                  cur_pos);
-                               GET_CHAR(&iter, cb, clen);
-
-                               /* insert space if it's alphanumeric */
-                               if ((cur_pos != line_pos) &&
-                                   ((clen > 1) || isalnum((guchar)cb[0]))) {
-                                       GtkTextIter cursor_iter;
-                                       gboolean go_back = FALSE;
-                                       gtk_text_buffer_get_iter_at_mark(textbuf, &cursor_iter, cursor_mark);
-                                       if (gtk_text_iter_get_offset(&iter) ==
-                                                gtk_text_iter_get_offset(&cursor_iter))
-                                               go_back = TRUE;
-                                       
-                                       gtk_text_buffer_insert(textbuf, &iter,
-                                                              " ", 1);
-                                       if (go_back) {
-                                               gtk_text_buffer_get_iter_at_mark(textbuf, &cursor_iter, cursor_mark);
-                                               gtk_text_iter_backward_chars(&cursor_iter, 1);
-                                               gtk_text_buffer_place_cursor(textbuf, &cursor_iter);
-                                       }
-                                       tlen++;
-                               }
+       /* move to paragraph start */
+       gtk_text_iter_set_line_offset(&iter, 0);
+       if (gtk_text_iter_ends_line(&iter)) {
+               while (gtk_text_iter_ends_line(&iter) &&
+                      gtk_text_iter_forward_line(&iter))
+                       ;
+       } else {
+               while (gtk_text_iter_backward_line(&iter)) {
+                       if (gtk_text_iter_ends_line(&iter)) {
+                               gtk_text_iter_forward_line(&iter);
+                               break;
+                       }
+               }
+       }
 
-                               /* and start over with current line */
-                               cur_pos = p_pos - 1;
-                               line_pos = cur_pos;
-                               line_len = cur_len = 0;
-                               do_delete = FALSE;
-                               is_new_line = TRUE;
-#ifdef WRAP_DEBUG
-                               g_print("after delete l_pos=");
-                               dump_text(textbuf, line_pos, tlen, 1);
-#endif
-                               /* move beginning of line if we are on LF */
-                               gtk_text_buffer_get_iter_at_offset(textbuf,
-                                                                  &iter,
-                                                                  line_pos);
-                               GET_CHAR(&iter, cb, clen);
-                               if (clen == 1 && *cb == '\n')
-                                       line_pos++;
-#ifdef WRAP_DEBUG
-                               g_print("new line_pos=%d\n", line_pos);
-#endif
+       if (gtk_text_iter_is_end(&iter)) {
+               if (par_iter)
+                       *par_iter = iter;
+               return;
+       }
 
+       do {
+               quote_str = compose_get_quote_str(buffer, &iter, &quote_len);
+               if (quote_str) {
+                       if (!wrap_quote) {
+                               gtk_text_iter_forward_line(&iter);
+                               g_free(quote_str);
                                continue;
                        }
-
-                       /* mark new line beginning */
-                       line_pos = cur_pos + 1;
-                       line_len = cur_len = 0;
-                       do_delete = FALSE;
-                       is_new_line = TRUE;
-                       continue;
-               }
-
-               if (ch_len < 0) {
-                       cbuf[0] = '\0';
-                       ch_len = 1;
+                       debug_print("compose_wrap_paragraph(): quote_str = '%s'\n", quote_str);
                }
 
-               /* possible line break */
-               if (ch_len == 1 && isspace(*(guchar *)cbuf)) {
-                       line_pos = cur_pos + 1;
-                       line_len = cur_len + DISP_WIDTH(ch_len);
-               }
+               if (compose_get_line_break_pos(buffer, &iter, &break_pos,
+                                              prefs_common.linewrap_len,
+                                              quote_len)) {
+                       GtkTextIter prev, next, cur;
 
-               /* are we over wrapping length set in preferences ? */
-               if (cur_len + DISP_WIDTH(ch_len) > linewrap_len) {
-                       gint clen;
+                       gtk_text_buffer_insert(buffer, &break_pos, "\n", 1);
 
-#ifdef WRAP_DEBUG
-                       g_print("should wrap cur_pos=%d ", cur_pos);
-                       dump_text(textbuf, p_pos, tlen, 1);
-                       dump_text(textbuf, line_pos, tlen, 1);
-#endif
-                       /* force wrapping if it is one long word but not URL */
-                       if (line_pos - p_pos <= i_len)
-                               if (!gtkut_text_buffer_is_uri_string
-                                   (textbuf, line_pos, tlen))
-                                       line_pos = cur_pos - 1;
-#ifdef WRAP_DEBUG
-                       g_print("new line_pos=%d\n", line_pos);
-#endif
+                       /* remove trailing spaces */
+                       cur = break_pos;
+                       gtk_text_iter_backward_char(&cur);
+                       prev = next = cur;
+                       while (!gtk_text_iter_starts_line(&cur)) {
+                               gunichar wc;
 
-                       gtk_text_buffer_get_iter_at_offset(textbuf,
-                                                          &iter,
-                                                          line_pos - 1);
-                       GET_CHAR(&iter, cbuf, clen);
-
-                       /* if next character is space delete it */
-                       if (clen == 1 && isspace(*(guchar *)cbuf)) {
-                               if (p_pos + i_len != line_pos ||
-                                   !gtkut_text_buffer_is_uri_string
-                                       (textbuf, line_pos, tlen)) {
-                                       /* workaround for correct cursor
-                                          position */
-                                       if (set_editable_pos == FALSE) {
-                                               GtkTextMark *ins = gtk_text_buffer_get_insert(textbuf);
-                                               gtk_text_buffer_get_iter_at_mark(textbuf, &iter, ins);
-                                               editable_pos = gtk_text_iter_get_offset(&iter);
-                                               if (editable_pos == line_pos)
-                                                       set_editable_pos = TRUE;
-                                       }
-                                       gtk_text_buffer_get_iter_at_offset(textbuf,
-                                                          &iter,
-                                                          line_pos-1);
-                                       gtk_text_buffer_get_iter_at_offset(textbuf,
-                                                          &end_iter,
-                                                          line_pos);
-                                       gtk_text_buffer_delete(textbuf, &iter, &end_iter);
-                                       //gtk_stext_set_point(text, line_pos);
-                                       //gtk_stext_backward_delete(text, 1);
-                                       tlen--;
-                                       cur_pos--;
-                                       line_pos--;
-                                       cur_len--;
-                                       line_len--;
-                               }
+                               gtk_text_iter_backward_char(&cur);
+                               wc = gtk_text_iter_get_char(&cur);
+                               if (!g_unichar_isspace(wc))
+                                       break;
+                               prev = cur;
                        }
-
-                       /* if it is URL at beginning of line don't wrap */
-                       if (p_pos + i_len == line_pos &&
-                           gtkut_text_buffer_is_uri_string(textbuf, line_pos, tlen)) {
-#ifdef WRAP_DEBUG
-                               g_print("found URL at ");
-                               dump_text(textbuf, line_pos, tlen, 1);
-#endif
-                               continue;
+                       if (!gtk_text_iter_equal(&prev, &next)) {
+                               gtk_text_buffer_delete(buffer, &prev, &next);
+                               break_pos = next;
+                               gtk_text_iter_forward_char(&break_pos);
                        }
 
-                       /* insert CR */
-                       gtk_text_buffer_get_iter_at_offset(textbuf,
-                                                          &iter,
-                                                          line_pos);
-                       gtk_text_buffer_insert(textbuf, &iter, "\n", 1);
-                       //gtk_stext_set_point(text, line_pos);
-                       //gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
-                       //gtk_stext_compact_buffer(text);
-                       tlen++;
-                       line_pos++;
-                       /* for loop will increase it */
-                       cur_pos = line_pos - 1;
-                       /* start over with current line */
-                       is_new_line = TRUE;
-                       line_len = cur_len = 0;
-                       if (autowrap || i_len > 0) {
-                               do_delete = TRUE;
-                       } else
-                               do_delete = FALSE;
-#ifdef WRAP_DEBUG
-                       g_print("after CR insert ");
-                       dump_text(textbuf, line_pos, tlen, 1);
-                       dump_text(textbuf, cur_pos, tlen, 1);
-#endif
+                       if (quote_str)
+                               gtk_text_buffer_insert(buffer, &break_pos,
+                                                      quote_str, -1);
 
-                       /* should we insert quotation ? */
-                       if (linewrap_quote && i_len) {
-                               /* only if line is not already quoted  */
-                               if (!gtkut_text_buffer_str_compare
-                                       (textbuf, line_pos, tlen, qfmt)) {
-                                       guint ins_len;
-                                       
-                                       gtk_text_buffer_get_iter_at_offset(textbuf, &iter, line_pos);
-                                       
-                                       if (line_pos - p_pos > i_len) {
-                                               ins_len = ins_quote
-                                                       (textbuf, &iter, i_len, p_pos,
-                                                        tlen, qfmt);
-                                               tlen += ins_len;
-                                       }
-#ifdef WRAP_DEBUG
-                                       g_print("after quote insert ");
-                                       dump_text(textbuf, line_pos, tlen, 1);
-#endif
-                               }
-                       }
-                       continue;
+                       iter = break_pos;
+                       compose_join_next_line(compose, buffer, &iter, quote_str);
+
+                       /* move iter to current line start */
+                       gtk_text_iter_set_line_offset(&iter, 0);
+               } else {
+                       /* move iter to next line start */
+                       iter = break_pos;
+                       gtk_text_iter_forward_line(&iter);
                }
 
-               /* advance to next character in buffer */
-               cur_len += DISP_WIDTH(ch_len);
-       }
+               g_free(quote_str);
+       } while (!gtk_text_iter_ends_line(&iter));
+       /* stop if paragraph end (empty line) */
 
-       if (set_editable_pos && editable_pos <= tlen) {
-               gtk_text_buffer_get_iter_at_offset(textbuf, &iter, editable_pos);
-               gtk_text_buffer_place_cursor(textbuf, &iter);
-       }
+       if (par_iter)
+               *par_iter = iter;
+}
+
+static void compose_wrap_all(Compose *compose)
+{
+       compose_wrap_all_full(compose, FALSE);
 }
 
-#undef GET_CHAR
-#undef CHAR_BUF_SIZE
+static void compose_wrap_all_full(Compose *compose, gboolean autowrap)
+{
+       GtkTextView *text = GTK_TEXT_VIEW(compose->text);
+       GtkTextBuffer *buffer;
+       GtkTextIter iter;
+
+       buffer = gtk_text_view_get_buffer(text);
+
+       gtk_text_buffer_get_start_iter(buffer, &iter);
+       while (!gtk_text_iter_is_end(&iter))
+               compose_wrap_paragraph(compose, &iter);
+}
 
 static void compose_set_title(Compose *compose)
 {
@@ -3694,6 +3459,8 @@ static gint compose_write_to_file(Compose *compose, FILE *fp, gint action)
                        return -1;
 
        procmime_write_mimeinfo(mimemsg, fp);
+       
+       procmime_mimeinfo_free_all(mimemsg);
 
        return 0;
 }
@@ -3837,7 +3604,7 @@ static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
        }
 
         if (prefs_common.linewrap_at_send)
-               compose_wrap_line_all(compose);
+               compose_wrap_all(compose);
 
        /* write queue header */
        tmp = g_strdup_printf("%s%cqueue.%p", get_tmp_dir(),
@@ -4045,6 +3812,13 @@ static void compose_add_attachments(Compose *compose, MimeInfo *parent)
                        mimepart->disposition = DISPOSITIONTYPE_ATTACHMENT;
                }
 
+               if (compose->use_signing) {
+                       if (ainfo->encoding == ENC_7BIT)
+                               ainfo->encoding = ENC_QUOTED_PRINTABLE;
+                       else if (ainfo->encoding == ENC_8BIT)
+                               ainfo->encoding = ENC_BASE64;
+               }
+               
                procmime_encode_content(mimepart, ainfo->encoding);
 
                g_node_append(parent->node, mimepart->node);
@@ -5281,7 +5055,11 @@ static void compose_set_privacy_system_cb(GtkWidget *widget, gpointer data)
 
        ifactory = gtk_item_factory_from_widget(compose->menubar);
        menu_set_sensitive(ifactory, "/Options/Sign", can_sign);
+       if (!can_sign)
+               menu_set_active(ifactory, "/Options/Sign", FALSE);
        menu_set_sensitive(ifactory, "/Options/Encrypt", can_encrypt);
+       if (!can_encrypt)
+               menu_set_active(ifactory, "/Options/Encrypt", FALSE);
 }
 
 static void compose_update_privacy_system_menu_item(Compose * compose)
@@ -6642,12 +6420,20 @@ static void compose_destroy_cb(GtkWidget *widget, Compose *compose)
 
 static void compose_undo_cb(Compose *compose)
 {
+       gboolean prev_autowrap = compose->autowrap;
+
+       compose->autowrap = FALSE;
        undo_undo(compose->undostruct);
+       compose->autowrap = prev_autowrap;
 }
 
 static void compose_redo_cb(Compose *compose)
 {
+       gboolean prev_autowrap = compose->autowrap;
+       
+       compose->autowrap = FALSE;
        undo_redo(compose->undostruct);
+       compose->autowrap = prev_autowrap;
 }
 
 static void entry_cut_clipboard(GtkWidget *entry)
@@ -6701,7 +6487,6 @@ static void entry_allsel(GtkWidget *entry)
        }
 }
 
-
 static void compose_cut_cb(Compose *compose)
 {
        if (compose->focused_editable &&
@@ -7073,13 +6858,23 @@ static void compose_changed_cb(GtkTextBuffer *textbuf, Compose *compose)
        }
 }
 
+static void compose_wrap_cb(gpointer data, guint action, GtkWidget *widget)
+{
+       Compose *compose = (Compose *)data;
+
+       if (action == 1)
+               compose_wrap_all(compose);
+       else
+               compose_wrap_paragraph(compose, NULL);
+}
+
 static void compose_toggle_autowrap_cb(gpointer data, guint action,
                                       GtkWidget *widget)
 {
        Compose *compose = (Compose *)data;
        compose->autowrap = GTK_CHECK_MENU_ITEM(widget)->active;
        if (compose->autowrap)
-               compose_wrap_line_all_full(compose, TRUE);
+               compose_wrap_all_full(compose, TRUE);
 }
 
 static void compose_toggle_sign_cb(gpointer data, guint action,
@@ -7412,7 +7207,7 @@ static void text_inserted(GtkTextBuffer *buffer, GtkTextIter *iter,
                gtk_text_buffer_insert(buffer, iter, text, len);
 
        mark = gtk_text_buffer_create_mark(buffer, NULL, iter, FALSE);
-       compose_wrap_line_all_full(compose, TRUE);
+       compose_wrap_all_full(compose, TRUE);
        gtk_text_buffer_get_iter_at_mark(buffer, iter, mark);
        gtk_text_buffer_delete_mark(buffer, mark);