2005-02-09 [colin] 1.0.1cvs1.3
[claws.git] / src / textview.c
index 550f398ebf7f4844722a9fd048fc8bd0f2fbf1c6..bda46c7147e7ff20376fe9fd587f23f971c449b0 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2004 Hiroyuki Yamamoto
+ * Copyright (C) 1999-2005 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
@@ -51,6 +51,7 @@
 #include "account.h"
 #include "mimeview.h"
 #include "alertpanel.h"
+#include "menu.h"
 
 struct _RemoteURI
 {
@@ -185,12 +186,31 @@ static gboolean textview_uri_security_check       (TextView       *textview,
                                                 RemoteURI      *uri);
 static void textview_uri_list_remove_all       (GSList         *uri_list);
 
+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 GtkItemFactoryEntry textview_link_popup_entries[] = 
+{
+       {N_("/_Open link"),             NULL, open_uri_cb, 0, NULL},
+       {N_("/_Copy link location"),    NULL, copy_uri_cb, 0, NULL},
+};
 
-static void populate_popup(GtkTextView *textview, GtkMenu *menu,
-                          gpointer *dummy)
+static GtkItemFactoryEntry textview_mail_popup_entries[] = 
 {
-       gtk_menu_detach(menu);
-}
+       {N_("/_Add to addressbook"),    NULL, add_uri_to_addrbook_cb, 0, NULL},
+       {N_("/_Email"),                 NULL, mail_to_uri_cb, 0, NULL},
+};
+
 
 TextView *textview_create(void)
 {
@@ -200,7 +220,9 @@ TextView *textview_create(void)
        GtkWidget *text;
        GtkTextBuffer *buffer;
        GtkClipboard *clipboard;
-       PangoFontDescription *font_desc = NULL;
+       GtkItemFactory *link_popupfactory, *mail_popupfactory;
+       GtkWidget *link_popupmenu, *mail_popupmenu;
+       gint n_entries;
 
        debug_print("Creating text view...\n");
        textview = g_new0(TextView, 1);
@@ -208,9 +230,10 @@ TextView *textview_create(void)
        scrolledwin = gtk_scrolled_window_new(NULL, NULL);
        gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
                                       GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
-       gtk_widget_set_size_request(scrolledwin, prefs_common.mainview_width, -1);
        gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwin),
                                            GTK_SHADOW_IN);
+       gtk_widget_set_size_request
+               (scrolledwin, prefs_common.mainview_width, -1);
 
        /* create GtkSText widgets for single-byte and multi-byte character */
        text = gtk_text_view_new();
@@ -219,9 +242,8 @@ TextView *textview_create(void)
        gtk_text_view_set_editable(GTK_TEXT_VIEW(text), FALSE);
        gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text), GTK_WRAP_WORD_CHAR);
        gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(text), FALSE);
-       g_signal_connect(G_OBJECT(text), "populate-popup",
-                G_CALLBACK(populate_popup), NULL);
-
+       gtk_text_view_set_left_margin(GTK_TEXT_VIEW(text), 6);
+       gtk_text_view_set_right_margin(GTK_TEXT_VIEW(text), 6);
 
        buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text));
        clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
@@ -229,14 +251,6 @@ TextView *textview_create(void)
 
        gtk_widget_ensure_style(text);
 
-       if (prefs_common.normalfont)
-               font_desc = pango_font_description_from_string
-                                       (prefs_common.normalfont);
-       if (font_desc) {
-               gtk_widget_modify_font(text, font_desc);
-       }
-       pango_font_description_free(font_desc);
-
        gtk_widget_ref(scrolledwin);
 
        gtk_container_add(GTK_CONTAINER(scrolledwin), text);
@@ -266,32 +280,63 @@ TextView *textview_create(void)
 
        gtk_widget_show(vbox);
 
-       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;
+       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);
+
+       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->link_popup_menu    = link_popupmenu;
+       textview->link_popup_factory = link_popupfactory;
+       textview->mail_popup_menu    = mail_popupmenu;
+       textview->mail_popup_factory = mail_popupfactory;
 
        return textview;
 }
 
 static void textview_create_tags(GtkTextView *text, TextView *textview)
 {
-       GtkTextBuffer *buffer = gtk_text_view_get_buffer(text);
+       GtkTextBuffer *buffer;
        GtkTextTag *tag;
+       static PangoFontDescription *font_desc, *bold_font_desc;
+
+       if (!font_desc)
+               font_desc = pango_font_description_from_string
+                       (NORMAL_FONT);
+
+       if (!bold_font_desc) {
+               bold_font_desc = pango_font_description_from_string
+                       (BOLD_FONT);
+               pango_font_description_set_weight
+                       (bold_font_desc, PANGO_WEIGHT_BOLD);
+       }
+
+       buffer = gtk_text_view_get_buffer(text);
 
        gtk_text_buffer_create_tag(buffer, "header",
                                   "pixels-above-lines", 0,
                                   "pixels-above-lines-set", TRUE,
                                   "pixels-below-lines", 0,
                                   "pixels-below-lines-set", TRUE,
+                                  "font-desc", font_desc,
                                   "left-margin", 0,
                                   "left-margin-set", TRUE,
                                   NULL);
        gtk_text_buffer_create_tag(buffer, "header_title",
-                                  "font", prefs_common.boldfont,
+                                  "font-desc", bold_font_desc,
                                   NULL);
        gtk_text_buffer_create_tag(buffer, "quote0",
                                   "foreground-gdk", &quote_colors[0],
@@ -321,11 +366,9 @@ static void textview_create_tags(GtkTextView *text, TextView *textview)
 
 void textview_init(TextView *textview)
 {
-       gtkut_widget_disable_theme_engine(textview->text);
        textview_update_message_colors();
        textview_set_all_headers(textview, FALSE);
        textview_set_font(textview, NULL);
-
        textview_create_tags(GTK_TEXT_VIEW(textview->text), textview);
 }
 
@@ -873,7 +916,7 @@ static gboolean get_email_part(const gchar *start, const gchar *scanpos,
 
        if (!result) return FALSE;
 
-       if (*(bp_ - 1) == '"' && *(ep_) == '"' 
+       if (*ep_ && *(bp_ - 1) == '"' && *(ep_) == '"' 
        && *(ep_ + 1) == ' ' && *(ep_ + 2) == '<'
        && IS_RFC822_CHAR(*(ep_ + 3))) {
                /* this informative part with an @ in it is 
@@ -1105,22 +1148,19 @@ static void textview_make_clickable_parts(TextView *textview,
                                                               last->ep);
                        uri->start = gtk_text_iter_get_offset(&iter);
                        gtk_text_buffer_insert_with_tags_by_name
-                               (buffer, &iter,
-                                last->bp, last->ep - last->bp,
-                                uri_tag, NULL);
+                               (buffer, &iter, last->bp, last->ep - last->bp,
+                                uri_tag, fg_tag, NULL);
                        uri->end = gtk_text_iter_get_offset(&iter);
                        textview->uri_list =
                                g_slist_append(textview->uri_list, uri);
                }
 
                if (*normal_text)
-                       gtk_text_buffer_insert_with_tags_by_name(buffer, &iter,
-                                                                normal_text, -1,
-                                                                fg_tag, NULL);
+                       gtk_text_buffer_insert_with_tags_by_name
+                               (buffer, &iter, normal_text, -1, fg_tag, NULL);
        } else {
-               gtk_text_buffer_insert_with_tags_by_name(buffer, &iter,
-                                                        linebuf, -1,
-                                                        fg_tag, NULL);
+               gtk_text_buffer_insert_with_tags_by_name
+                       (buffer, &iter, linebuf, -1, fg_tag, NULL);
        }
 }
 
@@ -1141,14 +1181,13 @@ static void textview_write_line(TextView *textview, const gchar *str,
        buffer = gtk_text_view_get_buffer(text);
        gtk_text_buffer_get_end_iter(buffer, &iter);
 
-       if (!conv) {
+       if (!conv)
                strncpy2(buf, str, sizeof(buf));
-       } else if (conv_convert(conv, buf, sizeof(buf), str) < 0) {
-               conv_localetodisp(buf, sizeof(buf), str);
-       }
+       else if (conv_convert(conv, buf, sizeof(buf), str) < 0)
+               conv_utf8todisp(buf, sizeof(buf), str);
 
        strcrchomp(buf);
-       if (prefs_common.conv_mb_alnum) conv_mb_alnum(buf);
+       //if (prefs_common.conv_mb_alnum) conv_mb_alnum(buf);
        fg_color = NULL;
 
        /* change color of quotation
@@ -1206,23 +1245,10 @@ void textview_write_link(TextView *textview, const gchar *str,
        buffer = gtk_text_view_get_buffer(text);
        gtk_text_buffer_get_end_iter(buffer, &iter);
 
-#warning FIXME_GTK2
-#if 0
-       if (!conv) {
-               if (textview->text_is_mb)
-                       conv_localetodisp(buf, sizeof(buf), str);
-               else
-                       strncpy2(buf, str, sizeof(buf));
-       } else if (conv_convert(conv, buf, sizeof(buf), str) < 0)
-               conv_localetodisp(buf, sizeof(buf), str);
-       else if (textview->text_is_mb)
-               conv_unreadable_locale(buf);
-#else
        if (!conv)
                strncpy2(buf, str, sizeof(buf));
        else if (conv_convert(conv, buf, sizeof(buf), str) < 0)
-               conv_localetodisp(buf, sizeof(buf), str);
-#endif
+               conv_utf8todisp(buf, sizeof(buf), str);
 
        strcrchomp(buf);
 
@@ -1237,8 +1263,8 @@ void textview_write_link(TextView *textview, const gchar *str,
        r_uri = g_new(RemoteURI, 1);
        r_uri->uri = g_strdup(uri);
        r_uri->start = gtk_text_iter_get_offset(&iter);
-       gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, bufp, -1,
-                                                "link", NULL);
+       gtk_text_buffer_insert_with_tags_by_name
+               (buffer, &iter, bufp, -1, "link", NULL);
        r_uri->end = gtk_text_iter_get_offset(&iter);
        textview->uri_list = g_slist_append(textview->uri_list, r_uri);
 }
@@ -1249,7 +1275,7 @@ void textview_clear(TextView *textview)
        GtkTextBuffer *buffer;
 
        buffer = gtk_text_view_get_buffer(text);
-       gtk_text_buffer_set_text(buffer, "\0", -1);
+       gtk_text_buffer_set_text(buffer, "", -1);
 
        TEXTVIEW_STATUSBAR_POP(textview);
        textview_uri_list_remove_all(textview->uri_list);
@@ -1276,8 +1302,7 @@ void textview_set_font(TextView *textview, const gchar *codeset)
        if (prefs_common.textfont) {
                PangoFontDescription *font_desc = NULL;
 
-               if (prefs_common.textfont)
-                       font_desc = pango_font_description_from_string
+               font_desc = pango_font_description_from_string
                                                (prefs_common.textfont);
                if (font_desc) {
                        gtk_widget_modify_font(textview->text, font_desc);
@@ -1288,11 +1313,6 @@ void textview_set_font(TextView *textview, const gchar *codeset)
                                             prefs_common.line_space / 2);
        gtk_text_view_set_pixels_below_lines(GTK_TEXT_VIEW(textview->text),
                                             prefs_common.line_space / 2);
-       if (prefs_common.head_space) {
-               gtk_text_view_set_left_margin(GTK_TEXT_VIEW(textview->text), 6);
-       } else {
-               gtk_text_view_set_left_margin(GTK_TEXT_VIEW(textview->text), 0);
-       }
 }
 
 void textview_set_text(TextView *textview, const gchar *text)
@@ -1590,19 +1610,15 @@ void textview_scroll_one_line(TextView *textview, gboolean up)
        if (!up) {
                upper = vadj->upper - vadj->page_size;
                if (vadj->value < upper) {
-                       vadj->value +=
-                               vadj->step_increment * 4;
-                       vadj->value =
-                               MIN(vadj->value, upper);
+                       vadj->value += vadj->step_increment;
+                       vadj->value = MIN(vadj->value, upper);
                        g_signal_emit_by_name(G_OBJECT(vadj),
                                              "value_changed", 0);
                }
        } else {
                if (vadj->value > 0.0) {
-                       vadj->value -=
-                               vadj->step_increment * 4;
-                       vadj->value =
-                               MAX(vadj->value, 0.0);
+                       vadj->value -= vadj->step_increment;
+                       vadj->value = MAX(vadj->value, 0.0);
                        g_signal_emit_by_name(G_OBJECT(vadj),
                                              "value_changed", 0);
                }
@@ -1686,8 +1702,7 @@ static void textview_smooth_scroll_one_line(TextView *textview, gboolean up)
                upper = vadj->upper - vadj->page_size;
                if (vadj->value < upper) {
                        old_value = vadj->value;
-                       last_value = vadj->value +
-                               vadj->step_increment * 4;
+                       last_value = vadj->value + vadj->step_increment;
                        last_value = MIN(last_value, upper);
 
                        textview_smooth_scroll_do(textview, old_value,
@@ -1697,8 +1712,7 @@ static void textview_smooth_scroll_one_line(TextView *textview, gboolean up)
        } else {
                if (vadj->value > 0.0) {
                        old_value = vadj->value;
-                       last_value = vadj->value -
-                               vadj->step_increment * 4;
+                       last_value = vadj->value - vadj->step_increment;
                        last_value = MAX(last_value, 0.0);
 
                        textview_smooth_scroll_do(textview, old_value,
@@ -1776,7 +1790,7 @@ static gint textview_key_pressed(GtkWidget *widget, GdkEventKey *event,
        case GDK_End:
        case GDK_Control_L:
        case GDK_Control_R:
-               break;
+               return FALSE;
        case GDK_space:
                if (summaryview)
                        summary_pass_key_press_event(summaryview, event);
@@ -1824,70 +1838,6 @@ static gint textview_key_pressed(GtkWidget *widget, GdkEventKey *event,
        return TRUE;
 }
 
-/*!
- *\brief    Check to see if a web URL has been disguised as a different
- *          URL (possible with HTML email).
- *
- *\param    uri The uri to check
- *
- *\param    textview The TextView the URL is contained in
- *
- *\return   gboolean TRUE if the URL is ok, or if the user chose to open
- *          it anyway, otherwise FALSE          
- */
-static gboolean uri_security_check(RemoteURI *uri, TextView *textview) 
-{
-       gchar *clicked_str;
-       gboolean retval = TRUE;
-
-       if (g_ascii_strncasecmp(uri->uri, "http:", 5) &&
-           g_ascii_strncasecmp(uri->uri, "https:", 6) &&
-           g_ascii_strncasecmp(uri->uri, "www.", 4)) 
-               return retval;
-
-       clicked_str = gtk_editable_get_chars(GTK_EDITABLE(textview->text),
-                                            uri->start,
-                                            uri->end);
-       if (clicked_str == NULL)
-               return TRUE;
-
-       if (strcmp(clicked_str, uri->uri) &&
-           (!g_ascii_strncasecmp(clicked_str, "http:",  5) ||
-            !g_ascii_strncasecmp(clicked_str, "https:", 6) ||
-            !g_ascii_strncasecmp(clicked_str, "www.",   4))) {
-               gchar *str;
-               retval = FALSE;
-
-               /* allow uri->uri    == http://somewhere.com
-                  and   clicked_str ==        somewhere.com */
-               str = g_strconcat("http://", clicked_str, NULL);
-
-               if (!g_ascii_strcasecmp(str, uri->uri))
-                       retval = TRUE;
-               g_free(str);
-       }
-
-       if (retval == FALSE) {
-               gchar *msg = NULL;
-               AlertValue resp;
-
-               msg = g_strdup_printf(_("The real URL (%s) is different from\n"
-                                       "the apparent URL (%s).  \n"
-                                       "Open it anyway?"),
-                                       uri->uri, clicked_str);
-               resp = alertpanel_with_type(_("Warning"), 
-                                 msg,
-                                 _("Yes"), 
-                                 _("No"),
-                                 NULL, NULL, ALERT_WARNING);
-               g_free(msg);
-               if (resp == G_ALERTDEFAULT)
-                       retval = TRUE;
-       } 
-       g_free(clicked_str);
-       return retval;
-}
-
 static gboolean textview_motion_notify(GtkWidget *widget,
                                       GdkEventMotion *event,
                                       TextView *textview)
@@ -1912,7 +1862,15 @@ static gboolean textview_visibility_notify(GtkWidget *widget,
                                           TextView *textview)
 {
        gint wx, wy;
-  
+       GdkWindow *window;
+
+       window = gtk_text_view_get_window(GTK_TEXT_VIEW(widget),
+                                         GTK_TEXT_WINDOW_TEXT);
+
+       /* check if occurred for the text window part */
+       if (window != event->window)
+               return FALSE;
+       
        gdk_window_get_pointer(widget->window, &wx, &wy, NULL);
        textview_uri_update(textview, wx, wy);
 
@@ -2102,19 +2060,12 @@ static gboolean textview_uri_button_pressed(GtkTextTag *tag, GObject *obj,
                bevent->button == 2 || bevent->button == 3) {
                if (!g_ascii_strncasecmp(uri->uri, "mailto:", 7)) {
                        if (bevent->button == 3) {
-                               gchar *fromname, *fromaddress;
-                                               
-                               /* extract url */
-                               fromaddress = g_strdup(uri->uri + 7);
-                               /* Hiroyuki: please put this function in utils.c! */
-                               fromname = procheader_get_fromname(fromaddress);
-                               extract_address(fromaddress);
-                               g_message("adding from textview %s <%s>", fromname, fromaddress);
-                               /* Add to address book - Match */
-                               addressbook_add_contact( fromname, fromaddress, NULL );
-                                               
-                               g_free(fromaddress);
-                               g_free(fromname);
+                               g_object_set_data(
+                                       G_OBJECT(textview->mail_popup_menu),
+                                       "menu_button", uri);
+                               gtk_menu_popup(GTK_MENU(textview->mail_popup_menu), 
+                                              NULL, NULL, NULL, NULL, 
+                                              bevent->button, bevent->time);
                        } else {
                                PrefsAccount *account = NULL;
 
@@ -2130,9 +2081,18 @@ static gboolean textview_uri_button_pressed(GtkTextTag *tag, GObject *obj,
                        }
                        return TRUE;
                } else {
-                       if (textview_uri_security_check(textview, uri) == TRUE) 
-                               open_uri(uri->uri,
-                                        prefs_common.uri_cmd);
+                       if (bevent->button == 1 &&
+                           textview_uri_security_check(textview, uri) == TRUE) 
+                                       open_uri(uri->uri,
+                                                prefs_common.uri_cmd);
+                       else if (bevent->button == 3) {
+                               g_object_set_data(
+                                       G_OBJECT(textview->link_popup_menu),
+                                       "menu_button", uri);
+                               gtk_menu_popup(GTK_MENU(textview->link_popup_menu), 
+                                              NULL, NULL, NULL, NULL, 
+                                              bevent->button, bevent->time);
+                       }
                        return TRUE;
                }
        }
@@ -2155,12 +2115,19 @@ static gboolean textview_uri_security_check(TextView *textview, RemoteURI *uri)
 {
        gchar *visible_str;
        gboolean retval = TRUE;
+       GtkTextBuffer *buffer;
+       GtkTextIter start, end;
 
        if (is_uri_string(uri->uri) == FALSE)
                return TRUE;
 
-       visible_str = gtk_editable_get_chars(GTK_EDITABLE(textview->text),
-                                            uri->start, uri->end);
+       buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview->text));
+
+       gtk_text_buffer_get_iter_at_offset(buffer, &start, uri->start);
+       gtk_text_buffer_get_iter_at_offset(buffer, &end,   uri->end);
+
+       visible_str = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
+
        if (visible_str == NULL)
                return TRUE;
 
@@ -2182,8 +2149,9 @@ static gboolean textview_uri_security_check(TextView *textview, RemoteURI *uri)
                                        "the apparent URL (%s).\n"
                                        "Open it anyway?"),
                                      uri->uri, visible_str);
-               aval = alertpanel_with_type(_("Warning"), msg, _("Yes"), _("No"), NULL,
-                                           NULL, ALERT_WARNING);
+               aval = alertpanel_with_type(_("Warning"), msg,
+                                           GTK_STOCK_YES, GTK_STOCK_NO,
+                                           NULL, NULL, ALERT_WARNING);
                g_free(msg);
                if (aval == G_ALERTDEFAULT)
                        retval = TRUE;
@@ -2207,3 +2175,71 @@ 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)
+{
+       RemoteURI *uri = g_object_get_data(G_OBJECT(textview->link_popup_menu),
+                                          "menu_button");
+       if (uri == NULL)
+               return;
+
+       if (textview_uri_security_check(textview, uri) == TRUE) 
+               open_uri(uri->uri,
+                        prefs_common.uri_cmd);
+       g_object_set_data(G_OBJECT(textview->link_popup_menu), "menu_button",
+                         NULL);
+}
+
+static void copy_uri_cb        (TextView *textview, guint action, void *data)
+{
+       RemoteURI *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_NONE), uri->uri, -1);
+       g_object_set_data(G_OBJECT(textview->link_popup_menu), "menu_button",
+                         NULL);
+}
+
+static void add_uri_to_addrbook_cb (TextView *textview, guint action, void *data)
+{
+       gchar *fromname, *fromaddress;
+       RemoteURI *uri = g_object_get_data(G_OBJECT(textview->mail_popup_menu),
+                                          "menu_button");
+       if (uri == NULL)
+               return;
+
+       /* extract url */
+       fromaddress = g_strdup(uri->uri + 7);
+       /* Hiroyuki: please put this function in utils.c! */
+       fromname = procheader_get_fromname(fromaddress);
+       extract_address(fromaddress);
+       g_message("adding from textview %s <%s>", fromname, fromaddress);
+       /* Add to address book - Match */
+       addressbook_add_contact( fromname, fromaddress, NULL );
+
+       g_free(fromaddress);
+       g_free(fromname);
+}
+
+static void mail_to_uri_cb (TextView *textview, guint action, void *data)
+{
+       PrefsAccount *account = NULL;
+       RemoteURI *uri = g_object_get_data(G_OBJECT(textview->mail_popup_menu),
+                                          "menu_button");
+       if (uri == NULL)
+               return;
+
+       if (textview->messageview && textview->messageview->msginfo &&
+           textview->messageview->msginfo->folder) {
+               FolderItem   *folder_item;
+
+               folder_item = textview->messageview->msginfo->folder;
+               if (folder_item->prefs && folder_item->prefs->enable_default_account)
+                       account = account_find_from_id(folder_item->prefs->default_account);
+       }
+       compose_new(account, uri->uri + 7, NULL);
+}
+
+