Remove more markup from translatable strings
[claws.git] / src / textview.c
index c6e6b4a645e4546ca21552d2f2e14cd9a926b338..f074aea90952e87e6178c2a589ea5903648f244a 100644 (file)
@@ -1,6 +1,6 @@
 /*
- * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2007 Hiroyuki Yamamoto and the Claws Mail team
+ * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
+ * Copyright (C) 1999-2015 the Claws Mail team
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  *
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * 
  */
 
 #ifdef HAVE_CONFIG_H
 #  include "config.h"
+#include "claws-features.h"
 #endif
 
 #include "defs.h"
 #if HAVE_SYS_WAIT_H
 #include <sys/wait.h>
 #endif
-#if HAVE_LIBCOMPFACE
-#  include <compface.h>
-#endif
-
-#if HAVE_LIBCOMPFACE
-#define XPM_XFACE_HEIGHT       (HEIGHT + 3)  /* 3 = 1 header + 2 colors */
-#endif
 
 #include "main.h"
 #include "summaryview.h"
 #include "html.h"
 #include "enriched.h"
 #include "compose.h"
-#include "addressbook.h"
+#ifndef USE_NEW_ADDRBOOK
+       #include "addressbook.h"
+       #include "addrindex.h"
+#else
+       #include "addressbook-dbus.h"
+       #include "addressadd.h"
+#endif
 #include "displayheader.h"
 #include "account.h"
 #include "mimeview.h"
 #include "menu.h"
 #include "image_viewer.h"
 #include "filesel.h"
-#include "base64.h"
 #include "inputdialog.h"
 #include "timing.h"
 #include "tags.h"
-#include "addrindex.h"
+#include "manage_window.h"
+#include "folder_item_prefs.h"
+#include "hooks.h"
+#include "avatars.h"
 
 static GdkColor quote_colors[3] = {
        {(gulong)0, (gushort)0, (gushort)0, (gushort)0},
@@ -101,6 +102,27 @@ static GdkColor emphasis_color = {
        (gushort)0
 };
 
+static GdkColor diff_added_color = {
+       (gulong)0,
+       (gushort)0,
+       (gushort)0,
+       (gushort)0
+};
+
+static GdkColor diff_deleted_color = {
+       (gulong)0,
+       (gushort)0,
+       (gushort)0,
+       (gushort)0
+};
+
+static GdkColor diff_hunk_color = {
+       (gulong)0,
+       (gushort)0,
+       (gushort)0,
+       (gushort)0
+};
+
 static GdkCursor *hand_cursor = NULL;
 static GdkCursor *text_cursor = NULL;
 static GdkCursor *watch_cursor= NULL;
@@ -191,6 +213,8 @@ static void copy_uri_cb                             (GtkAction      *action,
                                                 TextView       *textview);
 static void add_uri_to_addrbook_cb             (GtkAction      *action,
                                                 TextView       *textview);
+static void reply_to_uri_cb                    (GtkAction      *action,
+                                                TextView       *textview);
 static void mail_to_uri_cb                     (GtkAction      *action,
                                                 TextView       *textview);
 static void copy_mail_to_uri_cb                        (GtkAction      *action,
@@ -212,6 +236,7 @@ static GtkActionEntry textview_mail_popup_entries[] =
 {
        {"TextviewPopupMail",                   NULL, "TextviewPopupMail" },
        {"TextviewPopupMail/Compose",           NULL, N_("Compose _new message"), NULL, NULL, G_CALLBACK(mail_to_uri_cb) },
+       {"TextviewPopupMail/ReplyTo",           NULL, N_("_Reply to this address"), NULL, NULL, G_CALLBACK(reply_to_uri_cb) },
        {"TextviewPopupMail/AddAB",             NULL, N_("Add to _Address book"), NULL, NULL, G_CALLBACK(add_uri_to_addrbook_cb) },
        {"TextviewPopupMail/Copy",              NULL, N_("Copy this add_ress"), NULL, NULL, G_CALLBACK(copy_mail_to_uri_cb) },
 };
@@ -230,8 +255,10 @@ static void scrolled_cb (GtkAdjustment *adj, TextView *textview)
 #  define HEIGHT 48
 #endif
        if (textview->image) {
+               GtkAllocation allocation;
                gint x, y, x1;
-               x1 = textview->text->allocation.width - WIDTH - 5;
+               gtk_widget_get_allocation(textview->text, &allocation);
+               x1 = allocation.width - WIDTH - 5;
                gtk_text_view_buffer_to_window_coords(
                        GTK_TEXT_VIEW(textview->text),
                        GTK_TEXT_WINDOW_TEXT, x1, 5, &x, &y);
@@ -314,41 +341,57 @@ TextView *textview_create(void)
        gtk_widget_show(vbox);
 
        
-       textview->link_action_group = cm_menu_create_action_group("TextviewPopupLink",
+       textview->ui_manager = gtk_ui_manager_new();
+       textview->link_action_group = cm_menu_create_action_group_full(textview->ui_manager,
+                       "TextviewPopupLink",
                        textview_link_popup_entries,
                        G_N_ELEMENTS(textview_link_popup_entries), (gpointer)textview);
-       textview->mail_action_group = cm_menu_create_action_group("TextviewPopupMail",
+       textview->mail_action_group = cm_menu_create_action_group_full(textview->ui_manager,
+                       "TextviewPopupMail",
                        textview_mail_popup_entries,
                        G_N_ELEMENTS(textview_mail_popup_entries), (gpointer)textview);
-       textview->file_action_group = cm_menu_create_action_group("TextviewPopupFile",
+       textview->file_action_group = cm_menu_create_action_group_full(textview->ui_manager,
+                       "TextviewPopupFile",
                        textview_file_popup_entries,
                        G_N_ELEMENTS(textview_file_popup_entries), (gpointer)textview);
 
-       MENUITEM_ADDUI("/Menus", "TextviewPopupLink", "TextviewPopupLink", GTK_UI_MANAGER_MENU)
-       MENUITEM_ADDUI("/Menus", "TextviewPopupMail", "TextviewPopupMail", GTK_UI_MANAGER_MENU)
-       MENUITEM_ADDUI("/Menus", "TextviewPopupFile", "TextviewPopupFile", GTK_UI_MANAGER_MENU)
-
-       MENUITEM_ADDUI("/Menus/TextviewPopupLink", "Open", "TextviewPopupLink/Open", GTK_UI_MANAGER_MENUITEM)
-       MENUITEM_ADDUI("/Menus/TextviewPopupLink", "Copy", "TextviewPopupLink/Copy", GTK_UI_MANAGER_MENUITEM)
-       MENUITEM_ADDUI("/Menus/TextviewPopupMail", "Compose", "TextviewPopupMail/Compose", GTK_UI_MANAGER_MENUITEM)
-       MENUITEM_ADDUI("/Menus/TextviewPopupMail", "AddAB", "TextviewPopupMail/AddAB", GTK_UI_MANAGER_MENUITEM)
-       MENUITEM_ADDUI("/Menus/TextviewPopupMail", "Copy", "TextviewPopupMail/Copy", GTK_UI_MANAGER_MENUITEM)
-       MENUITEM_ADDUI("/Menus/TextviewPopupFile", "Open", "TextviewPopupFile/Open", GTK_UI_MANAGER_MENUITEM)
-       MENUITEM_ADDUI("/Menus/TextviewPopupFile", "Save", "TextviewPopupFile/Save", GTK_UI_MANAGER_MENUITEM)
+       MENUITEM_ADDUI_MANAGER(textview->ui_manager, "/", "Menus", "Menus", GTK_UI_MANAGER_MENUBAR)
+       MENUITEM_ADDUI_MANAGER(textview->ui_manager, 
+                       "/Menus", "TextviewPopupLink", "TextviewPopupLink", GTK_UI_MANAGER_MENU)
+       MENUITEM_ADDUI_MANAGER(textview->ui_manager, 
+                       "/Menus", "TextviewPopupMail", "TextviewPopupMail", GTK_UI_MANAGER_MENU)
+       MENUITEM_ADDUI_MANAGER(textview->ui_manager, 
+                       "/Menus", "TextviewPopupFile", "TextviewPopupFile", GTK_UI_MANAGER_MENU)
+
+       MENUITEM_ADDUI_MANAGER(textview->ui_manager, 
+                       "/Menus/TextviewPopupLink", "Open", "TextviewPopupLink/Open", GTK_UI_MANAGER_MENUITEM)
+       MENUITEM_ADDUI_MANAGER(textview->ui_manager, 
+                       "/Menus/TextviewPopupLink", "Copy", "TextviewPopupLink/Copy", GTK_UI_MANAGER_MENUITEM)
+       MENUITEM_ADDUI_MANAGER(textview->ui_manager, 
+                       "/Menus/TextviewPopupMail", "Compose", "TextviewPopupMail/Compose", GTK_UI_MANAGER_MENUITEM)
+       MENUITEM_ADDUI_MANAGER(textview->ui_manager, 
+                       "/Menus/TextviewPopupMail", "ReplyTo", "TextviewPopupMail/ReplyTo", GTK_UI_MANAGER_MENUITEM)
+       MENUITEM_ADDUI_MANAGER(textview->ui_manager, 
+                       "/Menus/TextviewPopupMail", "AddAB", "TextviewPopupMail/AddAB", GTK_UI_MANAGER_MENUITEM)
+       MENUITEM_ADDUI_MANAGER(textview->ui_manager, 
+                       "/Menus/TextviewPopupMail", "Copy", "TextviewPopupMail/Copy", GTK_UI_MANAGER_MENUITEM)
+       MENUITEM_ADDUI_MANAGER(textview->ui_manager, 
+                       "/Menus/TextviewPopupFile", "Open", "TextviewPopupFile/Open", GTK_UI_MANAGER_MENUITEM)
+       MENUITEM_ADDUI_MANAGER(textview->ui_manager, 
+                       "/Menus/TextviewPopupFile", "Save", "TextviewPopupFile/Save", GTK_UI_MANAGER_MENUITEM)
 
        textview->link_popup_menu = gtk_menu_item_get_submenu(GTK_MENU_ITEM(
-                               gtk_ui_manager_get_widget(gtkut_ui_manager(), "/Menus/TextviewPopupLink")) );
+                               gtk_ui_manager_get_widget(textview->ui_manager, "/Menus/TextviewPopupLink")) );
        textview->mail_popup_menu = gtk_menu_item_get_submenu(GTK_MENU_ITEM(
-                               gtk_ui_manager_get_widget(gtkut_ui_manager(), "/Menus/TextviewPopupMail")) );
+                               gtk_ui_manager_get_widget(textview->ui_manager, "/Menus/TextviewPopupMail")) );
        textview->file_popup_menu = gtk_menu_item_get_submenu(GTK_MENU_ITEM(
-                               gtk_ui_manager_get_widget(gtkut_ui_manager(), "/Menus/TextviewPopupFile")) );
+                               gtk_ui_manager_get_widget(textview->ui_manager, "/Menus/TextviewPopupFile")) );
 
        textview->vbox               = vbox;
        textview->scrolledwin        = scrolledwin;
        textview->text               = text;
        textview->uri_list           = NULL;
        textview->body_pos           = 0;
-       textview->show_all_headers   = FALSE;
        textview->last_buttonpress   = GDK_NOTHING;
        textview->image              = NULL;
        return textview;
@@ -358,10 +401,16 @@ static void textview_create_tags(GtkTextView *text, TextView *textview)
 {
        GtkTextBuffer *buffer;
        GtkTextTag *tag, *qtag;
+#if !GTK_CHECK_VERSION(3, 0, 0)
        static GdkColor yellow, black;
        static gboolean color_init = FALSE;
+#else
+       static GdkColor yellow = { (guint32)0, (guint16)0xf5, (guint16)0xf6, (guint16)0xbe };
+       static GdkColor black = { (guint32)0, (guint16)0x0, (guint16)0x0, (guint16)0x0 };
+#endif
        static PangoFontDescription *font_desc, *bold_font_desc;
        
+#if !GTK_CHECK_VERSION(3, 0, 0)
        if (!color_init) {
                gdk_color_parse("#f5f6be", &yellow);
                gdk_color_parse("#000000", &black);
@@ -370,6 +419,7 @@ static void textview_create_tags(GtkTextView *text, TextView *textview)
                color_init &= gdk_colormap_alloc_color(
                        gdk_colormap_get_system(), &black, FALSE, TRUE);
        }
+#endif
 
        if (!font_desc)
                font_desc = pango_font_description_from_string
@@ -437,16 +487,10 @@ static void textview_create_tags(GtkTextView *text, TextView *textview)
                                "foreground-gdk", &quote_colors[2],
                                NULL);
        }
-#if GTK_CHECK_VERSION(2, 8, 0)
        gtk_text_buffer_create_tag(buffer, "tags",
                        "foreground-gdk", &black,
                        "paragraph-background-gdk", &yellow,
                        NULL);
-#else
-       gtk_text_buffer_create_tag(buffer, "tags",
-                       "foreground-gdk", &emphasis_color,
-                       NULL);
-#endif
        gtk_text_buffer_create_tag(buffer, "emphasis",
                        "foreground-gdk", &emphasis_color,
                        NULL);
@@ -461,6 +505,24 @@ static void textview_create_tags(GtkTextView *text, TextView *textview)
        gtk_text_buffer_create_tag(buffer, "link-hover",
                        "underline", PANGO_UNDERLINE_SINGLE,
                        NULL);
+       gtk_text_buffer_create_tag(buffer, "diff-add",
+                       "foreground-gdk", &diff_added_color,
+                       NULL);
+       gtk_text_buffer_create_tag(buffer, "diff-del",
+                       "foreground-gdk", &diff_deleted_color,
+                       NULL);
+       gtk_text_buffer_create_tag(buffer, "diff-add-file",
+                       "foreground-gdk", &diff_added_color,
+                       "weight", PANGO_WEIGHT_BOLD,
+                       NULL);
+       gtk_text_buffer_create_tag(buffer, "diff-del-file",
+                       "foreground-gdk", &diff_deleted_color,
+                       "weight", PANGO_WEIGHT_BOLD,
+                       NULL);
+       gtk_text_buffer_create_tag(buffer, "diff-hunk",
+                       "foreground-gdk", &diff_hunk_color,
+                       "weight", PANGO_WEIGHT_BOLD,
+                       NULL);
        g_signal_connect(G_OBJECT(qtag), "event",
                          G_CALLBACK(textview_uri_button_pressed), textview);
        g_signal_connect(G_OBJECT(tag), "event",
@@ -481,24 +543,15 @@ void textview_init(TextView *textview)
                watch_cursor = gdk_cursor_new(GDK_WATCH);
 
        textview_reflect_prefs(textview);
-       textview_set_all_headers(textview, FALSE);
        textview_set_font(textview, NULL);
        textview_create_tags(GTK_TEXT_VIEW(textview->text), textview);
 }
 
-#if GTK_CHECK_VERSION(2, 8, 0)
  #define CHANGE_TAG_COLOR(tagname, colorfg, colorbg) { \
        tag = gtk_text_tag_table_lookup(tags, tagname); \
        if (tag) \
                g_object_set(G_OBJECT(tag), "foreground-gdk", colorfg, "paragraph-background-gdk", colorbg, NULL); \
  }
-#else
- #define CHANGE_TAG_COLOR(tagname, colorfg, colorbg) { \
-       tag = gtk_text_tag_table_lookup(tags, tagname); \
-       if (tag) \
-               g_object_set(G_OBJECT(tag), "foreground-gdk", colorfg, NULL); \
- }
-#endif
 
 static void textview_update_message_colors(TextView *textview)
 {
@@ -509,8 +562,9 @@ static void textview_update_message_colors(TextView *textview)
        GtkTextTag *tag = NULL;
 
        quote_bgcolors[0] = quote_bgcolors[1] = quote_bgcolors[2] = black;
-       quote_colors[0] = quote_colors[1] = quote_colors[2] = 
-               uri_color = emphasis_color = signature_color = black;
+       quote_colors[0] = quote_colors[1] = quote_colors[2] = black;
+       uri_color = emphasis_color = signature_color = diff_added_color =
+               diff_deleted_color = diff_hunk_color = black;
 
        if (prefs_common.enable_color) {
                /* grab the quote colors, converting from an int to a GdkColor */
@@ -526,6 +580,12 @@ static void textview_update_message_colors(TextView *textview)
                                               &signature_color);
                gtkut_convert_int_to_gdk_color(prefs_common.emphasis_col,
                                               &emphasis_color);
+               gtkut_convert_int_to_gdk_color(prefs_common.diff_added_color,
+                                              &diff_added_color);
+               gtkut_convert_int_to_gdk_color(prefs_common.diff_deleted_color,
+                                              &diff_deleted_color);
+               gtkut_convert_int_to_gdk_color(prefs_common.diff_hunk_color,
+                                              &diff_hunk_color);
        }
        if (prefs_common.enable_color && prefs_common.enable_bgcolor) {
                gtkut_convert_int_to_gdk_color(prefs_common.quote_level1_bgcol,
@@ -547,6 +607,11 @@ static void textview_update_message_colors(TextView *textview)
        CHANGE_TAG_COLOR("signature", &signature_color, NULL);
        CHANGE_TAG_COLOR("link", &uri_color, NULL);
        CHANGE_TAG_COLOR("link-hover", &uri_color, NULL);
+       CHANGE_TAG_COLOR("diff-add", &diff_added_color, NULL);
+       CHANGE_TAG_COLOR("diff-del", &diff_deleted_color, NULL);
+       CHANGE_TAG_COLOR("diff-add-file", &diff_added_color, NULL);
+       CHANGE_TAG_COLOR("diff-del-file", &diff_deleted_color, NULL);
+       CHANGE_TAG_COLOR("diff-hunk", &diff_hunk_color, NULL);
 }
 #undef CHANGE_TAG_COLOR
 
@@ -561,42 +626,34 @@ void textview_reflect_prefs(TextView *textview)
 void textview_show_part(TextView *textview, MimeInfo *mimeinfo, FILE *fp)
 {
        START_TIMING("");
-       g_return_if_fail(mimeinfo != NULL);
-       g_return_if_fail(fp != NULL);
+       cm_return_if_fail(mimeinfo != NULL);
+       cm_return_if_fail(fp != NULL);
 
-       if ((mimeinfo->type == MIMETYPE_MULTIPART) ||
-           ((mimeinfo->type == MIMETYPE_MESSAGE) && !g_ascii_strcasecmp(mimeinfo->subtype, "rfc822"))) {
-               textview->loading = TRUE;
-               textview->stop_loading = FALSE;
-               
-               textview_clear(textview);
-               textview_add_parts(textview, mimeinfo);
-
-               textview->loading = FALSE;
-               textview->stop_loading = FALSE;
-               END_TIMING();
-               return;
-       }
        textview->loading = TRUE;
        textview->stop_loading = FALSE;
 
-       if (fseek(fp, mimeinfo->offset, SEEK_SET) < 0)
-               perror("fseek");
-
        textview_clear(textview);
 
-       if (mimeinfo->type == MIMETYPE_MULTIPART)
+       if (mimeinfo->type == MIMETYPE_MULTIPART ||
+           (mimeinfo->type == MIMETYPE_MESSAGE && !g_ascii_strcasecmp(mimeinfo->subtype, "rfc822"))) {
                textview_add_parts(textview, mimeinfo);
-       else
+       } else {
+               if (fseek(fp, mimeinfo->offset, SEEK_SET) < 0)
+                       perror("fseek");
+
                textview_write_body(textview, mimeinfo);
+       }
 
        textview->loading = FALSE;
        textview->stop_loading = FALSE;
+       textview_set_position(textview, 0);
+
        END_TIMING();
 }
 
 static void textview_add_part(TextView *textview, MimeInfo *mimeinfo)
 {
+       GtkAllocation allocation;
        GtkTextView *text;
        GtkTextBuffer *buffer;
        GtkTextIter iter, start_iter;
@@ -605,9 +662,10 @@ static void textview_add_part(TextView *textview, MimeInfo *mimeinfo)
        const gchar *name;
        gchar *content_type;
        gint charcount;
+
        START_TIMING("");
 
-       g_return_if_fail(mimeinfo != NULL);
+       cm_return_if_fail(mimeinfo != NULL);
        text = GTK_TEXT_VIEW(textview->text);
        buffer = gtk_text_view_get_buffer(text);
        charcount = gtk_text_buffer_get_char_count(buffer);
@@ -634,7 +692,12 @@ static void textview_add_part(TextView *textview, MimeInfo *mimeinfo)
                        END_TIMING();
                        return;
                }
-               fseek(fp, mimeinfo->offset, SEEK_SET);
+               if (fseek(fp, mimeinfo->offset, SEEK_SET) < 0) {
+                       FILE_OP_ERROR(mimeinfo->data.filename, "fseek");
+                       fclose(fp);
+                       END_TIMING();
+                       return;
+               }
                headers = textview_scan_header(textview, fp);
                if (headers) {
                        if (charcount > 0)
@@ -673,8 +736,6 @@ static void textview_add_part(TextView *textview, MimeInfo *mimeinfo)
                if (mimeinfo->type == MIMETYPE_IMAGE  &&
                    prefs_common.inline_img ) {
                        GdkPixbuf *pixbuf;
-                       gint avail_width;
-                       gint avail_height;
                        GError *error = NULL;
                        gchar *filename;
                        ClickableText *uri;
@@ -685,28 +746,18 @@ static void textview_add_part(TextView *textview, MimeInfo *mimeinfo)
                        filename = procmime_get_tmp_file_name(mimeinfo);
 
                        if ((err = procmime_get_part(filename, mimeinfo)) < 0) {
-                               g_warning("Can't get the image file.(%s)", strerror(-err));
+                               g_warning("Can't get the image file.(%s)", g_strerror(-err));
                                g_free(filename);
                                END_TIMING();
                                return;
                        }
 
-                       if (!prefs_common.resize_img) {
-                               pixbuf = gdk_pixbuf_new_from_file(filename, &error);
-                       } else {
-                               gint w, h;
-                               gdk_pixbuf_get_file_info(filename, &w, &h);
-                               avail_width = textview->scrolledwin->allocation.width;
-                               avail_height = textview->scrolledwin->allocation.height;
-                               if (avail_width - 100 > 0 &&
-                                   (w > avail_width || h > avail_height))
-                                       pixbuf = gdk_pixbuf_new_from_file_at_scale(filename, 
-                                               avail_width, avail_height, TRUE, &error);
-                               else
-                                       pixbuf = gdk_pixbuf_new_from_file(filename, &error);
+                       pixbuf = gdk_pixbuf_new_from_file(filename, &error);
+                       if (textview->stop_loading) {
+                               return;
                        }
                        if (error != NULL) {
-                               g_warning("%s\n", error->message);
+                               g_warning("%s", error->message);
                                g_error_free(error);
                        }
                        if (!pixbuf) {
@@ -716,6 +767,15 @@ static void textview_add_part(TextView *textview, MimeInfo *mimeinfo)
                                return;
                        }
 
+                       gtk_widget_get_allocation(textview->scrolledwin, &allocation);
+                       pixbuf = claws_load_pixbuf_fitting(pixbuf,
+                                       allocation.width,
+                                       allocation.height);
+
+                       if (textview->stop_loading) {
+                               return;
+                       }
+
                        uri_str = g_filename_to_uri(filename, NULL, NULL);
                        if (uri_str) {
                                uri = g_new0(ClickableText, 1);
@@ -723,7 +783,10 @@ static void textview_add_part(TextView *textview, MimeInfo *mimeinfo)
                                uri->start = gtk_text_iter_get_offset(&iter);
                                
                                gtk_text_buffer_insert_pixbuf(buffer, &iter, pixbuf);
-                               
+                               if (textview->stop_loading) {
+                                       g_free(uri);
+                                       return;
+                               }
                                uri->end = uri->start + 1;
                                uri->filename = procmime_get_part_file_name(mimeinfo);
                                textview->uri_list =
@@ -735,6 +798,9 @@ static void textview_add_part(TextView *textview, MimeInfo *mimeinfo)
                                                &start_iter, &iter);
                        } else {
                                gtk_text_buffer_insert_pixbuf(buffer, &iter, pixbuf);
+                               if (textview->stop_loading) {
+                                       return;
+                               }
                                gtk_text_buffer_insert(buffer, &iter, " ", 1);
                        }
 
@@ -747,7 +813,17 @@ static void textview_add_part(TextView *textview, MimeInfo *mimeinfo)
                if (prefs_common.display_header && (charcount > 0))
                        gtk_text_buffer_insert(buffer, &iter, "\n", 1);
 
+               if (!gtk_text_buffer_get_mark(buffer, "body_start")) {
+                       gtk_text_buffer_get_end_iter(buffer, &iter);
+                       gtk_text_buffer_create_mark(buffer, "body_start", &iter, TRUE);
+               }
+
                textview_write_body(textview, mimeinfo);
+
+               if (!gtk_text_buffer_get_mark(buffer, "body_end")) {
+                       gtk_text_buffer_get_end_iter(buffer, &iter);
+                       gtk_text_buffer_create_mark(buffer, "body_end", &iter, TRUE);
+               }
        }
        END_TIMING();
 }
@@ -817,7 +893,7 @@ static void recursive_add_parts(TextView *textview, GNode *node)
 
 static void textview_add_parts(TextView *textview, MimeInfo *mimeinfo)
 {
-       g_return_if_fail(mimeinfo != NULL);
+       cm_return_if_fail(mimeinfo != NULL);
         
         recursive_add_parts(textview, mimeinfo->node);
 }
@@ -840,10 +916,27 @@ void textview_show_error(TextView *textview)
                      "  This is probably due to a network error.\n"
                      "\n"
                      "  Use "));
-       TEXTVIEW_INSERT_LINK(_("'View Log'"), "sc://view_log", NULL);
+       TEXTVIEW_INSERT_LINK(_("'Network Log'"), "sc://view_log", NULL);
        TEXTVIEW_INSERT(_(" in the Tools menu for more information."));
        textview_show_icon(textview, GTK_STOCK_DIALOG_ERROR);
+}
+
+void textview_show_info(TextView *textview, const gchar *info_str)
+{
+       GtkTextView *text;
+       GtkTextBuffer *buffer;
+       GtkTextIter iter;
+
+       textview_set_font(textview, NULL);
+       textview_clear(textview);
+
+       text = GTK_TEXT_VIEW(textview->text);
+       buffer = gtk_text_view_get_buffer(text);
+       gtk_text_buffer_get_start_iter(buffer, &iter);
 
+       TEXTVIEW_INSERT(info_str);
+       textview_show_icon(textview, GTK_STOCK_DIALOG_INFO);
+       textview_cursor_normal(textview);
 }
 
 void textview_show_mime_part(TextView *textview, MimeInfo *partinfo)
@@ -852,10 +945,16 @@ void textview_show_mime_part(TextView *textview, MimeInfo *partinfo)
        GtkTextBuffer *buffer;
        GtkTextIter iter;
        const gchar *name;
-       gchar *content_type;
+       gchar *content_type, *shortcut;
+       GtkUIManager *ui_manager;
 
        if (!partinfo) return;
 
+       if (textview->messageview->window != NULL)
+               ui_manager = textview->messageview->ui_manager;
+       else
+               ui_manager = textview->messageview->mainwin->ui_manager;
+
        textview_set_font(textview, NULL);
        textview_clear(textview);
 
@@ -890,7 +989,11 @@ void textview_show_mime_part(TextView *textview, MimeInfo *partinfo)
        TEXTVIEW_INSERT(_("     - To save, select "));
        TEXTVIEW_INSERT_LINK(_("'Save as...'"), "sc://save_as", NULL);
 #ifndef GENERIC_UMPC
-       TEXTVIEW_INSERT(_(" (Shortcut key: 'y')"));
+       TEXTVIEW_INSERT(_(" (Shortcut key: '"));
+       shortcut = cm_menu_item_get_shortcut(ui_manager, "Menu/File/SavePartAs");
+       TEXTVIEW_INSERT(shortcut);
+       g_free(shortcut);
+       TEXTVIEW_INSERT("')");
 #endif
        TEXTVIEW_INSERT("\n");
 
@@ -898,7 +1001,11 @@ void textview_show_mime_part(TextView *textview, MimeInfo *partinfo)
        TEXTVIEW_INSERT_LINK(_("'Display as text'"), "sc://display_as_text", NULL);
 
 #ifndef GENERIC_UMPC
-       TEXTVIEW_INSERT(_(" (Shortcut key: 't')"));
+       TEXTVIEW_INSERT(_(" (Shortcut key: '"));
+       shortcut = cm_menu_item_get_shortcut(ui_manager, "Menu/View/Part/AsText");
+       TEXTVIEW_INSERT(shortcut);
+       g_free(shortcut);
+       TEXTVIEW_INSERT("')");
 #endif
        TEXTVIEW_INSERT("\n");
 
@@ -906,12 +1013,22 @@ void textview_show_mime_part(TextView *textview, MimeInfo *partinfo)
        TEXTVIEW_INSERT_LINK(_("'Open'"), "sc://open", NULL);
 
 #ifndef GENERIC_UMPC
-       TEXTVIEW_INSERT(_(" (Shortcut key: 'l')\n"));
+       TEXTVIEW_INSERT(_(" (Shortcut key: '"));
+       shortcut = cm_menu_item_get_shortcut(ui_manager, "Menu/View/Part/Open");
+       TEXTVIEW_INSERT(shortcut);
+       g_free(shortcut);
+       TEXTVIEW_INSERT("')\n");
        TEXTVIEW_INSERT(_("       (alternately double-click, or click the middle "));
        TEXTVIEW_INSERT(_("mouse button)\n"));
+#ifndef G_OS_WIN32
        TEXTVIEW_INSERT(_("     - Or use "));
        TEXTVIEW_INSERT_LINK(_("'Open with...'"), "sc://open_with", NULL);
-       TEXTVIEW_INSERT(_(" (Shortcut key: 'o')"));
+       TEXTVIEW_INSERT(_(" (Shortcut key: '"));
+       shortcut = cm_menu_item_get_shortcut(ui_manager, "Menu/View/Part/OpenWith");
+       TEXTVIEW_INSERT(shortcut);
+       g_free(shortcut);
+       TEXTVIEW_INSERT("')");
+#endif
 #endif
        TEXTVIEW_INSERT("\n");
 
@@ -931,9 +1048,16 @@ static void textview_write_body(TextView *textview, MimeInfo *mimeinfo)
        if (textview->messageview->forced_charset)
                charset = textview->messageview->forced_charset;
        else {
+               /* use supersets transparently when possible */
                charset = procmime_mimeinfo_get_parameter(mimeinfo, "charset");
                if (charset && !strcasecmp(charset, CS_ISO_8859_1))
                        charset = CS_WINDOWS_1252;
+               else if (charset && !strcasecmp(charset, CS_X_GBK))
+                       charset = CS_GB18030;
+               else if (charset && !strcasecmp(charset, CS_GBK))
+                       charset = CS_GB18030;
+               else if (charset && !strcasecmp(charset, CS_GB2312))
+                       charset = CS_GB18030;
        }
 
        textview_set_font(textview, charset);
@@ -943,6 +1067,7 @@ static void textview_write_body(TextView *textview, MimeInfo *mimeinfo)
        procmime_force_encoding(textview->messageview->forced_encoding);
        
        textview->is_in_signature = FALSE;
+       textview->is_diff = FALSE;
 
        procmime_decode_content(mimeinfo);
 
@@ -953,8 +1078,10 @@ static void textview_write_body(TextView *textview, MimeInfo *mimeinfo)
                filename = procmime_get_tmp_file_name(mimeinfo);
                if (procmime_get_part(filename, mimeinfo) == 0) {
                        tmpfp = g_fopen(filename, "rb");
-                       textview_show_html(textview, tmpfp, conv);
-                       fclose(tmpfp);
+                       if (tmpfp) {
+                               textview_show_html(textview, tmpfp, conv);
+                               fclose(tmpfp);
+                       }
                        claws_unlink(filename);
                }
                g_free(filename);
@@ -964,8 +1091,10 @@ static void textview_write_body(TextView *textview, MimeInfo *mimeinfo)
                filename = procmime_get_tmp_file_name(mimeinfo);
                if (procmime_get_part(filename, mimeinfo) == 0) {
                        tmpfp = g_fopen(filename, "rb");
-                       textview_show_ertf(textview, tmpfp, conv);
-                       fclose(tmpfp);
+                       if (tmpfp) {
+                               textview_show_ertf(textview, tmpfp, conv);
+                               fclose(tmpfp);
+                       }
                        claws_unlink(filename);
                }
                g_free(filename);
@@ -985,14 +1114,14 @@ static void textview_write_body(TextView *textview, MimeInfo *mimeinfo)
 
                if (pipe(pfd) < 0) {
                        g_snprintf(buf, sizeof(buf),
-                               "pipe failed for textview\n\n%s\n", strerror(errno));
+                               "pipe failed for textview\n\n%s\n", g_strerror(errno));
                        textview_write_line(textview, buf, conv, TRUE);
                        goto textview_default;
                }
                pid = fork();
                if (pid < 0) {
                        g_snprintf(buf, sizeof(buf),
-                               "fork failed for textview\n\n%s\n", strerror(errno));
+                               "fork failed for textview\n\n%s\n", g_strerror(errno));
                        textview_write_line(textview, buf, conv, TRUE);
                        close(pfd[0]);
                        close(pfd[1]);
@@ -1004,7 +1133,7 @@ static void textview_write_body(TextView *textview, MimeInfo *mimeinfo)
                        argv = strsplit_with_quote(buf, " ", 0);
                        close(1);
                        close(pfd[0]);
-                       dup(pfd[1]);
+                       rc = dup(pfd[1]);
                        rc = execvp(argv[0], argv);
                        close(pfd[1]);
                        g_print(_("The command to view attachment "
@@ -1021,17 +1150,21 @@ static void textview_write_body(TextView *textview, MimeInfo *mimeinfo)
                        if (textview->stop_loading) {
                                fclose(tmpfp);
                                waitpid(pid, pfd, 0);
-                               unlink(fname);
+                               g_unlink(fname);
                                return;
                        }
                }
 
                fclose(tmpfp);
                waitpid(pid, pfd, 0);
-               unlink(fname);
+               g_unlink(fname);
 #endif
        } else {
 textview_default:
+               if (!g_ascii_strcasecmp(mimeinfo->subtype, "x-patch")
+                               || !g_ascii_strcasecmp(mimeinfo->subtype, "x-diff"))
+                       textview->is_diff = TRUE;
+
                if (mimeinfo->content == MIMECONTENT_MEM)
                        tmpfp = str_open_as_stream(mimeinfo->data.mem);
                else
@@ -1040,7 +1173,11 @@ textview_default:
                        FILE_OP_ERROR(mimeinfo->data.filename, "fopen");
                        return;
                }
-               fseek(tmpfp, mimeinfo->offset, SEEK_SET);
+               if (fseek(tmpfp, mimeinfo->offset, SEEK_SET) < 0) {
+                       FILE_OP_ERROR(mimeinfo->data.filename, "fseek");
+                       fclose(tmpfp);
+                       return;
+               }
                debug_print("Viewing text content of type: %s (length: %d)\n", mimeinfo->subtype, mimeinfo->length);
                while (((i = ftell(tmpfp)) < mimeinfo->offset + mimeinfo->length) &&
                       (fgets(buf, sizeof(buf), tmpfp) != NULL)
@@ -1094,7 +1231,7 @@ static void textview_show_html(TextView *textview, FILE *fp,
        gint lines = 0;
 
        parser = sc_html_parser_new(fp, conv);
-       g_return_if_fail(parser != NULL);
+       cm_return_if_fail(parser != NULL);
 
        while ((str = sc_html_parse(parser)) != NULL) {
                if (parser->state == SC_HTML_HREF) {
@@ -1135,7 +1272,7 @@ static void textview_show_ertf(TextView *textview, FILE *fp,
        gint lines = 0;
 
        parser = ertf_parser_new(fp, conv);
-       g_return_if_fail(parser != NULL);
+       cm_return_if_fail(parser != NULL);
 
        while ((str = ertf_parse(parser)) != NULL) {
                textview_write_line(textview, str, NULL, FALSE);
@@ -1156,7 +1293,7 @@ static void textview_show_ertf(TextView *textview, FILE *fp,
                last->bp = (bp_); last->ep = (ep_); last->pti = (pti_); \
                last->next = NULL; \
        } else { \
-               g_warning("alloc error scanning URIs\n"); \
+               g_warning("alloc error scanning URIs"); \
                gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, \
                                                         linebuf, -1, \
                                                         fg_tag, NULL); \
@@ -1169,7 +1306,7 @@ static void textview_show_ertf(TextView *textview, FILE *fp,
                last->bp = (bp_); last->ep = (ep_); last->pti = (pti_); \
                last->next = NULL; \
        } else { \
-               g_warning("alloc error scanning URIs\n"); \
+               g_warning("alloc error scanning URIs"); \
        }
 
 /* textview_make_clickable_parts() - colorizes clickable parts */
@@ -1207,6 +1344,7 @@ static void textview_make_clickable_parts(TextView *textview,
                {"https://", strcasestr, get_uri_part,   make_uri_string},
                {"ftp://",   strcasestr, get_uri_part,   make_uri_string},
                {"sftp://",  strcasestr, get_uri_part,   make_uri_string},
+               {"gopher://",strcasestr, get_uri_part,   make_uri_string},
                {"www.",     strcasestr, get_uri_part,   make_http_string},
                {"mailto:",  strcasestr, get_uri_part,   make_uri_string},
                {"@",        strcasestr, get_email_part, make_email_string}
@@ -1231,7 +1369,7 @@ static void textview_make_clickable_parts(TextView *textview,
        gtk_text_buffer_get_end_iter(buffer, &iter);
 
        /* parse for clickable parts, and build a list of begin and end positions  */
-       for (walk = mybuf, n = 0;;) {
+       for (walk = mybuf;;) {
                gint last_index = PARSE_ELEMS;
                gchar *scanpos = NULL;
 
@@ -1351,7 +1489,7 @@ static void textview_make_clickable_parts_later(TextView *textview,
        offset = gtk_text_iter_get_offset(&start_iter);
 
        /* parse for clickable parts, and build a list of begin and end positions  */
-       for (walk = mybuf, n = 0;;) {
+       for (walk = mybuf;;) {
                gint last_index = PARSE_ELEMS;
                gchar *scanpos = NULL;
 
@@ -1472,10 +1610,25 @@ static void textview_write_line(TextView *textview, const gchar *str,
                fg_color = quote_tag_str;
        }
 
-       if (prefs_common.enable_color && 
-           (strcmp(buf,"-- \n") == 0 || strcmp(buf, "- -- \n") == 0 || textview->is_in_signature)) {
-               fg_color = "signature";
-               textview->is_in_signature = TRUE;
+       if (prefs_common.enable_color) {
+               if (textview->is_diff) {
+                       if (strncmp(buf, "+++ ", 4) == 0)
+                               fg_color = "diff-add-file";
+                       else if (buf[0] == '+')
+                               fg_color = "diff-add";
+                       else if (strncmp(buf, "--- ", 4) == 0)
+                               fg_color = "diff-del-file";
+                       else if (buf[0] == '-')
+                               fg_color = "diff-del";
+                       else if (strncmp(buf, "@@ ", 3) == 0 &&
+                                       strcmp(buf+strlen(buf)-4, " @@\n") == 0)
+                               fg_color = "diff-hunk";
+               } else if (strcmp(buf,"-- \n") == 0
+                               || strcmp(buf, "- -- \n") == 0
+                               || textview->is_in_signature) {
+                       fg_color = "signature";
+                       textview->is_in_signature = TRUE;
+               }
        }
 
        if (real_quotelevel > -1 && do_quote_folding) {
@@ -1492,6 +1645,7 @@ do_quote:
                        uri = g_new0(ClickableText, 1);
                        uri->uri = g_strdup("");
                        uri->data = g_strdup(buf);
+                       uri->data_len = strlen(uri->data);
                        uri->start = gtk_text_iter_get_offset(&iter);
                        uri->is_quote = TRUE;
                        uri->quote_level = real_quotelevel;
@@ -1518,16 +1672,19 @@ do_quote:
                        } else {
                                g_print("oops (%d %d)\n",
                                        real_quotelevel, textview->prev_quote_level);
-                       }               
-                       if (lasturi->is_quote == FALSE) {
-                               textview->prev_quote_level = -1;
-                               goto do_quote;
+                       }       
+                       if (lasturi) {  
+                               if (lasturi->is_quote == FALSE) {
+                                       textview->prev_quote_level = -1;
+                                       goto do_quote;
+                               }
+                               e_len = lasturi->data ? lasturi->data_len:0;
+                               n_len = strlen(buf);
+                               lasturi->data = g_realloc((gchar *)lasturi->data, e_len + n_len + 1);
+                               strcpy((gchar *)lasturi->data + e_len, buf);
+                               *((gchar *)lasturi->data + e_len + n_len) = '\0';
+                               lasturi->data_len += n_len;
                        }
-                       e_len = lasturi->data ? strlen(lasturi->data):0;
-                       n_len = strlen(buf);
-                       lasturi->data = g_realloc((gchar *)lasturi->data, e_len + n_len + 1);
-                       strcpy((gchar *)lasturi->data + e_len, buf);
-                       *((gchar *)lasturi->data + e_len + n_len) = '\0';
                }
        } else {
                textview_make_clickable_parts(textview, fg_color, "link", buf, FALSE);
@@ -1538,7 +1695,6 @@ do_quote:
 void textview_write_link(TextView *textview, const gchar *str,
                         const gchar *uri, CodeConverter *conv)
 {
-       GdkColor *link_color = NULL;
        GtkTextView *text;
        GtkTextBuffer *buffer;
        GtkTextIter iter;
@@ -1579,9 +1735,6 @@ void textview_write_link(TextView *textview, const gchar *str,
        if (bufp > buf)
                gtk_text_buffer_insert(buffer, &iter, buf, bufp - buf);
 
-       if (prefs_common.enable_color) {
-               link_color = &uri_color;
-       }
        r_uri = g_new0(ClickableText, 1);
        r_uri->uri = g_strdup(uri);
        r_uri->start = gtk_text_iter_get_offset(&iter);
@@ -1606,6 +1759,10 @@ void textview_clear(TextView *textview)
 
        buffer = gtk_text_view_get_buffer(text);
        gtk_text_buffer_set_text(buffer, "", -1);
+       if (gtk_text_buffer_get_mark(buffer, "body_start"))
+               gtk_text_buffer_delete_mark_by_name(buffer, "body_start");
+       if (gtk_text_buffer_get_mark(buffer, "body_end"))
+               gtk_text_buffer_delete_mark_by_name(buffer, "body_end");
 
        TEXTVIEW_STATUSBAR_POP(textview);
        textview_uri_list_remove_all(textview->uri_list);
@@ -1617,6 +1774,7 @@ void textview_clear(TextView *textview)
        if (textview->image) 
                gtk_widget_destroy(textview->image);
        textview->image = NULL;
+       textview->avatar_type = 0;
 
        if (textview->messageview->mainwin->cursor_count == 0) {
                textview_set_cursor(window, text_cursor);
@@ -1641,11 +1799,6 @@ void textview_destroy(TextView *textview)
        g_free(textview);
 }
 
-void textview_set_all_headers(TextView *textview, gboolean all_headers)
-{
-       textview->show_all_headers = all_headers;
-}
-
 #define CHANGE_TAG_FONT(tagname, font) { \
        tag = gtk_text_tag_table_lookup(tags, tagname); \
        if (tag) \
@@ -1703,8 +1856,8 @@ void textview_set_text(TextView *textview, const gchar *text)
        GtkTextView *view;
        GtkTextBuffer *buffer;
 
-       g_return_if_fail(textview != NULL);
-       g_return_if_fail(text != NULL);
+       cm_return_if_fail(textview != NULL);
+       cm_return_if_fail(text != NULL);
 
        textview_clear(textview);
 
@@ -1736,26 +1889,6 @@ void textview_set_position(TextView *textview, gint pos)
        gtkut_text_view_set_position(text, pos);
 }
 
-static gboolean header_is_internal(Header *header)
-{
-       const gchar *internal_hdrs[] = 
-               {"AF:", "NF:", "PS:", "SRH:", "SFN:", "DSR:", "MID:", 
-                "CFG:", "PT:", "S:", "RQ:", "SSV:", "NSV:", "SSH:", 
-                "R:", "MAID:", "SCF:", "RMID:", "FMID:", "NAID:", 
-                "X-Claws-Account-Id:", "X-Claws-Sign:", "X-Claws-Encrypt:", 
-                "X-Claws-Privacy-System:", "X-Claws-End-Special-Headers:",
-                "X-Sylpheed-Account-Id:", "X-Sylpheed-Sign:", "X-Sylpheed-Encrypt:", 
-                "X-Sylpheed-Privacy-System:", "X-Sylpheed-End-Special-Headers:",
-                NULL};
-       int i;
-       
-       for (i = 0; internal_hdrs[i]; i++) {
-               if (!strcmp(header->name, internal_hdrs[i]))
-                       return TRUE;
-       }
-       return FALSE;
-}
-
 static GPtrArray *textview_scan_header(TextView *textview, FILE *fp)
 {
        gchar buf[BUFFSIZE];
@@ -1764,14 +1897,14 @@ static GPtrArray *textview_scan_header(TextView *textview, FILE *fp)
        Header *header;
        gint i;
 
-       g_return_val_if_fail(fp != NULL, NULL);
+       cm_return_val_if_fail(fp != NULL, NULL);
 
-       if (textview->show_all_headers) {
+       if (prefs_common.show_all_headers) {
                headers = procheader_get_header_array_asis(fp);
                sorted_headers = g_ptr_array_new();
                for (i = 0; i < headers->len; i++) {
                        header = g_ptr_array_index(headers, i);
-                       if (!header_is_internal(header))
+                       if (!procheader_header_is_internal(header->name))
                                g_ptr_array_add(sorted_headers, header);
                        else
                                procheader_header_free(header);
@@ -1814,7 +1947,7 @@ static GPtrArray *textview_scan_header(TextView *textview, FILE *fp)
        if (prefs_common.show_other_header) {
                for (i = 0; i < headers->len; i++) {
                        header = g_ptr_array_index(headers, i);
-                       if (!header_is_internal(header)) {
+                       if (!procheader_header_is_internal(header->name)) {
                                g_ptr_array_add(sorted_headers, header);
                        } else {
                                procheader_header_free(header);
@@ -1828,45 +1961,54 @@ static GPtrArray *textview_scan_header(TextView *textview, FILE *fp)
        return sorted_headers;
 }
 
-static void textview_show_face(TextView *textview)
+static void textview_show_avatar(TextView *textview)
 {
+       GtkAllocation allocation;
        GtkTextView *text = GTK_TEXT_VIEW(textview->text);
        MsgInfo *msginfo = textview->messageview->msginfo;
        int x = 0;
+       AvatarRender *avatarr;
        
-       if (prefs_common.display_header_pane
-       ||  !prefs_common.display_xface)
+       if (prefs_common.display_header_pane || !prefs_common.display_xface)
                goto bail;
        
-       if (!msginfo->extradata || !msginfo->extradata->face) {
+       avatarr = avatars_avatarrender_new(msginfo);
+       hooks_invoke(AVATAR_IMAGE_RENDER_HOOKLIST, avatarr);
+
+       if (!avatarr->image) {
+               avatars_avatarrender_free(avatarr);
                goto bail;
        }
 
        if (textview->image) 
                gtk_widget_destroy(textview->image);
        
-       textview->image = face_get_from_header(msginfo->extradata->face);
-       g_return_if_fail(textview->image != NULL);
+       textview->image = avatarr->image;
+       textview->avatar_type = avatarr->type;
+       avatarr->image = NULL; /* avoid destroying */
+       avatars_avatarrender_free(avatarr);
 
        gtk_widget_show(textview->image);
        
-       x = textview->text->allocation.width - WIDTH -5;
+       gtk_widget_get_allocation(textview->text, &allocation);
+       x = allocation.width - WIDTH -5;
 
        gtk_text_view_add_child_in_window(text, textview->image, 
                GTK_TEXT_WINDOW_TEXT, x, 5);
 
        gtk_widget_show_all(textview->text);
-       
 
        return;
 bail:
        if (textview->image) 
                gtk_widget_destroy(textview->image);
        textview->image = NULL; 
+       textview->avatar_type = 0;
 }
 
 void textview_show_icon(TextView *textview, const gchar *stock_id)
 {
+       GtkAllocation allocation;
        GtkTextView *text = GTK_TEXT_VIEW(textview->text);
        int x = 0;
        
@@ -1874,11 +2016,12 @@ void textview_show_icon(TextView *textview, const gchar *stock_id)
                gtk_widget_destroy(textview->image);
        
        textview->image = gtk_image_new_from_stock(stock_id, GTK_ICON_SIZE_DIALOG);
-       g_return_if_fail(textview->image != NULL);
+       cm_return_if_fail(textview->image != NULL);
 
        gtk_widget_show(textview->image);
        
-       x = textview->text->allocation.width - WIDTH -5;
+       gtk_widget_get_allocation(textview->text, &allocation);
+       x = allocation.width - WIDTH -5;
 
        gtk_text_view_add_child_in_window(text, textview->image, 
                GTK_TEXT_WINDOW_TEXT, x, 5);
@@ -1889,65 +2032,18 @@ void textview_show_icon(TextView *textview, const gchar *stock_id)
        return;
 }
 
-#if HAVE_LIBCOMPFACE
-static void textview_show_xface(TextView *textview)
-{
-       MsgInfo *msginfo = textview->messageview->msginfo;
-       GtkTextView *text = GTK_TEXT_VIEW(textview->text);
-       int x = 0;
-       GdkWindow *window = NULL;
-       
-       if (prefs_common.display_header_pane
-       ||  !prefs_common.display_xface)
-               goto bail;
-       
-       if (!msginfo || !msginfo->extradata)
-               goto bail;
-
-       if (msginfo->extradata->face)
-               return;
-       
-       if (!msginfo->extradata->xface || strlen(msginfo->extradata->xface) < 5) {
-               goto bail;
-       }
-
-       if (textview->image) 
-               gtk_widget_destroy(textview->image);
-
-       window = mainwindow_get_mainwindow() ?
-                       mainwindow_get_mainwindow()->window->window :
-                       textview->text->window;
-       textview->image = xface_get_from_header(msginfo->extradata->xface,
-                               &textview->text->style->white,
-                               window);
-       g_return_if_fail(textview->image != NULL);
-
-       gtk_widget_show(textview->image);
-       
-       x = textview->text->allocation.width - WIDTH -5;
-
-       gtk_text_view_add_child_in_window(text, textview->image, 
-               GTK_TEXT_WINDOW_TEXT, x, 5);
-
-       gtk_widget_show_all(textview->text);
-       
-       return;
-bail:
-       if (textview->image) 
-               gtk_widget_destroy(textview->image);
-       textview->image = NULL;
-       
-}
-#endif
-
 static void textview_save_contact_pic(TextView *textview)
 {
+#ifndef USE_NEW_ADDRBOOK
        MsgInfo *msginfo = textview->messageview->msginfo;
        gchar *filename = NULL;
        GError *error = NULL;
        GdkPixbuf *picture = NULL;
-                               
-       if (!msginfo->extradata || (!msginfo->extradata->face && !msginfo->extradata->xface))
+
+       if (!msginfo->extradata || !msginfo->extradata->avatars)
+               return;
+
+       if (textview->avatar_type > AVATAR_FACE)
                return;
 
        if (textview->image) 
@@ -1959,16 +2055,20 @@ static void textview_save_contact_pic(TextView *textview)
        if (!is_file_exist(filename)) {
                gdk_pixbuf_save(picture, filename, "png", &error, NULL);
                if (error) {
-                       g_warning(_("Failed to save image: \n%s"),
+                       g_warning("Failed to save image: %s",
                                        error->message);
                        g_error_free(error);
                }
        }
        g_free(filename);
+#else
+       /* new address book */
+#endif
 }
 
 static void textview_show_contact_pic(TextView *textview)
 {
+#ifndef USE_NEW_ADDRBOOK
        MsgInfo *msginfo = textview->messageview->msginfo;
        GtkTextView *text = GTK_TEXT_VIEW(textview->text);
        int x = 0;
@@ -1976,12 +2076,13 @@ static void textview_show_contact_pic(TextView *textview)
        GError *error = NULL;
        GdkPixbuf *picture = NULL;
        gint w, h;
-                               
+       GtkAllocation allocation;
+
        if (prefs_common.display_header_pane
-       ||  !prefs_common.display_xface)
+               || !prefs_common.display_xface)
                goto bail;
        
-       if (msginfo->extradata && (msginfo->extradata->face || msginfo->extradata->xface))
+       if (msginfo->extradata && msginfo->extradata->avatars)
                return;
 
        if (textview->image) 
@@ -2016,11 +2117,12 @@ static void textview_show_contact_pic(TextView *textview)
                textview->image = gtk_image_new_from_pixbuf(picture);
                g_object_unref(picture);
        }
-       g_return_if_fail(textview->image != NULL);
+       cm_return_if_fail(textview->image != NULL);
 
        gtk_widget_show(textview->image);
        
-       x = textview->text->allocation.width - WIDTH -5;
+       gtk_widget_get_allocation(textview->text, &allocation);
+       x = allocation.width - WIDTH -5;
 
        gtk_text_view_add_child_in_window(text, textview->image, 
                GTK_TEXT_WINDOW_TEXT, x, 5);
@@ -2032,7 +2134,10 @@ bail:
        if (textview->image) 
                gtk_widget_destroy(textview->image);
        textview->image = NULL;
-       
+       textview->avatar_type = 0;
+#else
+       /* new address book */
+#endif 
 }
 
 static gint textview_tag_cmp_list(gconstpointer a, gconstpointer b)
@@ -2046,7 +2151,7 @@ static gint textview_tag_cmp_list(gconstpointer a, gconstpointer b)
                return tag_b == NULL ? 0:1;
        
        if (tag_b == NULL)
-               return tag_a == NULL ? 0:1;
+               return 1;
 
        return g_utf8_collate(tag_a, tag_b);
 }
@@ -2119,11 +2224,11 @@ static void textview_show_header(TextView *textview, GPtrArray *headers)
        Header *header;
        gint i;
 
-       g_return_if_fail(headers != NULL);
+       cm_return_if_fail(headers != NULL);
 
        for (i = 0; i < headers->len; i++) {
                header = g_ptr_array_index(headers, i);
-               g_return_if_fail(header->name != NULL);
+               cm_return_if_fail(header->name != NULL);
 
                gtk_text_buffer_get_end_iter (buffer, &iter);
                if(prefs_common.trans_hdr == TRUE) {
@@ -2150,12 +2255,20 @@ static void textview_show_header(TextView *textview, GPtrArray *headers)
                    procheader_headername_equal(header->name, "To")      ||
                    procheader_headername_equal(header->name, "Cc"))
                        unfold_line(header->body);
-
-               if ((procheader_headername_equal(header->name, "X-Mailer") ||
-                    procheader_headername_equal(header->name,
+               
+               if (procheader_headername_equal(header->name, "Date") &&
+                   prefs_common.msgview_date_format) {
+                       gchar hbody[80];
+                       
+                       procheader_date_parse(hbody, header->body, sizeof(hbody));
+                       gtk_text_buffer_get_end_iter (buffer, &iter);
+                       gtk_text_buffer_insert_with_tags_by_name
+                               (buffer, &iter, hbody, -1, "header", NULL);
+               } else if ((procheader_headername_equal(header->name, "X-Mailer") ||
+                               procheader_headername_equal(header->name,
                                                 "X-Newsreader")) &&
-                   (strstr(header->body, "Claws Mail") != NULL ||
-                    strstr(header->body, "Sylpheed-Claws") != NULL)) {
+                               (strstr(header->body, "Claws Mail") != NULL ||
+                               strstr(header->body, "Sylpheed-Claws") != NULL)) {
                        gtk_text_buffer_get_end_iter (buffer, &iter);
                        gtk_text_buffer_insert_with_tags_by_name
                                (buffer, &iter, header->body, -1,
@@ -2177,10 +2290,8 @@ static void textview_show_header(TextView *textview, GPtrArray *headers)
                                                         "header", NULL);
        }
        
-       textview_show_face(textview);
-#if HAVE_LIBCOMPFACE
-       textview_show_xface(textview);
-#endif
+       textview_show_avatar(textview);
+
        textview_save_contact_pic(textview);
        textview_show_contact_pic(textview);
 }
@@ -2204,7 +2315,7 @@ gboolean textview_search_string_backward(TextView *textview, const gchar *str,
 void textview_scroll_one_line(TextView *textview, gboolean up)
 {
        GtkTextView *text = GTK_TEXT_VIEW(textview->text);
-       GtkAdjustment *vadj = text->vadjustment;
+       GtkAdjustment *vadj = gtk_text_view_get_vadjustment(text);
 
        gtkutils_scroll_one_line(GTK_WIDGET(text), vadj, up);
 }
@@ -2212,11 +2323,28 @@ void textview_scroll_one_line(TextView *textview, gboolean up)
 gboolean textview_scroll_page(TextView *textview, gboolean up)
 {
        GtkTextView *text = GTK_TEXT_VIEW(textview->text);
-       GtkAdjustment *vadj = text->vadjustment;
+       GtkAdjustment *vadj = gtk_text_view_get_vadjustment(text);
 
        return gtkutils_scroll_page(GTK_WIDGET(text), vadj, up);
 }
 
+void textview_scroll_max(TextView *textview, gboolean up)
+{
+       GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview->text));
+       GtkTextIter iter;
+       
+       if (up) {
+               gtk_text_buffer_get_start_iter(buffer, &iter);
+               gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(textview->text),
+                                               &iter, 0.0, TRUE, 0.0, 1.0);
+       
+       } else {
+               gtk_text_buffer_get_end_iter(buffer, &iter);
+               gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(textview->text),
+                                               &iter, 0.0, TRUE, 0.0, 0.0);
+       }
+}
+
 #define KEY_PRESS_EVENT_STOP() \
        g_signal_stop_emission_by_name(G_OBJECT(widget), \
                                       "key_press_event");
@@ -2224,6 +2352,7 @@ gboolean textview_scroll_page(TextView *textview, gboolean up)
 static gint textview_key_pressed(GtkWidget *widget, GdkEventKey *event,
                                 TextView *textview)
 {
+       GdkWindow *window = NULL;
        SummaryView *summaryview = NULL;
        MessageView *messageview = textview->messageview;
 
@@ -2232,19 +2361,21 @@ static gint textview_key_pressed(GtkWidget *widget, GdkEventKey *event,
                summaryview = messageview->mainwin->summaryview;
 
        switch (event->keyval) {
-       case GDK_Tab:
-       case GDK_Home:
-       case GDK_Left:
-       case GDK_Up:
-       case GDK_Right:
-       case GDK_Down:
-       case GDK_Page_Up:
-       case GDK_Page_Down:
-       case GDK_End:
-       case GDK_Control_L:
-       case GDK_Control_R:
+       case GDK_KEY_Tab:
+       case GDK_KEY_Left:
+       case GDK_KEY_Up:
+       case GDK_KEY_Right:
+       case GDK_KEY_Down:
+       case GDK_KEY_Page_Up:
+       case GDK_KEY_Page_Down:
+       case GDK_KEY_Control_L:
+       case GDK_KEY_Control_R:
                return FALSE;
-       case GDK_space:
+       case GDK_KEY_Home:
+       case GDK_KEY_End:
+               textview_scroll_max(textview,(event->keyval == GDK_KEY_Home));
+               return TRUE;
+       case GDK_KEY_space:
                if (summaryview)
                        summary_pass_key_press_event(summaryview, event);
                else
@@ -2253,41 +2384,31 @@ static gint textview_key_pressed(GtkWidget *widget, GdkEventKey *event,
                                 (event->state &
                                  (GDK_SHIFT_MASK|GDK_MOD1_MASK)) != 0);
                break;
-       case GDK_BackSpace:
+       case GDK_KEY_BackSpace:
                mimeview_scroll_page(messageview->mimeview, TRUE);
                break;
-       case GDK_Return:
-       case GDK_KP_Enter:
+       case GDK_KEY_Return:
+       case GDK_KEY_KP_Enter:
                mimeview_scroll_one_line
                        (messageview->mimeview, (event->state &
                                    (GDK_SHIFT_MASK|GDK_MOD1_MASK)) != 0);
                break;
-       case GDK_Delete:
+       case GDK_KEY_Delete:
                if (summaryview)
                        summary_pass_key_press_event(summaryview, event);
                break;
-       case GDK_y:
-       case GDK_t:
-       case GDK_l:
-       case GDK_o:
-       case GDK_c:
-       case GDK_a:
-               if ((event->state & (GDK_MOD1_MASK|GDK_CONTROL_MASK)) == 0) {
-                       KEY_PRESS_EVENT_STOP();
-                       mimeview_pass_key_press_event(messageview->mimeview,
-                                                     event);
-                       break;
-               }
-               /* possible fall through */
        default:
-               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);
+               if (messageview->mainwin) {
+                       window = gtk_widget_get_window(messageview->mainwin->window);
+                       if (summaryview &&
+                           event->window != window) {
+                               GdkEventKey tmpev = *event;
+
+                               tmpev.window = window;
+                               KEY_PRESS_EVENT_STOP();
+                               gtk_widget_event(messageview->mainwin->window,
+                                                (GdkEvent *)&tmpev);
+                       }
                }
                break;
        }
@@ -2302,7 +2423,7 @@ static gboolean textview_motion_notify(GtkWidget *widget,
        if (textview->loading)
                return FALSE;
        textview_uri_update(textview, event->x, event->y);
-       gdk_window_get_pointer(widget->window, NULL, NULL, NULL);
+       gdk_window_get_pointer(gtk_widget_get_window(widget), NULL, NULL, NULL);
 
        return FALSE;
 }
@@ -2335,7 +2456,7 @@ static gboolean textview_visibility_notify(GtkWidget *widget,
        if (window != event->window)
                return FALSE;
        
-       gdk_window_get_pointer(widget->window, &wx, &wy, NULL);
+       gdk_window_get_pointer(gtk_widget_get_window(widget), &wx, &wy, NULL);
        textview_uri_update(textview, wx, wy);
 
        return FALSE;
@@ -2426,17 +2547,12 @@ static void textview_uri_update(TextView *textview, gint x, gint y)
                TEXTVIEW_STATUSBAR_POP(textview);
 
                if (uri) {
-                       char *trimmed_uri;
-
                        if (!uri->is_quote)
                                gtk_text_buffer_apply_tag_by_name(buffer,
                                                          "link-hover",
                                                          &start_iter,
                                                          &end_iter);
-
-                       trimmed_uri = trim_string(uri->uri, 60);
-                       TEXTVIEW_STATUSBAR_PUSH(textview, trimmed_uri);
-                       g_free(trimmed_uri);
+                       TEXTVIEW_STATUSBAR_PUSH(textview, uri->uri);
                }
        }
 }
@@ -2657,7 +2773,8 @@ static gboolean textview_uri_button_pressed(GtkTextTag *tag, GObject *obj,
                        } 
                        return TRUE;
                } else if (qlink && bevent->button == 1) {
-                       textview_toggle_quote(textview, NULL, uri, FALSE);
+                       if (prefs_common.hide_quoted)
+                               textview_toggle_quote(textview, NULL, uri, FALSE);
                        return TRUE;
                } else if (!g_ascii_strncasecmp(uri->uri, "mailto:", 7)) {
                        if (bevent->button == 3) {
@@ -2670,6 +2787,8 @@ static gboolean textview_uri_button_pressed(GtkTextTag *tag, GObject *obj,
                        } else {
                                PrefsAccount *account = NULL;
                                FolderItem   *folder_item = NULL;
+                               Compose *compose;
+                               
                                if (textview->messageview && textview->messageview->msginfo &&
                                    textview->messageview->msginfo->folder) {
                                        
@@ -2680,7 +2799,9 @@ static gboolean textview_uri_button_pressed(GtkTextTag *tag, GObject *obj,
                                        if (!account)
                                                account = account_find_from_item(folder_item);
                                }
-                               compose_new_with_folderitem(account, folder_item, uri->uri + 7);
+                               compose = compose_new_with_folderitem(account,
+                                                               folder_item, uri->uri + 7);
+                               compose_check_for_email_account(compose);
                        }
                        return TRUE;
                } else if (g_ascii_strncasecmp(uri->uri, "file:", 5)) {
@@ -2766,15 +2887,14 @@ gboolean textview_uri_security_check(TextView *textview, ClickableText *uri)
                gchar *msg;
                AlertValue aval;
 
-               msg = g_markup_printf_escaped(_("The real URL is different from "
-                                               "the displayed URL.\n"
-                                               "\n"
-                                               "<b>Displayed URL:</b> %s\n"
-                                               "\n"
-                                               "<b>Real URL:</b> %s\n"
-                                               "\n"
-                                               "Open it anyway?"),
-                                              visible_str,uri->uri);
+               msg = g_markup_printf_escaped("%s\n\n"
+                                               "<b>%s</b> %s\n\n"
+                                               "<b>%s</b> %s\n\n"
+                                               "%s",
+                                               _("The real URL is different from the displayed URL."),
+                                               _("Displayed URL:"), visible_str,
+                                               _("Real URL:"), uri->uri,
+                                               _("Open it anyway?"));
                aval = alertpanel_full(_("Phishing attempt warning"), msg,
                                       GTK_STOCK_CANCEL, _("_Open URL"), NULL, FALSE,
                                       NULL, ALERT_WARNING, G_ALERTDEFAULT);
@@ -2837,7 +2957,7 @@ static void open_image_cb (GtkAction *action, TextView *textview)
        gchar *cmd = NULL;
        gchar buf[1024];
        const gchar *p;
-       gchar *filename = NULL;
+       gchar *filename = NULL, *filepath = NULL;
        gchar *tmp_filename = NULL;
 
        if (uri == NULL)
@@ -2856,8 +2976,11 @@ static void open_image_cb (GtkAction *action, TextView *textview)
 
        subst_for_filename(filename);
 
+       filepath = g_strconcat(get_mime_tmp_dir(), G_DIR_SEPARATOR_S,
+                              filename, NULL);
+
        tmp_filename = g_filename_from_uri(uri->uri, NULL, NULL);
-       copy_file(tmp_filename, filename, FALSE);
+       copy_file(tmp_filename, filepath, FALSE);
        g_free(tmp_filename);
 
        cmd = mailcap_get_command_for_type("image/jpeg", filename);
@@ -2865,7 +2988,7 @@ static void open_image_cb (GtkAction *action, TextView *textview)
                gboolean remember = FALSE;
                cmd = input_dialog_combo_remember
                        (_("Open with"),
-                        _("Enter the command line to open file:\n"
+                        _("Enter the command-line to open file:\n"
                           "('%s' will be replaced with file name)"),
                         prefs_common.mime_open_cmd,
                         prefs_common.mime_open_cmd_history,
@@ -2876,14 +2999,17 @@ static void open_image_cb (GtkAction *action, TextView *textview)
        }
        if (cmd && (p = strchr(cmd, '%')) && *(p + 1) == 's' &&
            !strchr(p + 2, '%'))
-               g_snprintf(buf, sizeof(buf), cmd, filename);
+               g_snprintf(buf, sizeof(buf), cmd, filepath);
        else {
-               g_warning("Image viewer command line is invalid: '%s'", cmd);
+               g_warning("Image viewer command-line is invalid: '%s'", cmd);
+               g_free(filepath);
+               g_free(filename);
                return;
        }
 
        execute_command_line(buf, TRUE);
 
+       g_free(filepath);
        g_free(filename);
        g_free(cmd);
 
@@ -2899,6 +3025,8 @@ static void save_file_cb (GtkAction *action, TextView *textview)
        gchar *filepath = NULL;
        gchar *filedir = NULL;
        gchar *tmp_filename = NULL;
+       GtkWidget *window;
+
        if (uri == NULL)
                return;
 
@@ -2915,14 +3043,23 @@ static void save_file_cb (GtkAction *action, TextView *textview)
 
        subst_for_filename(filename);
        
-       if (prefs_common.attach_save_dir)
+       if (prefs_common.attach_save_dir && *prefs_common.attach_save_dir)
                filepath = g_strconcat(prefs_common.attach_save_dir,
                                       G_DIR_SEPARATOR_S, filename, NULL);
        else
-               filepath = g_strdup(filename);
+               filepath = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S,
+                                      filename, NULL);
 
        g_free(filename);
 
+       /* Pick correct window to set the file dialog "transient for" */
+       if (textview->messageview->window != NULL)
+               window = textview->messageview->window;
+       else
+               window = textview->messageview->mainwin->window;
+
+       manage_window_focus_in(window, NULL, NULL);
+
        filename = filesel_select_file_save(_("Save as"), filepath);
        if (!filename) {
                g_free(filepath);
@@ -2984,9 +3121,10 @@ static void add_uri_to_addrbook_cb (GtkAction *action, TextView *textview)
        gchar *fromname, *fromaddress;
        ClickableText *uri = g_object_get_data(G_OBJECT(textview->mail_popup_menu),
                                           "menu_button");
-       GtkWidget *image = NULL;
+       AvatarRender *avatarr = NULL;
        GdkPixbuf *picture = NULL;
        gboolean use_picture = FALSE;
+
        if (uri == NULL)
                return;
 
@@ -3000,34 +3138,45 @@ static void add_uri_to_addrbook_cb (GtkAction *action, TextView *textview)
        fromname = procheader_get_fromname(fromaddress);
        extract_address(fromaddress);
 
-       if (use_picture && 
-           textview->messageview->msginfo &&
-           textview->messageview->msginfo->extradata &&
-           textview->messageview->msginfo->extradata->face) {
-               image = face_get_from_header(textview->messageview->msginfo->extradata->face);
-       }
-#if HAVE_LIBCOMPFACE 
-       else if (use_picture && 
-                textview->messageview->msginfo &&
-                textview->messageview->msginfo->extradata &&
-                textview->messageview->msginfo->extradata->xface) {
-               image = xface_get_from_header(textview->messageview->msginfo->extradata->xface,
-                               &textview->text->style->white,
-                               mainwindow_get_mainwindow()->window->window);   
+       if (use_picture) {
+               avatarr = avatars_avatarrender_new(textview->messageview->msginfo);
+               hooks_invoke(AVATAR_IMAGE_RENDER_HOOKLIST, avatarr);
        }
-#endif
-       if (image)
-               picture = gtk_image_get_pixbuf(GTK_IMAGE(image));
 
+       if (avatarr && avatarr->image) {
+               picture = gtk_image_get_pixbuf(GTK_IMAGE(avatarr->image));
+       }
+       if (avatarr) {
+               avatars_avatarrender_free(avatarr);
+       }
+
+#ifndef USE_NEW_ADDRBOOK
        addressbook_add_contact( fromname, fromaddress, NULL, picture);
+#else
+       if (addressadd_selection(fromname, fromaddress, NULL, picture)) {
+               debug_print( "addressbook_add_contact - added\n" );
+       }
+#endif
 
        g_free(fromaddress);
        g_free(fromname);
 }
 
+static void reply_to_uri_cb (GtkAction *action, TextView *textview)
+{
+       ClickableText *uri = g_object_get_data(G_OBJECT(textview->mail_popup_menu),
+                                          "menu_button");
+       if (!textview->messageview || !uri)
+               return;
+
+       compose_reply_to_address (textview->messageview,
+                                 textview->messageview->msginfo, uri->uri+7);
+}
+
 static void mail_to_uri_cb (GtkAction *action, TextView *textview)
 {
        PrefsAccount *account = NULL;
+       Compose *compose;
        ClickableText *uri = g_object_get_data(G_OBJECT(textview->mail_popup_menu),
                                           "menu_button");
        if (uri == NULL)
@@ -3041,10 +3190,11 @@ static void mail_to_uri_cb (GtkAction *action, TextView *textview)
                if (folder_item->prefs && folder_item->prefs->enable_default_account)
                        account = account_find_from_id(folder_item->prefs->default_account);
                
-               compose_new_with_folderitem(account, folder_item, uri->uri+7);
+               compose = compose_new_with_folderitem(account, folder_item, uri->uri+7);
        } else {
-               compose_new(account, uri->uri + 7, NULL);
+               compose = compose_new(account, uri->uri + 7, NULL);
        }
+       compose_check_for_email_account(compose);
 }
 
 static void copy_mail_to_uri_cb        (GtkAction *action, TextView *textview)