*/
#define HYPERLINKIFY_MAX_LENGTH (1024*50)
+
+/*
+ * we mark the ampersand with \007 when converting text->html
+ * because after text->html we do hyperlink detecting, which
+ * could be screwed up by the ampersand
+ */
+#define MARK_AMP '\007'
+#define MARK_AMP_STR "\007"
+
+
/*
* we need these regexps to find URLs in plain text e-mails
*/
return result;
}
+
+gchar*
+modest_text_utils_remove_duplicate_addresses (const gchar *address_list)
+{
+ GSList *addresses, *cursor;
+ GHashTable *table;
+ gchar *new_list;
+
+ g_return_val_if_fail (address_list, NULL);
+
+ table = g_hash_table_new (g_str_hash, g_str_equal);
+ addresses = modest_text_utils_split_addresses_list (address_list);
+
+ new_list = g_strdup("");
+ cursor = addresses;
+ while (cursor) {
+ const gchar* address = (const gchar*)cursor->data;
+
+ /* ignore the address if already seen */
+ if (g_hash_table_lookup (table, address) == 0) {
+
+ gchar *tmp = g_strjoin (",", new_list, address, NULL);
+ g_free (new_list);
+ new_list = tmp;
+
+ g_hash_table_insert (table, (gchar*)address, GINT_TO_POINTER(1));
+ }
+ cursor = g_slist_next (cursor);
+ }
+
+ g_hash_table_destroy (table);
+ g_slist_foreach (addresses, (GFunc)g_free, NULL);
+ g_slist_free (addresses);
+
+ return new_list;
+}
+
+
static void
-modest_text_utils_convert_buffer_to_html (GString *html, const gchar *data, gssize n)
+modest_text_utils_convert_buffer_to_html_start (GString *html, const gchar *data, gssize n)
{
- guint i;
+ guint i;
gboolean space_seen = FALSE;
guint break_dist = 0; /* distance since last break point */
}
switch (kar) {
- case 0: break; /* ignore embedded \0s */
- case '<' : g_string_append (html, "<"); break;
- case '>' : g_string_append (html, ">"); break;
- case '&' : g_string_append (html, "&"); break;
- case '"' : g_string_append (html, """); break;
+ case 0:
+ case MARK_AMP: /* this is a temp place holder for '&'; we can only
+ * set the real '&' after hyperlink translation, otherwise
+ * we might screw that up */
+ break; /* ignore embedded \0s and MARK_AMP */
+ case '<' : g_string_append (html, MARK_AMP_STR "lt;"); break;
+ case '>' : g_string_append (html, MARK_AMP_STR "gt;"); break;
+ case '&' : g_string_append (html, MARK_AMP_STR "amp;"); break;
+ case '"' : g_string_append (html, MARK_AMP_STR "quot;"); break;
/* don't convert ' --> wpeditor will try to re-convert it... */
//case '\'' : g_string_append (html, "'"); break;
- case '\n' : g_string_append (html, "<br>\n"); break_dist= 0; break;
- case '\t' : g_string_append (html, " "); break_dist=0; break; /* note the space at the end*/
+ case '\n' : g_string_append (html, "<br>\n");break_dist= 0; break;
+ case '\t' : g_string_append (html, MARK_AMP_STR "nbsp;" MARK_AMP_STR "nbsp;" MARK_AMP_STR "nbsp; ");
+ break_dist=0; break; /* note the space at the end*/
case ' ':
break_dist = 0;
if (space_seen) { /* second space in a row */
}
}
+
+static void
+modest_text_utils_convert_buffer_to_html_finish (GString *html)
+{
+ int i;
+ /* replace all our MARK_AMPs with real ones */
+ for (i = 0; i != html->len; ++i)
+ if ((html->str)[i] == MARK_AMP)
+ (html->str)[i] = '&';
+}
+
+
gchar*
modest_text_utils_convert_to_html (const gchar *data)
{
"</head>"
"<body>");
- modest_text_utils_convert_buffer_to_html (html, data, -1);
+ modest_text_utils_convert_buffer_to_html_start (html, data, -1);
g_string_append (html, "</body></html>");
if (len <= HYPERLINKIFY_MAX_LENGTH)
hyperlinkify_plain_text (html);
+
+ modest_text_utils_convert_buffer_to_html_finish (html);
return g_string_free (html, FALSE);
}
n = strlen (data);
html = g_string_sized_new (1.5 * n); /* just a guess... */
- modest_text_utils_convert_buffer_to_html (html, data, n);
+ modest_text_utils_convert_buffer_to_html_start (html, data, n);
if (hyperlinkify && (n < HYPERLINKIFY_MAX_LENGTH))
hyperlinkify_plain_text (html);
+ modest_text_utils_convert_buffer_to_html_finish (html);
+
return g_string_free (html, FALSE);
}
return;
}
+#if 0
GSList *
modest_text_utils_split_addresses_list (const gchar *addresses)
{
return result;
}
+#endif
+
+
+
+
+GSList *
+modest_text_utils_split_addresses_list (const gchar *addresses)
+{
+ GSList *head;
+ const gchar *my_addrs = addresses;
+ const gchar *end;
+ gchar *addr;
+
+ /* skip any space, ',', ';' at the start */
+ while (my_addrs && (my_addrs[0] == ' ' || my_addrs[0] == ',' || my_addrs[0] == ';'))
+ ++my_addrs;
+
+ /* are we at the end of addresses list? */
+ if (!my_addrs[0])
+ return NULL;
+
+ /* nope, we are at the start of some address
+ * now, let's find the end of the address */
+ end = my_addrs + 1;
+ while (end[0] && end[0] != ',' && end[0] != ';')
+ ++end;
+
+ /* we got the address; copy it and remove trailing whitespace */
+ addr = g_strndup (my_addrs, end - my_addrs);
+ g_strchomp (addr);
+
+ head = g_slist_append (NULL, addr);
+ head->next = modest_text_utils_split_addresses_list (end); /* recurse */
+
+ return head;
+}
+
void
modest_text_utils_address_range_at_position (const gchar *recipients_list,
match->len = rm.rm_eo - rm.rm_so;
match->prefix = patterns[i].prefix;
match_list = g_slist_prepend (match_list, match);
- }
-
+ }
offset += rm.rm_eo;
}
}