aboutsummaryrefslogtreecommitdiffstats
path: root/e-util/e-html-utils.c
diff options
context:
space:
mode:
authorJon Trowbridge <trow@ximian.com>2001-03-31 02:05:48 +0800
committerJon Trowbridge <trow@src.gnome.org>2001-03-31 02:05:48 +0800
commit2067796514a4273959cc478a252932f6db1b2d2d (patch)
tree3fecced618ee8e85f6f742145f46d2b5eb46ab7c /e-util/e-html-utils.c
parentc2f952971ba1362587fa6b9ed5e4b916e14d13ab (diff)
downloadgsoc2013-evolution-2067796514a4273959cc478a252932f6db1b2d2d.tar.gz
gsoc2013-evolution-2067796514a4273959cc478a252932f6db1b2d2d.tar.zst
gsoc2013-evolution-2067796514a4273959cc478a252932f6db1b2d2d.zip
Add support for converting e-mail addresses to links. (is_email_address):
2001-03-30 Jon Trowbridge <trow@ximian.com> * e-html-utils.c (e_text_to_html_full): Add support for converting e-mail addresses to links. (is_email_address): Added. Identifies e-mail addresses. (email_address_extract): Added. Extracts a copy of the e-mail address from the text. * e-html-utils.h (E_TEXT_TO_HTML_CONVERT_ADDRESSES): Added. * e-url.c (e_url_shroud): Added. Copy a url, replacing any plaintext passwords with a single *. (e_url_equal): Compare two urls, taking into account that they may or may not be shrouded. 2001-03-30 Jon Trowbridge <trow@ximian.com> * camel-mime-message.c (camel_mime_message_set_source): Shrould our source URL before putting it into X-Evolution-Source. 2001-03-30 Jon Trowbridge <trow@ximian.com> * mail-display.c (mail_text_write): Add (commented-out) E_TEXT_TO_HTML_CONVERT_ADDRESSES. * mail-config.c (mail_config_get_account_by_source_url): Call e_url_equal to compare URLs. svn path=/trunk/; revision=9050
Diffstat (limited to 'e-util/e-html-utils.c')
-rw-r--r--e-util/e-html-utils.c81
1 files changed, 81 insertions, 0 deletions
diff --git a/e-util/e-html-utils.c b/e-util/e-html-utils.c
index 5afb0a6319..0a1938f0fa 100644
--- a/e-util/e-html-utils.c
+++ b/e-util/e-html-utils.c
@@ -65,6 +65,54 @@ url_extract (const unsigned char **text, gboolean check)
return out;
}
+/* FIXME */
+static gboolean
+is_email_address (const unsigned char *c)
+{
+ gboolean seen_at = FALSE, seen_postat = FALSE;
+
+ if (*c == '<')
+ ++c;
+
+ while (*c && (isalnum ((gint) *c)
+ || *c == '-'
+ || *c == '_'
+ || *c == (seen_at ? '.' : '@'))) {
+
+ if (seen_at && !seen_postat) {
+ if (*c == '.')
+ return FALSE;
+ seen_postat = TRUE;
+ }
+
+ if (*c == '@')
+ seen_at = TRUE;
+
+ ++c;
+ }
+
+ return seen_at && seen_postat && (isspace ((gint) *c) || *c == '>' || !*c);
+}
+
+static gchar *
+email_address_extract (const unsigned char **text)
+{
+ const unsigned char *end = *text;
+ char *out;
+
+ while (*end && !isspace (*end) && (*end != '>') && (*end < 0x80))
+ ++end;
+
+ out = g_strndup (*text, end - *text);
+ if (!is_email_address (out)) {
+ g_free (out);
+ return NULL;
+ }
+
+ *text = end;
+ return out;
+}
+
static gboolean
is_citation (const unsigned char *c)
{
@@ -115,6 +163,9 @@ is_citation (const unsigned char *c)
* - E_TEXT_TO_HTML_CONVERT_URLS: wrap <a href="..."> </a> around
* strings that look like URLs.
*
+ * - E_TEXT_TO_HTML_CONVERT_ADDRESSES: wrap <a href="mailto:..."> </a> around
+ * strings that look like mail addresses.
+ *
* - E_TEXT_TO_HTML_MARK_CITATION: wrap <font color="blue"> </font> around
* citations (lines beginning with "> ").
**/
@@ -202,6 +253,36 @@ e_text_to_html_full (const char *input, unsigned int flags, guint32 color)
break;
unicode_get_utf8 (cur, &u);
}
+
+ if (unicode_isalpha (u)
+ && (flags & E_TEXT_TO_HTML_CONVERT_ADDRESSES)
+ && is_email_address (cur)) {
+ gchar *addr = NULL, *dispaddr = NULL;
+
+ addr = email_address_extract (&cur);
+ dispaddr = e_text_to_html (addr, 0);
+
+ if (addr) {
+ gchar *outaddr = g_strdup_printf ("<a href=\"mailto:%s\">"
+ "<!--+GtkHTML:<DATA class=\"Text\" key=\"email\" value=\"%s\">-->"
+ "%s"
+ "<!--+GtkHTML:<DATA class=\"Text\" clear=\"email\">--> "
+ "</a>",
+ addr, addr, dispaddr);
+ out = check_size (&buffer, &buffer_size, out, strlen(outaddr));
+ out += sprintf (out, "%s", outaddr);
+ col += strlen (addr);
+ g_free (addr);
+ g_free (dispaddr);
+ g_free (outaddr);
+ }
+
+ if (!*cur)
+ break;
+ unicode_get_utf8 (cur, &u);
+
+ }
+
if (u == (unicode_char_t)-1) {
/* Sigh. Someone sent undeclared 8-bit data.
* Assume it's iso-8859-1.