rework image viewer
[claws.git] / src / textview.c
index 31708d69f1245469950ec06a72e9ec1629d8c366..62ad46eaf6735fc368aeb8dc569ead7ad9cd2b50 100644 (file)
@@ -1,6 +1,6 @@
 /*
- * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2014 Hiroyuki Yamamoto and the Claws Mail team
+ * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
+ * Copyright (C) 1999-2020 the Claws Mail team and Hiroyuki Yamamoto
  *
  * 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
@@ -14,7 +14,6 @@
  *
  * 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
@@ -49,7 +48,7 @@
 #include "html.h"
 #include "enriched.h"
 #include "compose.h"
-#ifndef USE_NEW_ADDRBOOK
+#ifndef USE_ALT_ADDRBOOK
        #include "addressbook.h"
        #include "addrindex.h"
 #else
@@ -63,7 +62,6 @@
 #include "menu.h"
 #include "image_viewer.h"
 #include "filesel.h"
-#include "base64.h"
 #include "inputdialog.h"
 #include "timing.h"
 #include "tags.h"
@@ -71,6 +69,7 @@
 #include "folder_item_prefs.h"
 #include "hooks.h"
 #include "avatars.h"
+#include "file-utils.h"
 
 static GdkColor quote_colors[3] = {
        {(gulong)0, (gushort)0, (gushort)0, (gushort)0},
@@ -125,6 +124,20 @@ static GdkColor diff_hunk_color = {
        (gushort)0
 };
 
+static GdkColor tags_bgcolor = {
+       (gulong)0,
+       (gushort)0,
+       (gushort)0,
+       (gushort)0
+};
+
+static GdkColor tags_color = {
+       (gulong)0,
+       (gushort)0,
+       (gushort)0,
+       (gushort)0
+};
+
 static GdkCursor *hand_cursor = NULL;
 static GdkCursor *text_cursor = NULL;
 static GdkCursor *watch_cursor= NULL;
@@ -221,35 +234,24 @@ static void mail_to_uri_cb                        (GtkAction      *action,
                                                 TextView       *textview);
 static void copy_mail_to_uri_cb                        (GtkAction      *action,
                                                 TextView       *textview);
-static void save_file_cb                       (GtkAction      *action,
-                                                TextView       *textview);
-static void open_image_cb                      (GtkAction      *action,
-                                                TextView       *textview);
 static void textview_show_tags(TextView *textview);
 
 static GtkActionEntry textview_link_popup_entries[] = 
 {
-       {"TextviewPopupLink",                   NULL, "TextviewPopupLink" },
+       {"TextviewPopupLink",                   NULL, "TextviewPopupLink", NULL, NULL, NULL },
        {"TextviewPopupLink/Open",              NULL, N_("_Open in web browser"), NULL, NULL, G_CALLBACK(open_uri_cb) },
        {"TextviewPopupLink/Copy",              NULL, N_("Copy this _link"), NULL, NULL, G_CALLBACK(copy_uri_cb) },
 };
 
 static GtkActionEntry textview_mail_popup_entries[] = 
 {
-       {"TextviewPopupMail",                   NULL, "TextviewPopupMail" },
+       {"TextviewPopupMail",                   NULL, "TextviewPopupMail", NULL, NULL, NULL },
        {"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) },
 };
 
-static GtkActionEntry textview_file_popup_entries[] = 
-{
-       {"TextviewPopupFile",                   NULL, "TextviewPopupFile" },
-       {"TextviewPopupFile/Open",              NULL, N_("_Open image"), NULL, NULL, G_CALLBACK(open_image_cb) },
-       {"TextviewPopupFile/Save",              NULL, N_("_Save image..."), NULL, NULL, G_CALLBACK(save_file_cb) },
-};
-
 static void scrolled_cb (GtkAdjustment *adj, TextView *textview)
 {
 #ifndef WIDTH
@@ -352,18 +354,12 @@ TextView *textview_create(void)
                        "TextviewPopupMail",
                        textview_mail_popup_entries,
                        G_N_ELEMENTS(textview_mail_popup_entries), (gpointer)textview);
-       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_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)
@@ -377,17 +373,11 @@ TextView *textview_create(void)
                        "/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(textview->ui_manager, "/Menus/TextviewPopupLink")) );
        textview->mail_popup_menu = gtk_menu_item_get_submenu(GTK_MENU_ITEM(
                                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(textview->ui_manager, "/Menus/TextviewPopupFile")) );
 
        textview->vbox               = vbox;
        textview->scrolledwin        = scrolledwin;
@@ -403,26 +393,8 @@ 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);
-               color_init = gdk_colormap_alloc_color(
-                       gdk_colormap_get_system(), &yellow, FALSE, TRUE);
-               color_init &= gdk_colormap_alloc_color(
-                       gdk_colormap_get_system(), &black, FALSE, TRUE);
-       }
-#endif
-
        if (!font_desc)
                font_desc = pango_font_description_from_string
                        (NORMAL_FONT);
@@ -490,8 +462,8 @@ static void textview_create_tags(GtkTextView *text, TextView *textview)
                                NULL);
        }
        gtk_text_buffer_create_tag(buffer, "tags",
-                       "foreground-gdk", &black,
-                       "paragraph-background-gdk", &yellow,
+                       "foreground-gdk", &tags_color,
+                       "paragraph-background-gdk", &tags_bgcolor,
                        NULL);
        gtk_text_buffer_create_tag(buffer, "emphasis",
                        "foreground-gdk", &emphasis_color,
@@ -567,34 +539,35 @@ static void textview_update_message_colors(TextView *textview)
        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;
+       tags_bgcolor = tags_color = black;
 
        if (prefs_common.enable_color) {
                /* grab the quote colors, converting from an int to a GdkColor */
-               gtkut_convert_int_to_gdk_color(prefs_common.quote_level1_col,
+               gtkut_convert_int_to_gdk_color(prefs_common.color[COL_QUOTE_LEVEL1],
                                               &quote_colors[0]);
-               gtkut_convert_int_to_gdk_color(prefs_common.quote_level2_col,
+               gtkut_convert_int_to_gdk_color(prefs_common.color[COL_QUOTE_LEVEL2],
                                               &quote_colors[1]);
-               gtkut_convert_int_to_gdk_color(prefs_common.quote_level3_col,
+               gtkut_convert_int_to_gdk_color(prefs_common.color[COL_QUOTE_LEVEL3],
                                               &quote_colors[2]);
-               gtkut_convert_int_to_gdk_color(prefs_common.uri_col,
+               gtkut_convert_int_to_gdk_color(prefs_common.color[COL_URI],
                                               &uri_color);
-               gtkut_convert_int_to_gdk_color(prefs_common.signature_col,
+               gtkut_convert_int_to_gdk_color(prefs_common.color[COL_SIGNATURE],
                                               &signature_color);
-               gtkut_convert_int_to_gdk_color(prefs_common.emphasis_col,
+               gtkut_convert_int_to_gdk_color(prefs_common.color[COL_EMPHASIS],
                                               &emphasis_color);
-               gtkut_convert_int_to_gdk_color(prefs_common.diff_added_color,
+               gtkut_convert_int_to_gdk_color(prefs_common.color[COL_DIFF_ADDED],
                                               &diff_added_color);
-               gtkut_convert_int_to_gdk_color(prefs_common.diff_deleted_color,
+               gtkut_convert_int_to_gdk_color(prefs_common.color[COL_DIFF_DELETED],
                                               &diff_deleted_color);
-               gtkut_convert_int_to_gdk_color(prefs_common.diff_hunk_color,
+               gtkut_convert_int_to_gdk_color(prefs_common.color[COL_DIFF_HUNK],
                                               &diff_hunk_color);
        }
        if (prefs_common.enable_color && prefs_common.enable_bgcolor) {
-               gtkut_convert_int_to_gdk_color(prefs_common.quote_level1_bgcol,
+               gtkut_convert_int_to_gdk_color(prefs_common.color[COL_QUOTE_LEVEL1_BG],
                                                   &quote_bgcolors[0]);
-               gtkut_convert_int_to_gdk_color(prefs_common.quote_level2_bgcol,
+               gtkut_convert_int_to_gdk_color(prefs_common.color[COL_QUOTE_LEVEL2_BG],
                                                   &quote_bgcolors[1]);
-               gtkut_convert_int_to_gdk_color(prefs_common.quote_level3_bgcol,
+               gtkut_convert_int_to_gdk_color(prefs_common.color[COL_QUOTE_LEVEL3_BG],
                                                   &quote_bgcolors[2]);
                CHANGE_TAG_COLOR("quote0", &quote_colors[0], &quote_bgcolors[0]);
                CHANGE_TAG_COLOR("quote1", &quote_colors[1], &quote_bgcolors[1]);
@@ -614,6 +587,11 @@ static void textview_update_message_colors(TextView *textview)
        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);
+
+       gtkut_convert_int_to_gdk_color(prefs_common.color[COL_TAGS_BG],
+                                          &tags_bgcolor);
+       gtkut_convert_int_to_gdk_color(prefs_common.color[COL_TAGS],
+                                          &tags_color);
 }
 #undef CHANGE_TAG_COLOR
 
@@ -664,6 +642,7 @@ static void textview_add_part(TextView *textview, MimeInfo *mimeinfo)
        const gchar *name;
        gchar *content_type;
        gint charcount;
+
        START_TIMING("");
 
        cm_return_if_fail(mimeinfo != NULL);
@@ -687,13 +666,18 @@ static void textview_add_part(TextView *textview, MimeInfo *mimeinfo)
                if (mimeinfo->content == MIMECONTENT_MEM)
                        fp = str_open_as_stream(mimeinfo->data.mem);
                else
-                       fp = g_fopen(mimeinfo->data.filename, "rb");
+                       fp = claws_fopen(mimeinfo->data.filename, "rb");
                if (!fp) {
-                       FILE_OP_ERROR(mimeinfo->data.filename, "fopen");
+                       FILE_OP_ERROR(mimeinfo->data.filename, "claws_fopen");
+                       END_TIMING();
+                       return;
+               }
+               if (fseek(fp, mimeinfo->offset, SEEK_SET) < 0) {
+                       FILE_OP_ERROR(mimeinfo->data.filename, "fseek");
+                       claws_fclose(fp);
                        END_TIMING();
                        return;
                }
-               fseek(fp, mimeinfo->offset, SEEK_SET);
                headers = textview_scan_header(textview, fp);
                if (headers) {
                        if (charcount > 0)
@@ -704,7 +688,7 @@ static void textview_add_part(TextView *textview, MimeInfo *mimeinfo)
                        textview_show_header(textview, headers);
                        procheader_header_array_destroy(headers);
                }
-               fclose(fp);
+               claws_fclose(fp);
                END_TIMING();
                return;
        }
@@ -733,75 +717,55 @@ static void textview_add_part(TextView *textview, MimeInfo *mimeinfo)
                    prefs_common.inline_img ) {
                        GdkPixbuf *pixbuf;
                        GError *error = NULL;
-                       gchar *filename;
                        ClickableText *uri;
-                       gchar *uri_str;
-                       gint err;
-                       START_TIMING("inserting image");
 
-                       filename = procmime_get_tmp_file_name(mimeinfo);
+                       START_TIMING("inserting image");
 
-                       if ((err = procmime_get_part(filename, mimeinfo)) < 0) {
-                               g_warning("Can't get the image file.(%s)", strerror(-err));
-                               g_free(filename);
+                       pixbuf = procmime_get_part_as_pixbuf(mimeinfo, &error);
+                       if (error != NULL) {
+                               g_warning("Can't load the image: %s\n", error->message);
+                               g_error_free(error);
                                END_TIMING();
                                return;
                        }
 
-                       pixbuf = gdk_pixbuf_new_from_file(filename, &error);
                        if (textview->stop_loading) {
-                               return;
-                       }
-                       if (error != NULL) {
-                               g_warning("%s\n", error->message);
-                               g_error_free(error);
-                       }
-                       if (!pixbuf) {
-                               g_warning("Can't load the image.");
-                               g_free(filename);
                                END_TIMING();
                                return;
                        }
 
                        gtk_widget_get_allocation(textview->scrolledwin, &allocation);
-                       pixbuf = claws_load_pixbuf_fitting(pixbuf,
-                                       allocation.width,
+                       pixbuf = claws_load_pixbuf_fitting(pixbuf, prefs_common.inline_img,
+                                       prefs_common.fit_img_height, allocation.width,
                                        allocation.height);
 
                        if (textview->stop_loading) {
+                               END_TIMING();
                                return;
                        }
 
-                       uri_str = g_filename_to_uri(filename, NULL, NULL);
-                       if (uri_str) {
-                               uri = g_new0(ClickableText, 1);
-                               uri->uri = uri_str;
-                               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 =
-                                       g_slist_prepend(textview->uri_list, uri);
-                               
-                               gtk_text_buffer_insert(buffer, &iter, " ", 1);
-                               gtk_text_buffer_get_iter_at_offset(buffer, &start_iter, uri->start);    
-                               gtk_text_buffer_apply_tag_by_name(buffer, "link", 
-                                               &start_iter, &iter);
-                       } else {
-                               gtk_text_buffer_insert_pixbuf(buffer, &iter, pixbuf);
-                               if (textview->stop_loading) {
-                                       return;
-                               }
-                               gtk_text_buffer_insert(buffer, &iter, " ", 1);
-                       }
+                       uri = g_new0(ClickableText, 1);
+                       uri->uri = g_strdup("");
+                       uri->filename = g_strdup("sc://select_attachment");
+                       uri->data = mimeinfo;
 
+                       uri->start = gtk_text_iter_get_offset(&iter);
+                       gtk_text_buffer_insert_pixbuf(buffer, &iter, pixbuf);
                        g_object_unref(pixbuf);
-                       g_free(filename);
+                       if (textview->stop_loading) {
+                               g_free(uri);
+                               return;
+                       }
+                       uri->end = gtk_text_iter_get_offset(&iter);
+
+                       textview->uri_list =
+                               g_slist_prepend(textview->uri_list, uri);
+
+                       gtk_text_buffer_insert(buffer, &iter, " ", 1);
+                       gtk_text_buffer_get_iter_at_offset(buffer, &start_iter, uri->start);
+                       gtk_text_buffer_apply_tag_by_name(buffer, "link",
+                                               &start_iter, &iter);
+
                        END_TIMING();
                        GTK_EVENTS_FLUSH();
                }
@@ -809,7 +773,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();
 }
@@ -832,40 +806,40 @@ static void recursive_add_parts(TextView *textview, GNode *node)
                 return;
         }
         if (g_ascii_strcasecmp(mimeinfo->subtype, "alternative") == 0) {
-                GNode * prefered_body;
-                int prefered_score;
-                
+                GNode * preferred_body;
+                int preferred_score;
+
                 /*
                   text/plain : score 3
                   text/ *    : score 2
                   other      : score 1
                 */
-                prefered_body = NULL;
-                prefered_score = 0;
-                
+                preferred_body = NULL;
+                preferred_score = 0;
+
                 for (iter = g_node_first_child(node) ; iter != NULL ;
                      iter = g_node_next_sibling(iter)) {
                         int score;
                         MimeInfo * submime;
-                        
+
                         score = 1;
                         submime = (MimeInfo *) iter->data;
                         if (submime->type == MIMETYPE_TEXT)
                                 score = 2;
-                        
                         if (submime->subtype != NULL) {
                                 if (g_ascii_strcasecmp(submime->subtype, "plain") == 0)
                                         score = 3;
                         }
-                        
-                        if (score > prefered_score) {
-                                prefered_score = score;
-                                prefered_body = iter;
+
+                        if (score > preferred_score) {
+                                preferred_score = score;
+                                preferred_body = iter;
                         }
                 }
-                
-                if (prefered_body != NULL) {
-                        recursive_add_parts(textview, prefered_body);
+
+                if (preferred_body != NULL) {
+                        recursive_add_parts(textview, preferred_body);
                 }
         }
         else {
@@ -880,8 +854,9 @@ static void recursive_add_parts(TextView *textview, GNode *node)
 static void textview_add_parts(TextView *textview, MimeInfo *mimeinfo)
 {
        cm_return_if_fail(mimeinfo != NULL);
-        
-        recursive_add_parts(textview, mimeinfo->node);
+       cm_return_if_fail(mimeinfo->node != NULL);
+
+       recursive_add_parts(textview, mimeinfo->node);
 }
 
 void textview_show_error(TextView *textview)
@@ -931,8 +906,11 @@ void textview_show_mime_part(TextView *textview, MimeInfo *partinfo)
        GtkTextBuffer *buffer;
        GtkTextIter iter;
        const gchar *name;
-       gchar *content_type, *shortcut;
+       gchar *content_type;
        GtkUIManager *ui_manager;
+#ifndef GENERIC_UMPC
+       gchar *shortcut;
+#endif
 
        if (!partinfo) return;
 
@@ -1026,7 +1004,10 @@ static void textview_write_body(TextView *textview, MimeInfo *mimeinfo)
        FILE *tmpfp;
        gchar buf[BUFFSIZE];
        CodeConverter *conv;
-       const gchar *charset, *p, *cmd;
+       const gchar *charset;
+#ifndef G_OS_WIN32
+       const gchar *p, *cmd;
+#endif
        GSList *cur;
        gboolean continue_write = TRUE;
        size_t wrote = 0, i = 0;
@@ -1054,18 +1035,24 @@ static void textview_write_body(TextView *textview, MimeInfo *mimeinfo)
        
        textview->is_in_signature = FALSE;
        textview->is_diff = FALSE;
+       textview->is_attachment = FALSE;;
+       textview->is_in_git_patch = FALSE;
 
        procmime_decode_content(mimeinfo);
 
+       account_sigsep_matchlist_create();
+
        if (!g_ascii_strcasecmp(mimeinfo->subtype, "html") &&
            prefs_common.render_html) {
                gchar *filename;
                
                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);
+                       tmpfp = claws_fopen(filename, "rb");
+                       if (tmpfp) {
+                               textview_show_html(textview, tmpfp, conv);
+                               claws_fclose(tmpfp);
+                       }
                        claws_unlink(filename);
                }
                g_free(filename);
@@ -1074,9 +1061,11 @@ 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);
+                       tmpfp = claws_fopen(filename, "rb");
+                       if (tmpfp) {
+                               textview_show_ertf(textview, tmpfp, conv);
+                               claws_fclose(tmpfp);
+                       }
                        claws_unlink(filename);
                }
                g_free(filename);
@@ -1096,14 +1085,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]);
@@ -1117,6 +1106,7 @@ static void textview_write_body(TextView *textview, MimeInfo *mimeinfo)
                        close(pfd[0]);
                        rc = dup(pfd[1]);
                        rc = execvp(argv[0], argv);
+                       perror("execvp");
                        close(pfd[1]);
                        g_print(_("The command to view attachment "
                                "as text failed:\n"
@@ -1125,44 +1115,61 @@ static void textview_write_body(TextView *textview, MimeInfo *mimeinfo)
                        exit(255);
                }
                close(pfd[1]);
-               tmpfp = fdopen(pfd[0], "rb");
-               while (fgets(buf, sizeof(buf), tmpfp)) {
+               tmpfp = claws_fdopen(pfd[0], "rb");
+               while (claws_fgets(buf, sizeof(buf), tmpfp)) {
                        textview_write_line(textview, buf, conv, TRUE);
                        
                        if (textview->stop_loading) {
-                               fclose(tmpfp);
+                               claws_fclose(tmpfp);
                                waitpid(pid, pfd, 0);
                                g_unlink(fname);
+                               account_sigsep_matchlist_delete();
                                return;
                        }
                }
 
-               fclose(tmpfp);
+               claws_fclose(tmpfp);
                waitpid(pid, pfd, 0);
                g_unlink(fname);
 #endif
        } else {
+#ifndef G_OS_WIN32
 textview_default:
+#endif
                if (!g_ascii_strcasecmp(mimeinfo->subtype, "x-patch")
                                || !g_ascii_strcasecmp(mimeinfo->subtype, "x-diff"))
                        textview->is_diff = TRUE;
 
+               /* Displayed part is an attachment, but not an attached
+                * e-mail. Set a flag, so that elsewhere in the code we
+                * know not to try making collapsible quotes in it. */
+               if (mimeinfo->disposition == DISPOSITIONTYPE_ATTACHMENT &&
+                               mimeinfo->type != MIMETYPE_MESSAGE)
+                       textview->is_attachment = TRUE;
+
                if (mimeinfo->content == MIMECONTENT_MEM)
                        tmpfp = str_open_as_stream(mimeinfo->data.mem);
                else
-                       tmpfp = g_fopen(mimeinfo->data.filename, "rb");
+                       tmpfp = claws_fopen(mimeinfo->data.filename, "rb");
                if (!tmpfp) {
-                       FILE_OP_ERROR(mimeinfo->data.filename, "fopen");
+                       FILE_OP_ERROR(mimeinfo->data.filename, "claws_fopen");
+                       account_sigsep_matchlist_delete();
+                       return;
+               }
+               if (fseek(tmpfp, mimeinfo->offset, SEEK_SET) < 0) {
+                       FILE_OP_ERROR(mimeinfo->data.filename, "fseek");
+                       claws_fclose(tmpfp);
+                       account_sigsep_matchlist_delete();
                        return;
                }
-               fseek(tmpfp, mimeinfo->offset, SEEK_SET);
                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)
+                      (claws_fgets(buf, sizeof(buf), tmpfp) != NULL)
                       && continue_write) {
                        textview_write_line(textview, buf, conv, TRUE);
                        if (textview->stop_loading) {
-                               fclose(tmpfp);
+                               claws_fclose(tmpfp);
+                               account_sigsep_matchlist_delete();
                                return;
                        }
                        wrote += ftell(tmpfp)-i;
@@ -1172,9 +1179,11 @@ textview_default:
                                continue_write = FALSE;
                        }
                }
-               fclose(tmpfp);
+               claws_fclose(tmpfp);
        }
 
+       account_sigsep_matchlist_delete();
+
        conv_code_converter_destroy(conv);
        procmime_force_encoding(0);
 
@@ -1211,6 +1220,8 @@ static void textview_show_html(TextView *textview, FILE *fp,
        parser = sc_html_parser_new(fp, conv);
        cm_return_if_fail(parser != NULL);
 
+       account_sigsep_matchlist_create();
+
        while ((str = sc_html_parse(parser)) != NULL) {
                if (parser->state == SC_HTML_HREF) {
                        /* first time : get and copy the URL */
@@ -1235,10 +1246,14 @@ static void textview_show_html(TextView *textview, FILE *fp,
                if (lines % 500 == 0)
                        GTK_EVENTS_FLUSH();
                if (textview->stop_loading) {
+                       account_sigsep_matchlist_delete();
                        return;
                }
        }
        textview_write_line(textview, "\n", NULL, FALSE);
+
+       account_sigsep_matchlist_delete();
+
        sc_html_parser_destroy(parser);
 }
 
@@ -1252,16 +1267,21 @@ static void textview_show_ertf(TextView *textview, FILE *fp,
        parser = ertf_parser_new(fp, conv);
        cm_return_if_fail(parser != NULL);
 
+       account_sigsep_matchlist_create();
+
        while ((str = ertf_parse(parser)) != NULL) {
                textview_write_line(textview, str, NULL, FALSE);
                lines++;
                if (lines % 500 == 0)
                        GTK_EVENTS_FLUSH();
                if (textview->stop_loading) {
+                       account_sigsep_matchlist_delete();
                        return;
                }
        }
        
+       account_sigsep_matchlist_delete();
+
        ertf_parser_destroy(parser);
 }
 
@@ -1271,7 +1291,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); \
@@ -1284,7 +1304,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 */
@@ -1566,7 +1586,8 @@ 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 
+       if (prefs_common.enable_color
+           && !textview->is_attachment
            && line_has_quote_char(buf, prefs_common.quote_chars)) {
                real_quotelevel = get_quote_level(buf, prefs_common.quote_chars);
                quotelevel = real_quotelevel;
@@ -1589,7 +1610,7 @@ static void textview_write_line(TextView *textview, const gchar *str,
        }
 
        if (prefs_common.enable_color) {
-               if (textview->is_diff) {
+               if (textview->is_diff || textview->is_in_git_patch) {
                        if (strncmp(buf, "+++ ", 4) == 0)
                                fg_color = "diff-add-file";
                        else if (buf[0] == '+')
@@ -1599,17 +1620,25 @@ static void textview_write_line(TextView *textview, const gchar *str,
                        else if (buf[0] == '-')
                                fg_color = "diff-del";
                        else if (strncmp(buf, "@@ ", 3) == 0 &&
-                                       strcmp(buf+strlen(buf)-4, " @@\n") == 0)
+                                strstr(&buf[3], " @@"))
                                fg_color = "diff-hunk";
-               } else if (strcmp(buf,"-- \n") == 0
-                               || strcmp(buf, "- -- \n") == 0
+
+                       if (account_sigsep_matchlist_nchar_found(buf, "%s\n")) {
+                               textview->is_in_git_patch = FALSE;
+                               textview->is_in_signature = TRUE;
+                               fg_color = "signature";
+                       }
+               } else if (account_sigsep_matchlist_str_found(buf, "%s\n")
+                               || account_sigsep_matchlist_str_found(buf, "- %s\n")
                                || textview->is_in_signature) {
                        fg_color = "signature";
                        textview->is_in_signature = TRUE;
+               } else if (strncmp(buf, "diff --git ", 11) == 0) {
+                       textview->is_in_git_patch = TRUE;
                }
        }
 
-       if (real_quotelevel > -1 && do_quote_folding) {
+       if (!textview->is_attachment && real_quotelevel > -1 && do_quote_folding) {
                if (!g_utf8_validate(buf, -1, NULL)) {
                        gchar *utf8buf = NULL;
                        utf8buf = g_malloc(BUFFSIZE);
@@ -1737,6 +1766,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);
@@ -1863,27 +1896,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-Claws-Auto-Wrapping:", "X-Claws-Auto-Indent:",
-                "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];
@@ -1899,7 +1911,7 @@ static GPtrArray *textview_scan_header(TextView *textview, FILE *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);
@@ -1909,7 +1921,7 @@ static GPtrArray *textview_scan_header(TextView *textview, FILE *fp)
        }
 
        if (!prefs_common.display_header) {
-               while (fgets(buf, sizeof(buf), fp) != NULL)
+               while (claws_fgets(buf, sizeof(buf), fp) != NULL)
                        if (buf[0] == '\r' || buf[0] == '\n') break;
                return NULL;
        }
@@ -1942,7 +1954,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);
@@ -2029,7 +2041,7 @@ void textview_show_icon(TextView *textview, const gchar *stock_id)
 
 static void textview_save_contact_pic(TextView *textview)
 {
-#ifndef USE_NEW_ADDRBOOK
+#ifndef USE_ALT_ADDRBOOK
        MsgInfo *msginfo = textview->messageview->msginfo;
        gchar *filename = NULL;
        GError *error = NULL;
@@ -2050,7 +2062,7 @@ 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);
                }
@@ -2063,7 +2075,7 @@ static void textview_save_contact_pic(TextView *textview)
 
 static void textview_show_contact_pic(TextView *textview)
 {
-#ifndef USE_NEW_ADDRBOOK
+#ifndef USE_ALT_ADDRBOOK
        MsgInfo *msginfo = textview->messageview->msginfo;
        GtkTextView *text = GTK_TEXT_VIEW(textview->text);
        int x = 0;
@@ -2101,7 +2113,7 @@ static void textview_show_contact_pic(TextView *textview)
                picture = gdk_pixbuf_new_from_file(filename, &error);
 
        if (error) {
-               debug_print("Failed to import image: \n%s",
+               debug_print("Failed to import image: %s\n",
                                error->message);
                g_error_free(error);
                goto bail;
@@ -2246,9 +2258,14 @@ static void textview_show_header(TextView *textview, GPtrArray *headers)
                                 "header_title", "header", NULL);
 
                if (procheader_headername_equal(header->name, "Subject") ||
-                   procheader_headername_equal(header->name, "From")    ||
-                   procheader_headername_equal(header->name, "To")      ||
-                   procheader_headername_equal(header->name, "Cc"))
+                   procheader_headername_equal(header->name, "From") ||
+                   procheader_headername_equal(header->name, "To") ||
+                   procheader_headername_equal(header->name, "Cc") ||
+                   procheader_headername_equal(header->name, "Bcc") ||
+                   procheader_headername_equal(header->name, "Reply-To") ||
+                   procheader_headername_equal(header->name, "Sender") ||
+                   procheader_headername_equal(header->name, "Resent-From") ||
+                   procheader_headername_equal(header->name, "Resent-To"))
                        unfold_line(header->body);
                
                if (procheader_headername_equal(header->name, "Date") &&
@@ -2275,7 +2292,9 @@ static void textview_show_header(TextView *textview, GPtrArray *headers)
                          procheader_headername_equal(header->name, "Cc") ||
                          procheader_headername_equal(header->name, "Bcc") ||
                          procheader_headername_equal(header->name, "Reply-To") ||
-                         procheader_headername_equal(header->name, "Sender");
+                         procheader_headername_equal(header->name, "Sender") ||
+                         procheader_headername_equal(header->name, "Resent-From") ||
+                         procheader_headername_equal(header->name, "Resent-To");
                        textview_make_clickable_parts(textview, "header", 
                                                      "hlink", header->body, 
                                                      hdr);
@@ -2286,8 +2305,8 @@ static void textview_show_header(TextView *textview, GPtrArray *headers)
        }
        
        textview_show_avatar(textview);
-
-       textview_save_contact_pic(textview);
+       if (prefs_common.save_xface)
+               textview_save_contact_pic(textview);
        textview_show_contact_pic(textview);
 }
 
@@ -2347,9 +2366,10 @@ void textview_scroll_max(TextView *textview, gboolean up)
 static gint textview_key_pressed(GtkWidget *widget, GdkEventKey *event,
                                 TextView *textview)
 {
-       GdkWindow *window;
+       GdkWindow *window = NULL;
        SummaryView *summaryview = NULL;
        MessageView *messageview = textview->messageview;
+       gboolean mod_pressed;
 
        if (!event) return FALSE;
        if (messageview->mainwin)
@@ -2361,8 +2381,6 @@ static gint textview_key_pressed(GtkWidget *widget, GdkEventKey *event,
        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;
@@ -2371,14 +2389,19 @@ static gint textview_key_pressed(GtkWidget *widget, GdkEventKey *event,
                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
-                       mimeview_scroll_page
-                               (messageview->mimeview,
-                                (event->state &
-                                 (GDK_SHIFT_MASK|GDK_MOD1_MASK)) != 0);
+               mod_pressed = ((event->state & (GDK_SHIFT_MASK|GDK_MOD1_MASK)) != 0);
+               if (!mimeview_scroll_page(messageview->mimeview, mod_pressed) &&
+                               summaryview != NULL) {
+                       if (mod_pressed)
+                               summary_select_prev_unread(summaryview);
+                       else
+                               summary_select_next_unread(summaryview);
+               }
                break;
+       case GDK_KEY_Page_Down:
+               mimeview_scroll_page(messageview->mimeview, FALSE);
+               break;
+       case GDK_KEY_Page_Up:
        case GDK_KEY_BackSpace:
                mimeview_scroll_page(messageview->mimeview, TRUE);
                break;
@@ -2393,15 +2416,17 @@ static gint textview_key_pressed(GtkWidget *widget, GdkEventKey *event,
                        summary_pass_key_press_event(summaryview, event);
                break;
        default:
-               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);
+               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;
        }
@@ -2766,9 +2791,11 @@ static gboolean textview_uri_button_pressed(GtkTextTag *tag, GObject *obj,
                        } 
                        return TRUE;
                } else if (qlink && bevent->button == 1) {
-                       if (prefs_common.hide_quoted)
+                       if (prefs_common.hide_quoted) {
                                textview_toggle_quote(textview, NULL, uri, FALSE);
-                       return TRUE;
+                               return TRUE;
+                       } else
+                               return FALSE;
                } else if (!g_ascii_strncasecmp(uri->uri, "mailto:", 7)) {
                        if (bevent->button == 3) {
                                g_object_set_data(
@@ -2880,18 +2907,17 @@ 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);
+                                      GTK_STOCK_CANCEL, _("_Open URL"), NULL, ALERTFOCUS_FIRST,
+                                                        FALSE, NULL, ALERT_WARNING);
                g_free(msg);
                if (aval == G_ALERTALTERNATE)
                        retval = TRUE;
@@ -2943,146 +2969,6 @@ static void open_uri_cb (GtkAction *action, TextView *textview)
        }
 }
 
-static void open_image_cb (GtkAction *action, TextView *textview)
-{
-       ClickableText *uri = g_object_get_data(G_OBJECT(textview->file_popup_menu),
-                                          "menu_button");
-
-       gchar *cmd = NULL;
-       gchar buf[1024];
-       const gchar *p;
-       gchar *filename = NULL;
-       gchar *tmp_filename = NULL;
-
-       if (uri == NULL)
-               return;
-
-       if (uri->filename == NULL)
-               return;
-       
-       filename = g_strdup(uri->filename);
-       
-       if (!g_utf8_validate(filename, -1, NULL)) {
-               gchar *tmp = conv_filename_to_utf8(filename);
-               g_free(filename);
-               filename = tmp;
-       }
-
-       subst_for_filename(filename);
-
-       tmp_filename = g_filename_from_uri(uri->uri, NULL, NULL);
-       copy_file(tmp_filename, filename, FALSE);
-       g_free(tmp_filename);
-
-       cmd = mailcap_get_command_for_type("image/jpeg", filename);
-       if (cmd == NULL) {
-               gboolean remember = FALSE;
-               cmd = input_dialog_combo_remember
-                       (_("Open with"),
-                        _("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,
-                        &remember);
-               if (cmd && remember) {
-                       mailcap_update_default("image/jpeg", cmd);
-               }
-       }
-       if (cmd && (p = strchr(cmd, '%')) && *(p + 1) == 's' &&
-           !strchr(p + 2, '%'))
-               g_snprintf(buf, sizeof(buf), cmd, filename);
-       else {
-               g_warning("Image viewer command-line is invalid: '%s'", cmd);
-               return;
-       }
-
-       execute_command_line(buf, TRUE);
-
-       g_free(filename);
-       g_free(cmd);
-
-       g_object_set_data(G_OBJECT(textview->file_popup_menu), "menu_button",
-                         NULL);
-}
-
-static void save_file_cb (GtkAction *action, TextView *textview)
-{
-       ClickableText *uri = g_object_get_data(G_OBJECT(textview->file_popup_menu),
-                                          "menu_button");
-       gchar *filename = NULL;
-       gchar *filepath = NULL;
-       gchar *filedir = NULL;
-       gchar *tmp_filename = NULL;
-       GtkWidget *window;
-
-       if (uri == NULL)
-               return;
-
-       if (uri->filename == NULL)
-               return;
-       
-       filename = g_strdup(uri->filename);
-       
-       if (!g_utf8_validate(filename, -1, NULL)) {
-               gchar *tmp = conv_filename_to_utf8(filename);
-               g_free(filename);
-               filename = tmp;
-       }
-
-       subst_for_filename(filename);
-       
-       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);
-
-       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);
-               return;
-       }
-
-       if (is_file_exist(filename)) {
-               AlertValue aval;
-               gchar *res;
-               
-               res = g_strdup_printf(_("Overwrite existing file '%s'?"),
-                                     filename);
-               aval = alertpanel(_("Overwrite"), res, GTK_STOCK_CANCEL, 
-                                 GTK_STOCK_OK, NULL);
-               g_free(res);                                      
-               if (G_ALERTALTERNATE != aval)
-                       return;
-       }
-
-       tmp_filename = g_filename_from_uri(uri->uri, NULL, NULL);
-       copy_file(tmp_filename, filename, FALSE);
-       g_free(tmp_filename);
-       
-       filedir = g_path_get_dirname(filename);
-       if (filedir && strcmp(filedir, ".")) {
-               g_free(prefs_common.attach_save_dir);
-               prefs_common.attach_save_dir = g_filename_to_utf8(filedir, -1, NULL, NULL, NULL);
-       }
-
-       g_free(filedir);
-       g_free(filepath);
-
-       g_object_set_data(G_OBJECT(textview->file_popup_menu), "menu_button",
-                         NULL);
-}
-
 static void copy_uri_cb        (GtkAction *action, TextView *textview)
 {
        ClickableText *uri = g_object_get_data(G_OBJECT(textview->link_popup_menu),
@@ -3090,16 +2976,16 @@ static void copy_uri_cb (GtkAction *action, TextView *textview)
        const gchar *raw_url =  g_object_get_data(G_OBJECT(textview->link_popup_menu),
                                           "raw_url");
        if (uri) {
-               gtk_clipboard_set_text(gtk_clipboard_get(GDK_SELECTION_PRIMARY), uri->uri, -1);
-               gtk_clipboard_set_text(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD), uri->uri, -1);
-               g_object_set_data(G_OBJECT(textview->link_popup_menu), "menu_button",
-                         NULL);
+               if (textview_uri_security_check(textview, uri) == TRUE) {
+                       gtk_clipboard_set_text(gtk_clipboard_get(GDK_SELECTION_PRIMARY), uri->uri, -1);
+                       gtk_clipboard_set_text(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD), uri->uri, -1);
+                       g_object_set_data(G_OBJECT(textview->link_popup_menu), "menu_button", NULL);
+               }
        }
        if (raw_url) {
                gtk_clipboard_set_text(gtk_clipboard_get(GDK_SELECTION_PRIMARY), raw_url, -1);
                gtk_clipboard_set_text(gtk_clipboard_get(GDK_SELECTION_CLIPBOARD), raw_url, -1);
-               g_object_set_data(G_OBJECT(textview->link_popup_menu), "raw_url",
-                         NULL);
+               g_object_set_data(G_OBJECT(textview->link_popup_menu), "raw_url", NULL);
        }
 }
 
@@ -3119,7 +3005,7 @@ static void add_uri_to_addrbook_cb (GtkAction *action, TextView *textview)
        fromaddress = g_strdup(uri->uri + 7);
        
        if (textview->messageview->msginfo &&
-          !strcmp2(fromaddress, textview->messageview->msginfo->from))
+          !g_strcmp0(fromaddress, textview->messageview->msginfo->from))
                use_picture = TRUE;
 
        fromname = procheader_get_fromname(fromaddress);
@@ -3137,7 +3023,7 @@ static void add_uri_to_addrbook_cb (GtkAction *action, TextView *textview)
                avatars_avatarrender_free(avatarr);
        }
 
-#ifndef USE_NEW_ADDRBOOK
+#ifndef USE_ALT_ADDRBOOK
        addressbook_add_contact( fromname, fromaddress, NULL, picture);
 #else
        if (addressadd_selection(fromname, fromaddress, NULL, picture)) {