X-Git-Url: http://git.maemo.org/git/?p=modest;a=blobdiff_plain;f=src%2Fmodest-text-utils.c;h=3c633851d08dffe10422afb076eb052e78c713a6;hp=52d9ecf2221429a6f8a4a62bf8aafb56aa0f3d43;hb=addd1287234fa35a521c56e6d6472de35739b3a2;hpb=53dc7de1843cd26cd027d1f8653165f769c7e2ed
diff --git a/src/modest-text-utils.c b/src/modest-text-utils.c
index 52d9ecf..3c63385 100644
--- a/src/modest-text-utils.c
+++ b/src/modest-text-utils.c
@@ -51,6 +51,14 @@
#define EMPTY_STRING ""
/*
+ * do the hyperlinkification only for texts < 50 Kb,
+ * as it's quite slow. Without this, e.g. mail with
+ * an uuencoded part (which is not recognized as attachment,
+ * will hang modest
+ */
+#define HYPERLINKIFY_MAX_LENGTH (1024*50)
+
+/*
* we need these regexps to find URLs in plain text e-mails
*/
typedef struct _url_match_pattern_t url_match_pattern_t;
@@ -71,7 +79,7 @@ struct _url_match_t {
{ "(file|rtsp|http|ftp|https)://[-A-Za-z0-9_$.+!*(),;:@%&=?/~#]+[-A-Za-z0-9_$%&=?/~#]",\
NULL, NULL },\
{ "www\\.[-a-z0-9.]+[-a-z0-9](:[0-9]*)?(/[-A-Za-z0-9_$.+!*(),;:@%&=?/~#]*[^]}\\),?!;:\"]?)?",\
- NULL, "http://" },\
+ NULL, "http://" }, \
{ "ftp\\.[-a-z0-9.]+[-a-z0-9](:[0-9]*)?(/[-A-Za-z0-9_$.+!*(),;:@%&=?/~#]*[^]}\\),?!;:\"]?)?",\
NULL, "ftp://" },\
{ "(voipto|callto|chatto|jabberto|xmpp):[-_a-z@0-9.\\+]+", \
@@ -86,7 +94,6 @@ struct _url_match_t {
static gchar* cite (const time_t sent_date, const gchar *from);
static void hyperlinkify_plain_text (GString *txt);
static gint cmp_offsets_reverse (const url_match_t *match1, const url_match_t *match2);
-static void chk_partial_match (const url_match_t *match, guint* offset);
static GSList* get_url_matches (GString *txt);
static GString* get_next_line (const char *b, const gsize blen, const gchar * iter);
@@ -300,6 +307,7 @@ modest_text_utils_convert_buffer_to_html (GString *html, const gchar *data)
guint i;
gboolean space_seen = FALSE;
gsize len;
+ guint break_dist = 0; /* distance since last break point */
len = strlen (data);
@@ -312,6 +320,15 @@ modest_text_utils_convert_buffer_to_html (GString *html, const gchar *data)
space_seen = FALSE;
}
+ /* we artificially insert a breakpoint (newline)
+ * after 256, to make sure our lines are not so long
+ * they will DOS the regexping later
+ */
+ if (++break_dist == 256) {
+ g_string_append_c (html, '\n');
+ break_dist = 0;
+ }
+
switch (kar) {
case 0: break; /* ignore embedded \0s */
case '<' : g_string_append (html, "<"); break;
@@ -319,9 +336,10 @@ modest_text_utils_convert_buffer_to_html (GString *html, const gchar *data)
case '&' : g_string_append (html, "&"); break;
case '"' : g_string_append (html, """); break;
case '\'' : g_string_append (html, "'"); break;
- case '\n' : g_string_append (html, "
\n"); break;
- case '\t' : g_string_append (html, " "); break; /* note the space at the end*/
+ case '\n' : g_string_append (html, "
\n"); break_dist= 0; break;
+ case '\t' : g_string_append (html, " "); break_dist=0; break; /* note the space at the end*/
case ' ':
+ break_dist = 0;
if (space_seen) { /* second space in a row */
g_string_append (html, " ");
space_seen = FALSE;
@@ -355,7 +373,9 @@ modest_text_utils_convert_to_html (const gchar *data)
modest_text_utils_convert_buffer_to_html (html, data);
g_string_append (html, "