X-Git-Url: http://git.maemo.org/git/?p=modest;a=blobdiff_plain;f=src%2Fmodest-text-utils.c;h=3c32ada5bbda1c8adc75cdf0c1d0d1755e9ace58;hp=213e83684d0fb8ad935c739da4449db42bbcf16d;hb=1ae76d480a98068ec23fb6fc6d231605302b809f;hpb=6d11595dfdc07450d9a48bff06a0544ca03a3d56
diff --git a/src/modest-text-utils.c b/src/modest-text-utils.c
index 213e836..3c32ada 100644
--- a/src/modest-text-utils.c
+++ b/src/modest-text-utils.c
@@ -300,6 +300,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 +313,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 +329,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;
@@ -1018,12 +1029,15 @@ modest_text_utils_get_display_date (time_t date)
return g_strdup(date_buf);
}
-gboolean
-modest_text_utils_validate_email_address (const gchar *email_address)
+gboolean
+modest_text_utils_validate_email_address (const gchar *email_address, const gchar **invalid_char_position)
{
int count = 0;
const gchar *c = NULL, *domain = NULL;
- static gchar *rfc822_specials = "()<>@,;:\\\"[]";
+ static gchar *rfc822_specials = "()<>@,;:\\\"[]&";
+
+ if (invalid_char_position != NULL)
+ *invalid_char_position = NULL;
/* first we validate the name portion (name@domain) */
for (c = email_address; *c; c++) {
@@ -1051,8 +1065,11 @@ modest_text_utils_validate_email_address (const gchar *email_address)
break;
if (*c <= ' ' || *c >= 127)
return FALSE;
- if (strchr(rfc822_specials, *c))
+ if (strchr(rfc822_specials, *c)) {
+ if (invalid_char_position)
+ *invalid_char_position = c;
return FALSE;
+ }
}
if (c == email_address || *(c - 1) == '.')
return FALSE;
@@ -1068,21 +1085,24 @@ modest_text_utils_validate_email_address (const gchar *email_address)
}
if (*c <= ' ' || *c >= 127)
return FALSE;
- if (strchr(rfc822_specials, *c))
+ if (strchr(rfc822_specials, *c)) {
+ if (invalid_char_position)
+ *invalid_char_position = c;
return FALSE;
+ }
} while (*++c);
return (count >= 1) ? TRUE : FALSE;
}
gboolean
-modest_text_utils_validate_recipient (const gchar *recipient)
+modest_text_utils_validate_recipient (const gchar *recipient, const gchar **invalid_char_position)
{
gchar *stripped, *current;
gchar *right_part;
gboolean has_error = FALSE;
- if (modest_text_utils_validate_email_address (recipient))
+ if (modest_text_utils_validate_email_address (recipient, invalid_char_position))
return TRUE;
stripped = g_strdup (recipient);
stripped = g_strstrip (stripped);
@@ -1139,7 +1159,7 @@ modest_text_utils_validate_recipient (const gchar *recipient)
address = g_strndup (right_part+1, strlen (right_part) - 2);
g_free (right_part);
- valid = modest_text_utils_validate_email_address (address);
+ valid = modest_text_utils_validate_email_address (address, invalid_char_position);
g_free (address);
return valid;
} else {