aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhiro <hiro@ee746299-78ed-0310-b773-934348b2243d>2007-05-18 02:26:45 +0000
committerhiro <hiro@ee746299-78ed-0310-b773-934348b2243d>2007-05-18 02:26:45 +0000
commitd86665625571fd744f58bdc8e228c3e3545287c0 (patch)
tree63e38313c8d050547510da62d78412ef0c2d3517
parent17f520fefb4f4c8c9715cf30f7e0062567132428 (diff)
URI encode mailto: to protect '+'.
git-svn-id: svn://sylpheed.sraoss.jp/sylpheed/trunk@1709 ee746299-78ed-0310-b773-934348b2243d
-rw-r--r--ChangeLog5
-rw-r--r--ChangeLog.ja6
-rw-r--r--libsylph/utils.c20
-rw-r--r--libsylph/utils.h1
-rw-r--r--src/textview.c32
5 files changed, 52 insertions, 12 deletions
diff --git a/ChangeLog b/ChangeLog
index 8bf7b1d6..a9371786 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2007-05-18
+
+ * libsylph/utils.[ch]: uriencode_for_mailto(): added.
+ * src/textview.c: URI encode mailto: to protect '+'.
+
2007-05-17
* src/main.c
diff --git a/ChangeLog.ja b/ChangeLog.ja
index 04cb2cc7..8ddd5f8d 100644
--- a/ChangeLog.ja
+++ b/ChangeLog.ja
@@ -1,3 +1,9 @@
+2007-05-18
+
+ * libsylph/utils.[ch]: uriencode_for_mailto(): 新規。
+ * src/textview.c: '+' を保護するために mailto: を URI エンコード
+ するようにした。
+
2007-05-17
* src/main.c
diff --git a/libsylph/utils.c b/libsylph/utils.c
index 56e7fccd..0379342b 100644
--- a/libsylph/utils.c
+++ b/libsylph/utils.c
@@ -1845,6 +1845,26 @@ gchar *uriencode_for_filename(const gchar *filename)
return enc;
}
+gchar *uriencode_for_mailto(const gchar *mailto)
+{
+ const gchar *p = mailto;
+ gchar *enc, *outp;
+
+ outp = enc = g_malloc(strlen(mailto) * 3 + 1);
+
+ for (p = mailto; *p != '\0'; p++) {
+ if (*p == '+') {
+ *outp++ = '%';
+ get_hex_str(outp, *p);
+ outp += 2;
+ } else
+ *outp++ = *p;
+ }
+
+ *outp = '\0';
+ return enc;
+}
+
gint scan_mailto_url(const gchar *mailto, gchar **to, gchar **cc, gchar **bcc,
gchar **subject, gchar **inreplyto, gchar **body)
{
diff --git a/libsylph/utils.h b/libsylph/utils.h
index d7f68b91..25978160 100644
--- a/libsylph/utils.h
+++ b/libsylph/utils.h
@@ -363,6 +363,7 @@ void decode_xdigit_encoded_str (gchar *decoded,
const gchar *encoded);
gchar *encode_uri (const gchar *filename);
gchar *uriencode_for_filename (const gchar *filename);
+gchar *uriencode_for_mailto (const gchar *mailto);
gint scan_mailto_url (const gchar *mailto,
gchar **to,
gchar **cc,
diff --git a/src/textview.c b/src/textview.c
index 5a8fa2e0..62559db5 100644
--- a/src/textview.c
+++ b/src/textview.c
@@ -1002,11 +1002,13 @@ static gchar *make_email_string(const gchar *bp, const gchar *ep)
{
/* returns a mailto: URI; mailto: is also used to detect the
* uri type later on in the button_pressed signal handler */
- gchar *tmp;
+ gchar *tmp, *enc;
gchar *result;
tmp = g_strndup(bp, ep - bp);
- result = g_strconcat("mailto:", tmp, NULL);
+ enc = uriencode_for_mailto(tmp);
+ result = g_strconcat("mailto:", enc, NULL);
+ g_free(enc);
g_free(tmp);
return result;
@@ -2056,26 +2058,29 @@ static void textview_popup_menu_activate_add_address_cb(GtkMenuItem *menuitem,
gpointer data)
{
RemoteURI *uri = (RemoteURI *)data;
- const gchar *addr;
+ gchar *addr;
g_return_if_fail(uri != NULL);
if (!uri->uri)
return;
- if (!g_ascii_strncasecmp(uri->uri, "mailto:", 7))
- addr = uri->uri + 7;
- else
- addr = uri->uri;
+ if (!g_ascii_strncasecmp(uri->uri, "mailto:", 7)) {
+ addr = g_malloc(strlen(uri->uri + 7) + 1);
+ decode_uri(addr, uri->uri + 7);
+ } else
+ addr = g_strdup(uri->uri);
addressbook_add_contact(addr, addr, NULL);
+
+ g_free(addr);
}
static void textview_popup_menu_activate_copy_cb(GtkMenuItem *menuitem,
gpointer data)
{
RemoteURI *uri = (RemoteURI *)data;
- const gchar *uri_string;
+ gchar *uri_string;
GtkClipboard *clipboard;
g_return_if_fail(uri != NULL);
@@ -2083,15 +2088,18 @@ static void textview_popup_menu_activate_copy_cb(GtkMenuItem *menuitem,
if (!uri->uri)
return;
- if (!g_ascii_strncasecmp(uri->uri, "mailto:", 7))
- uri_string = uri->uri + 7;
- else
- uri_string = uri->uri;
+ if (!g_ascii_strncasecmp(uri->uri, "mailto:", 7)) {
+ uri_string = g_malloc(strlen(uri->uri + 7) + 1);
+ decode_uri(uri_string, uri->uri + 7);
+ } else
+ uri_string = g_strdup(uri->uri);
clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
gtk_clipboard_set_text(clipboard, uri_string, -1);
clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);
gtk_clipboard_set_text(clipboard, uri_string, -1);
+
+ g_free(uri_string);
}
static void textview_popup_menu_activate_image_cb(GtkMenuItem *menuitem,