2009-03-23 [colin] 3.7.1cvs24
[claws.git] / src / textview.c
index f4de73ce951ea9d888ceb50abdfc6c004f62fb4c..89134e88a3ff13088c73e3436c3cdeea6fe8e907 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
+ * Copyright (C) 1999-2009 Hiroyuki Yamamoto and 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
@@ -27,9 +27,7 @@
 #include <glib/gi18n.h>
 #include <gdk/gdk.h>
 #include <gdk/gdkkeysyms.h>
-#include <gtk/gtkvbox.h>
-#include <gtk/gtkscrolledwindow.h>
-#include <gtk/gtksignal.h>
+#include <gtk/gtk.h>
 #include <stdio.h>
 #include <ctype.h>
 #include <string.h>
@@ -187,46 +185,42 @@ static void textview_toggle_quote         (TextView       *textview,
                                                 ClickableText  *uri,
                                                 gboolean        expand_only);
 
-static void open_uri_cb                                (TextView       *textview,
-                                                guint           action,
-                                                void           *data);
-static void copy_uri_cb                                (TextView       *textview,
-                                                guint           action,
-                                                void           *data);
-static void add_uri_to_addrbook_cb             (TextView       *textview, 
-                                                guint           action, 
-                                                void           *data);
-static void mail_to_uri_cb                     (TextView       *textview, 
-                                                guint           action, 
-                                                void           *data);
-static void copy_mail_to_uri_cb                        (TextView       *textview,
-                                                guint           action,
-                                                void           *data);
-static void save_file_cb                       (TextView       *textview,
-                                                guint           action,
-                                                void           *data);
-static void open_image_cb                      (TextView       *textview,
-                                                guint           action,
-                                                void           *data);
+static void open_uri_cb                                (GtkAction      *action,
+                                                TextView       *textview);
+static void copy_uri_cb                                (GtkAction      *action,
+                                                TextView       *textview);
+static void add_uri_to_addrbook_cb             (GtkAction      *action,
+                                                TextView       *textview);
+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 GtkItemFactoryEntry textview_link_popup_entries[] = 
+static GtkActionEntry textview_link_popup_entries[] = 
 {
-       {N_("/_Open with Web browser"), NULL, open_uri_cb, 0, NULL},
-       {N_("/Copy this _link"),        NULL, copy_uri_cb, 0, NULL},
+       {"TextviewPopupLink",                   NULL, "TextviewPopupLink" },
+       {"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 GtkItemFactoryEntry textview_mail_popup_entries[] = 
+static GtkActionEntry textview_mail_popup_entries[] = 
 {
-       {N_("/Compose _new message"),   NULL, mail_to_uri_cb, 0, NULL},
-       {N_("/Add to _address book"),   NULL, add_uri_to_addrbook_cb, 0, NULL},
-       {N_("/Copy this add_ress"),     NULL, copy_mail_to_uri_cb, 0, NULL},
+       {"TextviewPopupMail",                   NULL, "TextviewPopupMail" },
+       {"TextviewPopupMail/Compose",           NULL, N_("Compose _new message"), NULL, NULL, G_CALLBACK(mail_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 GtkItemFactoryEntry textview_file_popup_entries[] = 
+static GtkActionEntry textview_file_popup_entries[] = 
 {
-       {N_("/_Open image"),            NULL, open_image_cb, 0, NULL},
-       {N_("/_Save image..."),         NULL, save_file_cb, 0, NULL},
+       {"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)
@@ -261,10 +255,7 @@ TextView *textview_create(void)
        GtkWidget *text;
        GtkTextBuffer *buffer;
        GtkClipboard *clipboard;
-       GtkItemFactory *link_popupfactory, *mail_popupfactory, *file_popupfactory;
-       GtkWidget *link_popupmenu, *mail_popupmenu, *file_popupmenu;
        GtkAdjustment *adj;
-       gint n_entries;
 
        debug_print("Creating text view...\n");
        textview = g_new0(TextView, 1);
@@ -294,7 +285,7 @@ TextView *textview_create(void)
 
        gtk_widget_ensure_style(text);
 
-       gtk_widget_ref(scrolledwin);
+       g_object_ref(scrolledwin);
 
        gtk_container_add(GTK_CONTAINER(scrolledwin), text);
 
@@ -322,23 +313,50 @@ TextView *textview_create(void)
 
        gtk_widget_show(vbox);
 
-       n_entries = sizeof(textview_link_popup_entries) /
-               sizeof(textview_link_popup_entries[0]);
-       link_popupmenu = menu_create_items(textview_link_popup_entries, n_entries,
-                                     "<UriPopupMenu>", &link_popupfactory,
-                                     textview);
-
-       n_entries = sizeof(textview_mail_popup_entries) /
-               sizeof(textview_mail_popup_entries[0]);
-       mail_popupmenu = menu_create_items(textview_mail_popup_entries, n_entries,
-                                     "<UriPopupMenu>", &mail_popupfactory,
-                                     textview);
-
-       n_entries = sizeof(textview_file_popup_entries) /
-               sizeof(textview_file_popup_entries[0]);
-       file_popupmenu = menu_create_items(textview_file_popup_entries, n_entries,
-                                     "<FilePopupMenu>", &file_popupfactory,
-                                     textview);
+       
+       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_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_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)
+       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", "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;
@@ -347,12 +365,6 @@ TextView *textview_create(void)
        textview->body_pos           = 0;
        textview->show_all_headers   = FALSE;
        textview->last_buttonpress   = GDK_NOTHING;
-       textview->link_popup_menu    = link_popupmenu;
-       textview->link_popup_factory = link_popupfactory;
-       textview->mail_popup_menu    = mail_popupmenu;
-       textview->mail_popup_factory = mail_popupfactory;
-       textview->file_popup_menu    = file_popupmenu;
-       textview->file_popup_factory = file_popupfactory;
        textview->image              = NULL;
        return textview;
 }
@@ -564,8 +576,8 @@ 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"))) {
@@ -610,7 +622,7 @@ static void textview_add_part(TextView *textview, MimeInfo *mimeinfo)
        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);
@@ -764,7 +776,7 @@ static void recursive_add_parts(TextView *textview, GNode *node)
         mimeinfo = (MimeInfo *) node->data;
         
         textview_add_part(textview, mimeinfo);
-#ifdef MAEMO
+#ifdef GENERIC_UMPC
        textview_set_position(textview, 0);
 #endif        
         if ((mimeinfo->type != MIMETYPE_MULTIPART) &&
@@ -820,7 +832,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);
 }
@@ -879,20 +891,20 @@ void textview_show_mime_part(TextView *textview, MimeInfo *partinfo)
                TEXTVIEW_INSERT(" (");
                TEXTVIEW_INSERT(content_type);
                TEXTVIEW_INSERT(", ");
-               TEXTVIEW_INSERT(to_human_readable(partinfo->length));
+               TEXTVIEW_INSERT(to_human_readable((goffset)partinfo->length));
                TEXTVIEW_INSERT("):\n\n");
                
                g_free(content_type);
        }
        TEXTVIEW_INSERT(_("  The following can be performed on this part\n"));
-#ifndef MAEMO
+#ifndef GENERIC_UMPC
        TEXTVIEW_INSERT(_("  by right-clicking the icon or list item:"));
 #endif
        TEXTVIEW_INSERT("\n");
 
        TEXTVIEW_INSERT(_("     - To save, select "));
        TEXTVIEW_INSERT_LINK(_("'Save as...'"), "sc://save_as", NULL);
-#ifndef MAEMO
+#ifndef GENERIC_UMPC
        TEXTVIEW_INSERT(_(" (Shortcut key: 'y')"));
 #endif
        TEXTVIEW_INSERT("\n");
@@ -900,7 +912,7 @@ void textview_show_mime_part(TextView *textview, MimeInfo *partinfo)
        TEXTVIEW_INSERT(_("     - To display as text, select "));
        TEXTVIEW_INSERT_LINK(_("'Display as text'"), "sc://display_as_text", NULL);
 
-#ifndef MAEMO
+#ifndef GENERIC_UMPC
        TEXTVIEW_INSERT(_(" (Shortcut key: 't')"));
 #endif
        TEXTVIEW_INSERT("\n");
@@ -908,13 +920,15 @@ void textview_show_mime_part(TextView *textview, MimeInfo *partinfo)
        TEXTVIEW_INSERT(_("     - To open with an external program, select "));
        TEXTVIEW_INSERT_LINK(_("'Open'"), "sc://open", NULL);
 
-#ifndef MAEMO
+#ifndef GENERIC_UMPC
        TEXTVIEW_INSERT(_(" (Shortcut key: 'l')\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')"));
+#endif
 #endif
        TEXTVIEW_INSERT("\n");
 
@@ -933,8 +947,11 @@ static void textview_write_body(TextView *textview, MimeInfo *mimeinfo)
 
        if (textview->messageview->forced_charset)
                charset = textview->messageview->forced_charset;
-       else
+       else {
                charset = procmime_mimeinfo_get_parameter(mimeinfo, "charset");
+               if (charset && !strcasecmp(charset, CS_ISO_8859_1))
+                       charset = CS_WINDOWS_1252;
+       }
 
        textview_set_font(textview, charset);
 
@@ -955,7 +972,7 @@ static void textview_write_body(TextView *textview, MimeInfo *mimeinfo)
                        tmpfp = g_fopen(filename, "rb");
                        textview_show_html(textview, tmpfp, conv);
                        fclose(tmpfp);
-                       g_unlink(filename);
+                       claws_unlink(filename);
                }
                g_free(filename);
        } else if (!g_ascii_strcasecmp(mimeinfo->subtype, "enriched")) {
@@ -966,7 +983,7 @@ static void textview_write_body(TextView *textview, MimeInfo *mimeinfo)
                        tmpfp = g_fopen(filename, "rb");
                        textview_show_ertf(textview, tmpfp, conv);
                        fclose(tmpfp);
-                       g_unlink(filename);
+                       claws_unlink(filename);
                }
                g_free(filename);
 #ifndef G_OS_WIN32
@@ -1021,14 +1038,14 @@ 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:
@@ -1094,7 +1111,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 +1152,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);
@@ -1518,16 +1535,18 @@ 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 ? 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';
                        }
-                       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);
@@ -1703,8 +1722,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);
 
@@ -1745,6 +1764,7 @@ static gboolean header_is_internal(Header *header)
                 "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;
@@ -1764,7 +1784,7 @@ 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) {
                headers = procheader_get_header_array_asis(fp);
@@ -1846,7 +1866,7 @@ static void textview_show_face(TextView *textview)
                gtk_widget_destroy(textview->image);
        
        textview->image = face_get_from_header(msginfo->extradata->face);
-       g_return_if_fail(textview->image != NULL);
+       cm_return_if_fail(textview->image != NULL);
 
        gtk_widget_show(textview->image);
        
@@ -1874,7 +1894,7 @@ 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);
        
@@ -1920,7 +1940,7 @@ static void textview_show_xface(TextView *textview)
        textview->image = xface_get_from_header(msginfo->extradata->xface,
                                &textview->text->style->white,
                                window);
-       g_return_if_fail(textview->image != NULL);
+       cm_return_if_fail(textview->image != NULL);
 
        gtk_widget_show(textview->image);
        
@@ -2016,7 +2036,7 @@ 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);
        
@@ -2119,11 +2139,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) {
@@ -2426,17 +2446,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);
                }
        }
 }
@@ -2750,6 +2765,8 @@ gboolean textview_uri_security_check(TextView *textview, ClickableText *uri)
        if (visible_str == NULL)
                return TRUE;
 
+       g_strstrip(visible_str);
+
        if (strcmp(visible_str, uri->uri) != 0 && is_uri_string(visible_str)) {
                gchar *uri_path;
                gchar *visible_uri_path;
@@ -2806,21 +2823,28 @@ static void textview_uri_list_remove_all(GSList *uri_list)
        g_slist_free(uri_list);
 }
 
-static void open_uri_cb (TextView *textview, guint action, void *data)
+static void open_uri_cb (GtkAction *action, TextView *textview)
 {
        ClickableText *uri = g_object_get_data(G_OBJECT(textview->link_popup_menu),
                                           "menu_button");
-       if (uri == NULL)
-               return;
+       const gchar *raw_url = g_object_get_data(G_OBJECT(textview->link_popup_menu),
+                                          "raw_url");
 
-       if (textview_uri_security_check(textview, uri) == TRUE) 
-               open_uri(uri->uri,
-                        prefs_common_get_uri_cmd());
-       g_object_set_data(G_OBJECT(textview->link_popup_menu), "menu_button",
-                         NULL);
+       if (uri) {
+               if (textview_uri_security_check(textview, uri) == TRUE) 
+                       open_uri(uri->uri,
+                                prefs_common_get_uri_cmd());
+               g_object_set_data(G_OBJECT(textview->link_popup_menu), "menu_button",
+                                 NULL);
+       }
+       if (raw_url) {
+               open_uri(raw_url, prefs_common_get_uri_cmd());
+               g_object_set_data(G_OBJECT(textview->link_popup_menu), "raw_url",
+                                 NULL);
+       }
 }
 
-static void open_image_cb (TextView *textview, guint action, void *data)
+static void open_image_cb (GtkAction *action, TextView *textview)
 {
        ClickableText *uri = g_object_get_data(G_OBJECT(textview->file_popup_menu),
                                           "menu_button");
@@ -2856,7 +2880,7 @@ static void open_image_cb (TextView *textview, guint action, void *data)
                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,
@@ -2869,7 +2893,7 @@ static void open_image_cb (TextView *textview, guint action, void *data)
            !strchr(p + 2, '%'))
                g_snprintf(buf, sizeof(buf), cmd, filename);
        else {
-               g_warning("Image viewer command line is invalid: '%s'", cmd);
+               g_warning("Image viewer command-line is invalid: '%s'", cmd);
                return;
        }
 
@@ -2882,7 +2906,7 @@ static void open_image_cb (TextView *textview, guint action, void *data)
                          NULL);
 }
 
-static void save_file_cb (TextView *textview, guint action, void *data)
+static void save_file_cb (GtkAction *action, TextView *textview)
 {
        ClickableText *uri = g_object_get_data(G_OBJECT(textview->file_popup_menu),
                                           "menu_button");
@@ -2906,7 +2930,7 @@ static void save_file_cb (TextView *textview, guint action, void *data)
 
        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
@@ -2950,20 +2974,27 @@ static void save_file_cb (TextView *textview, guint action, void *data)
                          NULL);
 }
 
-static void copy_uri_cb        (TextView *textview, guint action, void *data)
+static void copy_uri_cb        (GtkAction *action, TextView *textview)
 {
        ClickableText *uri = g_object_get_data(G_OBJECT(textview->link_popup_menu),
                                           "menu_button");
-       if (uri == NULL)
-               return;
-
-       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",
+       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 (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);
+       }
 }
 
-static void add_uri_to_addrbook_cb (TextView *textview, guint action, void *data)
+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),
@@ -3009,7 +3040,7 @@ static void add_uri_to_addrbook_cb (TextView *textview, guint action, void *data
        g_free(fromname);
 }
 
-static void mail_to_uri_cb (TextView *textview, guint action, void *data)
+static void mail_to_uri_cb (GtkAction *action, TextView *textview)
 {
        PrefsAccount *account = NULL;
        ClickableText *uri = g_object_get_data(G_OBJECT(textview->mail_popup_menu),
@@ -3031,7 +3062,7 @@ static void mail_to_uri_cb (TextView *textview, guint action, void *data)
        }
 }
 
-static void copy_mail_to_uri_cb        (TextView *textview, guint action, void *data)
+static void copy_mail_to_uri_cb        (GtkAction *action, TextView *textview)
 {
        ClickableText *uri = g_object_get_data(G_OBJECT(textview->mail_popup_menu),
                                           "menu_button");