display signatures in grey
[claws.git] / src / textview.c
index 1f75beb868d44870581bc5da36853fb2f29efb2e..d8d56362191637ae865296325564869b3b5451e8 100644 (file)
@@ -78,6 +78,13 @@ static GdkColor quote_colors[3] = {
        {(gulong)0, (gushort)0, (gushort)0, (gushort)0}
 };
 
+static GdkColor signature_color = {
+       (gulong)0,
+       (gushort)0x7fff,
+       (gushort)0x7fff,
+       (gushort)0x7fff
+};
+       
 static GdkColor uri_color = {
        (gulong)0,
        (gushort)0,
@@ -92,18 +99,36 @@ static GdkColor emphasis_color = {
        (gushort)0xcfff
 };
 
+#if 0
 static GdkColor error_color = {
        (gulong)0,
        (gushort)0xefff,
        (gushort)0,
        (gushort)0
 };
+#endif
 
+static GdkFont *text_sb_font;
+static GdkFont *text_mb_font;
+static gint text_sb_font_orig_ascent;
+static gint text_sb_font_orig_descent;
+static gint text_mb_font_orig_ascent;
+static gint text_mb_font_orig_descent;
 static GdkFont *spacingfont;
 
 static void textview_show_ertf         (TextView       *textview,
                                         FILE           *fp,
                                         CodeConverter  *conv);
+static void textview_add_part          (TextView       *textview,
+                                        MimeInfo       *mimeinfo,
+                                        FILE           *fp);
+static void textview_add_parts         (TextView       *textview,
+                                        MimeInfo       *mimeinfo,
+                                        FILE           *fp);
+static void textview_write_body                (TextView       *textview,
+                                        MimeInfo       *mimeinfo,
+                                        FILE           *fp,
+                                        const gchar    *charset);
 static void textview_show_html         (TextView       *textview,
                                         FILE           *fp,
                                         CodeConverter  *conv);
@@ -150,7 +175,7 @@ TextView *textview_create(void)
        GtkWidget *text_sb;
        GtkWidget *text_mb;
 
-       debug_print(_("Creating text view...\n"));
+       debug_print("Creating text view...\n");
        textview = g_new0(TextView, 1);
 
        scrolledwin_sb = gtk_scrolled_window_new(NULL, NULL);
@@ -227,18 +252,22 @@ TextView *textview_create(void)
        vbox = gtk_vbox_new(FALSE, 0);
        gtk_box_pack_start(GTK_BOX(vbox), scrolledwin_sb, TRUE, TRUE, 0);
 
-       textview->vbox           = vbox;
-       textview->scrolledwin    = scrolledwin_sb;
-       textview->scrolledwin_sb = scrolledwin_sb;
-       textview->scrolledwin_mb = scrolledwin_mb;
-       textview->text           = text_sb;
-       textview->text_sb        = text_sb;
-       textview->text_mb        = text_mb;
-       textview->text_is_mb     = FALSE;
-       textview->uri_list       = NULL;
-       textview->body_pos       = 0;
-       textview->cur_pos        = 0;
+       gtk_widget_show(vbox);
+
+       textview->vbox             = vbox;
+       textview->scrolledwin      = scrolledwin_sb;
+       textview->scrolledwin_sb   = scrolledwin_sb;
+       textview->scrolledwin_mb   = scrolledwin_mb;
+       textview->text             = text_sb;
+       textview->text_sb          = text_sb;
+       textview->text_mb          = text_mb;
+       textview->text_is_mb       = FALSE;
+       textview->uri_list         = NULL;
+       textview->body_pos         = 0;
+       textview->cur_pos          = 0;
+       textview->show_all_headers = FALSE;
        textview->last_buttonpress = GDK_NOTHING;
+       textview->show_url_msgid   = 0;
 
        return textview;
 }
@@ -248,6 +277,7 @@ void textview_init(TextView *textview)
        gtkut_widget_disable_theme_engine(textview->text_sb);
        gtkut_widget_disable_theme_engine(textview->text_mb);
        textview_update_message_colors();
+       textview_set_all_headers(textview, FALSE);
        textview_set_font(textview, NULL);
 }
 
@@ -274,14 +304,38 @@ void textview_update_message_colors(void)
 void textview_show_message(TextView *textview, MimeInfo *mimeinfo,
                           const gchar *file)
 {
+       GtkSText *text;
        FILE *fp;
+       const gchar *charset = NULL;
+       GPtrArray *headers = NULL;
 
-       if ((fp = fopen(file, "r")) == NULL) {
+       if ((fp = fopen(file, "rb")) == NULL) {
                FILE_OP_ERROR(file, "fopen");
                return;
        }
 
-       textview_show_part(textview, mimeinfo, fp);
+       if (prefs_common.force_charset)
+               charset = prefs_common.force_charset;
+       else if (mimeinfo->charset)
+               charset = mimeinfo->charset;
+       textview_set_font(textview, charset);
+       textview_clear(textview);
+
+       text = GTK_STEXT(textview->text);
+
+       gtk_stext_freeze(text);
+
+       if (fseek(fp, mimeinfo->fpos, SEEK_SET) < 0) perror("fseek");
+       headers = textview_scan_header(textview, fp);
+       if (headers) {
+               textview_show_header(textview, headers);
+               procheader_header_array_destroy(headers);
+               textview->body_pos = gtk_stext_get_length(text);
+       }
+
+       textview_add_parts(textview, mimeinfo, fp);
+
+       gtk_stext_thaw(text);
 
        fclose(fp);
 }
@@ -293,30 +347,27 @@ void textview_show_part(TextView *textview, MimeInfo *mimeinfo, FILE *fp)
        const gchar *boundary = NULL;
        gint boundary_len = 0;
        const gchar *charset = NULL;
-       FILE *tmpfp;
        GPtrArray *headers = NULL;
-       CodeConverter *conv;
+       gboolean is_rfc822_part = FALSE;
 
        g_return_if_fail(mimeinfo != NULL);
        g_return_if_fail(fp != NULL);
 
        if (mimeinfo->mime_type == MIME_MULTIPART) {
-               if (mimeinfo->sub) {
-                       mimeinfo = mimeinfo->sub;
-                       if (fseek(fp, mimeinfo->fpos, SEEK_SET) < 0) {
-                               perror("fseek");
-                               return;
-                       }
-               } else
-                       return;
+               textview_clear(textview);
+               textview_add_parts(textview, mimeinfo, fp);
+               return;
        }
+
        if (mimeinfo->parent && mimeinfo->parent->boundary) {
                boundary = mimeinfo->parent->boundary;
                boundary_len = strlen(boundary);
        }
 
-       if (!boundary && (mimeinfo->mime_type == MIME_TEXT || mimeinfo->mime_type == MIME_TEXT_HTML || mimeinfo->mime_type == MIME_TEXT_ENRICHED)) {
-       
+       if (!boundary && (mimeinfo->mime_type == MIME_TEXT || 
+                         mimeinfo->mime_type == MIME_TEXT_HTML || 
+                         mimeinfo->mime_type == MIME_TEXT_ENRICHED)) {
+               
                if (fseek(fp, mimeinfo->fpos, SEEK_SET) < 0)
                        perror("fseek");
                headers = textview_scan_header(textview, fp);
@@ -349,17 +400,15 @@ void textview_show_part(TextView *textview, MimeInfo *mimeinfo, FILE *fp)
        }
 
        /* display attached RFC822 single text message */
-       if (mimeinfo->parent && mimeinfo->mime_type == MIME_MESSAGE_RFC822) {
-               if (headers) procheader_header_array_destroy(headers);
-               if (!mimeinfo->sub || mimeinfo->sub->children) return;
-               headers = textview_scan_header(textview, fp);
-               mimeinfo = mimeinfo->sub;
-       } else if (!mimeinfo->parent &&
-                  mimeinfo->mime_type == MIME_MESSAGE_RFC822) {
+       if (mimeinfo->mime_type == MIME_MESSAGE_RFC822) {
                if (headers) procheader_header_array_destroy(headers);
-               if (!mimeinfo->sub) return;
+               if (!mimeinfo->sub) {
+                       textview_clear(textview);
+                       return;
+               }
                headers = textview_scan_header(textview, fp);
                mimeinfo = mimeinfo->sub;
+               is_rfc822_part = TRUE;
        }
 
        if (prefs_common.force_charset)
@@ -368,47 +417,132 @@ void textview_show_part(TextView *textview, MimeInfo *mimeinfo, FILE *fp)
                charset = mimeinfo->charset;
        textview_set_font(textview, charset);
 
-       conv = conv_code_converter_new(charset);
-
-       textview_clear(textview);
        text = GTK_STEXT(textview->text);
-       gtk_stext_freeze(text);
 
-       textview->body_pos = 0;
-       textview->cur_pos  = 0;
+       gtk_stext_freeze(text);
+       textview_clear(textview);
 
        if (headers) {
                textview_show_header(textview, headers);
                procheader_header_array_destroy(headers);
+               textview->body_pos = gtk_stext_get_length(text);
+               if (!mimeinfo->main)
+                       gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
        }
 
-/* #if 0 */
-       tmpfp = procmime_decode_content(NULL, fp, mimeinfo);
+       if (mimeinfo->mime_type == MIME_MULTIPART || is_rfc822_part)
+               textview_add_parts(textview, mimeinfo, fp);
+       else
+               textview_write_body(textview, mimeinfo, fp, charset);
 
-       if (tmpfp) {
-               if (mimeinfo->mime_type == MIME_TEXT_HTML)
-                       textview_show_html(textview, tmpfp, conv);
-               else if (mimeinfo->mime_type == MIME_TEXT_ENRICHED)
-                       textview_show_ertf(textview, tmpfp, conv);
-               else
-                       while (fgets(buf, sizeof(buf), tmpfp) != NULL)
-                               textview_write_line(textview, buf, conv);
-               fclose(tmpfp);
+       gtk_stext_thaw(text);
+}
+
+static void textview_add_part(TextView *textview, MimeInfo *mimeinfo, FILE *fp)
+{
+       GtkSText *text = GTK_STEXT(textview->text);
+       gchar buf[BUFFSIZE];
+       const gchar *boundary = NULL;
+       gint boundary_len = 0;
+       const gchar *charset = NULL;
+       GPtrArray *headers = NULL;
+
+       g_return_if_fail(mimeinfo != NULL);
+       g_return_if_fail(fp != NULL);
+
+       if (mimeinfo->mime_type == MIME_MULTIPART) return;
+
+       if (!mimeinfo->parent &&
+           mimeinfo->mime_type != MIME_TEXT &&
+           mimeinfo->mime_type != MIME_TEXT_HTML &&
+           mimeinfo->mime_type != MIME_TEXT_ENRICHED)
+               return;
+
+       if (fseek(fp, mimeinfo->fpos, SEEK_SET) < 0) {
+               perror("fseek");
+               return;
        }
-/* #else
-       tmpfp = procmime_get_text_content(mimeinfo, fp);
 
-       while (fgets(buf, sizeof(buf), tmpfp) != NULL)
-               textview_write_line(textview, buf, conv);
+       if (mimeinfo->parent && mimeinfo->parent->boundary) {
+               boundary = mimeinfo->parent->boundary;
+               boundary_len = strlen(boundary);
+       }
 
-       fclose(tmpfp);
-#endif */
+       while (fgets(buf, sizeof(buf), fp) != NULL)
+               if (buf[0] == '\r' || buf[0] == '\n') break;
 
-       conv_code_converter_destroy(conv);
+       if (mimeinfo->mime_type == MIME_MESSAGE_RFC822) {
+               headers = textview_scan_header(textview, fp);
+               if (headers) {
+                       gtk_stext_freeze(text);
+                       gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
+                       textview_show_header(textview, headers);
+                       procheader_header_array_destroy(headers);
+                       gtk_stext_thaw(text);
+               }
+               return;
+       }
+
+       gtk_stext_freeze(text);
+
+#if USE_GPGME
+       if (mimeinfo->sigstatus)
+               g_snprintf(buf, sizeof(buf), "\n[%s (%s)]\n",
+                          mimeinfo->content_type, mimeinfo->sigstatus);
+       else
+#endif
+       if (mimeinfo->filename || mimeinfo->name)
+               g_snprintf(buf, sizeof(buf), "\n[%s  %s (%d bytes)]\n",
+                          mimeinfo->filename ? mimeinfo->filename :
+                          mimeinfo->name,
+                          mimeinfo->content_type, mimeinfo->size);
+       else
+               g_snprintf(buf, sizeof(buf), "\n[%s (%d bytes)]\n",
+                          mimeinfo->content_type, mimeinfo->size);
 
+       if (mimeinfo->mime_type != MIME_TEXT &&
+           mimeinfo->mime_type != MIME_TEXT_HTML &&
+           mimeinfo->mime_type != MIME_TEXT_ENRICHED) {
+               gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
+       } else {
+               if (!mimeinfo->main &&
+                   mimeinfo->parent &&
+                   mimeinfo->parent->children != mimeinfo)
+                       gtk_stext_insert(text, NULL, NULL, NULL, buf, -1);
+               else
+                       gtk_stext_insert(text, NULL, NULL, NULL, "\n", 1);
+               if (prefs_common.force_charset)
+                       charset = prefs_common.force_charset;
+               else if (mimeinfo->charset)
+                       charset = mimeinfo->charset;
+               textview_write_body(textview, mimeinfo, fp, charset);
+       }
+       
        gtk_stext_thaw(text);
 }
 
+static void textview_add_parts(TextView *textview, MimeInfo *mimeinfo, FILE *fp)
+{
+       gint level;
+
+       g_return_if_fail(mimeinfo != NULL);
+       g_return_if_fail(fp != NULL);
+
+       level = mimeinfo->level;
+
+       for (;;) {
+               textview_add_part(textview, mimeinfo, fp);
+               if (mimeinfo->parent && mimeinfo->parent->content_type &&
+                   !strcasecmp(mimeinfo->parent->content_type,
+                               "multipart/alternative"))
+                       mimeinfo = mimeinfo->parent->next;
+               else
+                       mimeinfo = procmime_mimeinfo_next(mimeinfo);
+               if (!mimeinfo || mimeinfo->level <= level)
+                       break;
+       }
+}
+
 #define TEXT_INSERT(str) \
        gtk_stext_insert(text, textview->msgfont, NULL, NULL, str, -1)
 
@@ -421,7 +555,7 @@ void textview_show_mime_part(TextView *textview, MimeInfo *partinfo)
        textview_set_font(textview, NULL);
        text = GTK_STEXT(textview->text);
        textview_clear(textview);
-
+       
        gtk_stext_freeze(text);
 
        TEXT_INSERT(_("To save this part, pop up the context menu with "));
@@ -431,6 +565,9 @@ void textview_show_mime_part(TextView *textview, MimeInfo *partinfo)
        TEXT_INSERT(_("To display this part as a text message, select "));
        TEXT_INSERT(_("`Display as text', or press `t' key.\n\n"));
 
+       TEXT_INSERT(_("To display this part as an image, select "));
+       TEXT_INSERT(_("`Display image', or press `i' key.\n\n"));
+
        TEXT_INSERT(_("To open this part with external program, select "));
        TEXT_INSERT(_("`Open' or `Open with...', "));
        TEXT_INSERT(_("or double-click, or click the center button, "));
@@ -459,13 +596,41 @@ void textview_show_signature_part(TextView *textview, MimeInfo *partinfo)
        } else {
                TEXT_INSERT(partinfo->sigstatus_full);
        }
-
+               
        gtk_stext_thaw(text);
 }
 #endif /* USE_GPGME */
 
 #undef TEXT_INSERT
 
+static void textview_write_body(TextView *textview, MimeInfo *mimeinfo,
+                               FILE *fp, const gchar *charset)
+{
+       FILE *tmpfp;
+       gchar buf[BUFFSIZE];
+       CodeConverter *conv;
+
+       conv = conv_code_converter_new(charset);
+
+       tmpfp = procmime_decode_content(NULL, fp, mimeinfo);
+       
+       textview->is_in_signature = FALSE;
+
+       if (tmpfp) {
+               
+               if (mimeinfo->mime_type == MIME_TEXT_HTML)
+                       textview_show_html(textview, tmpfp, conv);
+               else if (mimeinfo->mime_type == MIME_TEXT_ENRICHED)
+                       textview_show_ertf(textview, tmpfp, conv);
+               else
+                       while (fgets(buf, sizeof(buf), tmpfp) != NULL)
+                               textview_write_line(textview, buf, conv);
+               fclose(tmpfp);
+       }
+
+       conv_code_converter_destroy(conv);
+}
+
 static void textview_show_html(TextView *textview, FILE *fp,
                               CodeConverter *conv)
 {
@@ -501,6 +666,7 @@ static void textview_show_html(TextView *textview, FILE *fp,
                        textview_write_line(textview, str, NULL);
                }
        }
+       
        html_parser_destroy(parser);
 }
 
@@ -509,7 +675,6 @@ static void textview_show_ertf(TextView *textview, FILE *fp,
 {
        ERTFParser *parser;
        gchar *str;
-       gchar* url = NULL;
 
        parser = ertf_parser_new(fp, conv);
        g_return_if_fail(parser != NULL);
@@ -517,6 +682,7 @@ static void textview_show_ertf(TextView *textview, FILE *fp,
        while ((str = ertf_parse(parser)) != NULL) {
                textview_write_line(textview, str, NULL);
        }
+       
        ertf_parser_destroy(parser);
 }
 
@@ -569,7 +735,7 @@ static gchar *make_uri_string(const gchar *bp, const gchar *ep)
         (ch) > 32   && \
         (ch) != 127 && \
         !isspace(ch) && \
-        !strchr("()<>\"", (ch)))
+        !strchr("(),;<>\"", (ch)))
 
 /* alphabet and number within 7bit ASCII */
 #define IS_ASCII_ALNUM(ch)     (isascii(ch) && isalnum(ch))
@@ -748,6 +914,7 @@ static void textview_make_clickable_parts(TextView *textview,
        static struct table parser[] = {
                {"http://",  strcasestr, get_uri_part,   make_uri_string},
                {"https://", strcasestr, get_uri_part,   make_uri_string},
+               {"www.",     strcasestr, get_uri_part,   make_uri_string},
                {"ftp://",   strcasestr, get_uri_part,   make_uri_string},
                {"mailto:",  strcasestr, get_uri_part,   make_uri_string},
                {"@",        strcasestr, get_email_part, make_email_string}
@@ -841,6 +1008,7 @@ static void textview_write_link(TextView *textview, const gchar *url,
 
     /* this part is taken from textview_write_line. Right now the only place
      * that calls this function passes NULL for conv, but you never know. */
+#if 0
     if (!conv)
            strncpy2(buf, str, sizeof(buf));
     else if (conv_convert(conv, buf, sizeof(buf), str) < 0) {
@@ -851,7 +1019,14 @@ static void textview_write_link(TextView *textview, const gchar *url,
                            -1);
            return;
     }
+#endif
+
+    if (!conv || conv_convert(conv, buf, sizeof(buf), str) < 0)
+       strncpy2(buf, str, sizeof(buf));
 
+    strcrchomp(buf);
+    gtk_stext_insert(text, textview->msgfont, NULL, NULL, " ", 1);
     /* this part is based on the code in make_clickable_parts */
     if (prefs_common.enable_color) {
        link_color = &uri_color;
@@ -859,8 +1034,8 @@ static void textview_write_link(TextView *textview, const gchar *url,
     uri = g_new(RemoteURI, 1);
     uri->uri = g_strdup(url);
     uri->start = gtk_stext_get_point(text);
-    gtk_stext_insert(text, textview->msgfont, link_color, NULL, buf,
-                   strlen(buf));
+    gtk_stext_insert(text, textview->msgfont, link_color, NULL, str,
+                   strlen(str));
     uri->end = gtk_stext_get_point(text);
     textview->uri_list = g_slist_append(textview->uri_list, uri);
 }
@@ -873,6 +1048,7 @@ static void textview_write_line(TextView *textview, const gchar *str,
        GdkColor *fg_color;
        gint quotelevel = -1;
 
+#if 0
        if (!conv)
                strncpy2(buf, str, sizeof(buf));
        else if (conv_convert(conv, buf, sizeof(buf), str) < 0) {
@@ -883,6 +1059,9 @@ static void textview_write_line(TextView *textview, const gchar *str,
                                -1);
                return;
        }
+#endif
+       if (!conv || conv_convert(conv, buf, sizeof(buf), str) < 0)
+               strncpy2(buf, str, sizeof(buf));
 
        strcrchomp(buf);
        if (prefs_common.conv_mb_alnum) conv_mb_alnum(buf);
@@ -892,8 +1071,9 @@ static void textview_write_line(TextView *textview, const gchar *str,
           >, foo>, _> ... ok, <foo>, foo bar>, foo-> ... ng
           Up to 3 levels of quotations are detected, and each
           level is colored using a different color. */
-       if (prefs_common.enable_color && strchr(buf, '>')) {
-               quotelevel = get_quote_level(buf);
+       if (prefs_common.enable_color 
+           && line_has_quote_char(buf, prefs_common.quote_chars)) {
+               quotelevel = get_quote_level(buf, prefs_common.quote_chars);
 
                /* set up the correct foreground color */
                if (quotelevel > 2) {
@@ -910,6 +1090,11 @@ static void textview_write_line(TextView *textview, const gchar *str,
        else
                fg_color = &quote_colors[quotelevel];
 
+       if (prefs_common.enable_color && (strcmp(buf,"-- \n") == 0 || textview->is_in_signature)) {
+               fg_color = &signature_color;
+               textview->is_in_signature = TRUE;
+       }
+       
        if (prefs_common.head_space && spacingfont && buf[0] != '\n')
                gtk_stext_insert(text, spacingfont, NULL, NULL, " ", 1);
 
@@ -932,6 +1117,9 @@ void textview_clear(TextView *textview)
 
        textview_uri_list_remove_all(textview->uri_list);
        textview->uri_list = NULL;
+
+       textview->body_pos = 0;
+       textview->cur_pos  = 0;
 }
 
 void textview_destroy(TextView *textview)
@@ -944,17 +1132,19 @@ void textview_destroy(TextView *textview)
        if (!textview->scrolledwin_mb->parent)
                gtk_widget_destroy(textview->scrolledwin_mb);
 
-       if (textview->msgfont) {
-               textview->msgfont->ascent = textview->prev_ascent;
-               textview->msgfont->descent = textview->prev_descent;
+       if (textview->msgfont)
                gdk_font_unref(textview->msgfont);
-       }
        if (textview->boldfont)
                gdk_font_unref(textview->boldfont);
 
        g_free(textview);
 }
 
+void textview_set_all_headers(TextView *textview, gboolean all_headers)
+{
+       textview->show_all_headers = all_headers;
+}
+
 void textview_set_font(TextView *textview, const gchar *codeset)
 {
        gboolean use_fontset = TRUE;
@@ -1000,39 +1190,57 @@ void textview_set_font(TextView *textview, const gchar *codeset)
        }
 
        if (prefs_common.textfont) {
-               if (textview->msgfont) {
-                       textview->msgfont->ascent = textview->prev_ascent;
-                       textview->msgfont->descent = textview->prev_descent;
-                       gdk_font_unref(textview->msgfont);
-                       textview->msgfont = NULL;
-               }
-               if (use_fontset)
-                       textview->msgfont =
-                               gdk_fontset_load(prefs_common.textfont);
-               else {
+               GdkFont *font;
+
+               if (use_fontset) {
+                       if (text_mb_font) {
+                               text_mb_font->ascent = text_mb_font_orig_ascent;
+                               text_mb_font->descent = text_mb_font_orig_descent;
+                       }
+                       font = gdk_fontset_load(prefs_common.textfont);
+                       if (font && text_mb_font != font) {
+                               if (text_mb_font)
+                                       gdk_font_unref(text_mb_font);
+                               text_mb_font = font;
+                               text_mb_font_orig_ascent = font->ascent;
+                               text_mb_font_orig_descent = font->descent;
+                       }
+               } else {
+                       if (text_sb_font) {
+                               text_sb_font->ascent = text_sb_font_orig_ascent;
+                               text_sb_font->descent = text_sb_font_orig_descent;
+                       }
                        if (MB_CUR_MAX > 1) {
-                               FONT_LOAD(textview->msgfont,
-                                         "-*-courier-medium-r-normal--14-*-*-*-*-*-iso8859-1");
+                               FONT_LOAD(font, "-*-courier-medium-r-normal--14-*-*-*-*-*-iso8859-1");
                        } else {
-                               FONT_LOAD(textview->msgfont,
-                                         prefs_common.textfont);
+                               FONT_LOAD(font, prefs_common.textfont);
+                       }
+                       if (font && text_sb_font != font) {
+                               if (text_sb_font)
+                                       gdk_font_unref(text_sb_font);
+                               text_sb_font = font;
+                               text_sb_font_orig_ascent = font->ascent;
+                               text_sb_font_orig_descent = font->descent;
                        }
                }
 
-               if (textview->msgfont) {
+               if (font) {
                        gint ascent, descent;
 
-                       textview->prev_ascent = textview->msgfont->ascent;
-                       textview->prev_descent = textview->msgfont->descent;
                        descent = prefs_common.line_space / 2;
                        ascent  = prefs_common.line_space - descent;
-                       textview->msgfont->ascent  += ascent;
-                       textview->msgfont->descent += descent;
+                       font->ascent  += ascent;
+                       font->descent += descent;
+
+                       if (textview->msgfont)
+                               gdk_font_unref(textview->msgfont);
+                       textview->msgfont = font;
+                       gdk_font_ref(font);
                }
        }
 
-       if (!textview->boldfont)
-               FONT_LOAD(textview->boldfont, BOLD_FONT);
+       if (!textview->boldfont && prefs_common.boldfont)
+               FONT_LOAD(textview->boldfont, prefs_common.boldfont);
        if (!spacingfont)
                spacingfont = gdk_font_load("-*-*-medium-r-normal--6-*");
 }
@@ -1073,6 +1281,9 @@ static GPtrArray *textview_scan_header(TextView *textview, FILE *fp)
 
        g_return_val_if_fail(fp != NULL, NULL);
 
+       if (textview->show_all_headers)
+               return procheader_get_header_array_asis(fp);
+
        if (!prefs_common.display_header) {
                while (fgets(buf, sizeof(buf), fp) != NULL)
                        if (buf[0] == '\r' || buf[0] == '\n') break;
@@ -1109,9 +1320,10 @@ static GPtrArray *textview_scan_header(TextView *textview, FILE *fp)
                        header = g_ptr_array_index(headers, i);
                        g_ptr_array_add(sorted_headers, header);
                }
-       }
+               g_ptr_array_free(headers, TRUE);
+       } else
+               procheader_header_array_destroy(headers);
 
-       g_ptr_array_free(headers, FALSE);
 
        return sorted_headers;
 }
@@ -1161,9 +1373,7 @@ static void textview_show_header(TextView *textview, GPtrArray *headers)
                gtk_stext_insert(text, textview->msgfont, NULL, NULL, "\n", 1);
        }
 
-       gtk_stext_insert(text, textview->msgfont, NULL, NULL, "\n", 1);
        gtk_stext_thaw(text);
-       textview->body_pos = gtk_stext_get_length(text);
 }
 
 gboolean textview_search_string(TextView *textview, const gchar *str,
@@ -1194,17 +1404,18 @@ gboolean textview_search_string(TextView *textview, const gchar *str,
                if (text_len - pos < len) break;
                if (gtkut_stext_match_string(text, pos, wcs, len, case_sens)
                    == TRUE) {
+                       gtk_widget_hide(GTK_WIDGET(textview->scrolledwin));
                        gtk_editable_set_position(GTK_EDITABLE(text),
                                                  pos + len);
                        gtk_editable_select_region(GTK_EDITABLE(text),
                                                   pos, pos + len);
+                       gtk_widget_show(GTK_WIDGET(textview->scrolledwin));
                        textview_set_position(textview, pos + len);
                        found = TRUE;
                        break;
                }
                if (text_len - pos == len) break;
        }
-
        g_free(wcs);
        return found;
 }
@@ -1466,6 +1677,10 @@ static gint textview_key_pressed(GtkWidget *widget, GdkEventKey *event,
                textview_scroll_one_line(textview,
                                         (event->state & GDK_MOD1_MASK) != 0);
                break;
+       case GDK_Delete:
+               if (summaryview)
+                       summary_pass_key_press_event(summaryview, event);
+               break;
        case GDK_n:
        case GDK_N:
        case GDK_p:
@@ -1473,7 +1688,8 @@ static gint textview_key_pressed(GtkWidget *widget, GdkEventKey *event,
        case GDK_y:
        case GDK_t:
        case GDK_l:
-               if (messageview->type == MVIEW_MIME) {
+               if (messageview->type == MVIEW_MIME &&
+                   textview == messageview->mimeview->textview) {
                        KEY_PRESS_EVENT_STOP();
                        mimeview_pass_key_press_event(messageview->mimeview,
                                                      event);
@@ -1481,14 +1697,34 @@ static gint textview_key_pressed(GtkWidget *widget, GdkEventKey *event,
                }
                /* fall through */
        default:
-               if (summaryview)
-                       summary_pass_key_press_event(summaryview, event);
+               if (summaryview &&
+                   event->window != messageview->mainwin->window->window) {
+                       GdkEventKey tmpev = *event;
+
+                       tmpev.window = messageview->mainwin->window->window;
+                       KEY_PRESS_EVENT_STOP();
+                       gtk_widget_event(messageview->mainwin->window,
+                                        (GdkEvent *)&tmpev);
+               }
                break;
        }
 
        return TRUE;
 }
 
+static gint show_url_timeout_cb(gpointer data)
+{
+       TextView *textview = (TextView *)data;
+       
+       if (textview->messageview->mainwin)
+               if (textview->show_url_msgid)
+                       gtk_statusbar_remove(GTK_STATUSBAR(
+                               textview->messageview->mainwin->statusbar),
+                               textview->messageview->mainwin->folderview_cid,
+                               textview->show_url_msgid);
+               return FALSE;
+}
+
 static gint textview_button_pressed(GtkWidget *widget, GdkEventButton *event,
                                    TextView *textview)
 {
@@ -1504,7 +1740,7 @@ static gint textview_button_released(GtkWidget *widget, GdkEventButton *event,
                gtk_editable_get_position(GTK_EDITABLE(textview->text));
 
        if (event && 
-           ((event->button == 1 && textview->last_buttonpress == GDK_2BUTTON_PRESS)
+           ((event->button == 1)
             || event->button == 2 || event->button == 3)) {
                GSList *cur;
 
@@ -1520,10 +1756,28 @@ static gint textview_button_released(GtkWidget *widget, GdkEventButton *event,
 
                        if (textview->cur_pos >= uri->start &&
                            textview->cur_pos <  uri->end) {
+                               /* single click: display url in statusbar */
+                               if (event->button == 1 && textview->last_buttonpress != GDK_2BUTTON_PRESS) {
+                                       if (textview->messageview->mainwin) {
+                                               if (textview->show_url_msgid) {
+                                                       gtk_timeout_remove(textview->show_url_timeout_tag);
+                                                       gtk_statusbar_remove(GTK_STATUSBAR(
+                                                               textview->messageview->mainwin->statusbar),
+                                                               textview->messageview->mainwin->folderview_cid,
+                                                               textview->show_url_msgid);
+                                                       textview->show_url_msgid = 0;
+                                               }
+                                               textview->show_url_msgid = gtk_statusbar_push(
+                                                               GTK_STATUSBAR(textview->messageview->mainwin->statusbar),
+                                                               textview->messageview->mainwin->folderview_cid,
+                                                               uri->uri);
+                                               textview->show_url_timeout_tag = gtk_timeout_add( 4000, show_url_timeout_cb, textview );
+                                               gtkut_widget_wait_for_draw(textview->messageview->mainwin->hbox_stat);
+                                       }
+                               } else
                                if (!g_strncasecmp(uri->uri, "mailto:", 7)) {
                                        if (event->button == 3) {
                                                gchar *fromname, *fromaddress;
-                                               GdkEventButton tmpev;   
                                                
                                                /* extract url */
                                                fromaddress = g_strdup(uri->uri + 7);
@@ -1547,8 +1801,7 @@ static gint textview_button_released(GtkWidget *widget, GdkEventButton *event,
                                                        if (folder_item->prefs && folder_item->prefs->enable_default_account)
                                                                account = account_find_from_id(folder_item->prefs->default_account);
                                                }
-                                               compose_new_with_recipient
-                                                       (account, uri->uri + 7);
+                                               compose_new(account, uri->uri + 7, NULL);
                                        }
                                } else {
                                        open_uri(uri->uri,