guint i;
gboolean space_seen = FALSE;
gsize len;
+ guint break_dist = 0; /* distance since last break point */
len = strlen (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;
case '&' : g_string_append (html, "&"); break;
case '"' : g_string_append (html, """); break;
case '\'' : g_string_append (html, "'"); break;
- case '\n' : g_string_append (html, "<br>\n"); break;
- case '\t' : g_string_append (html, " "); 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, " "); 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;
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++) {
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;
}
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);
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 {
else
return g_strndup (left_limit + 1, (right_limit - left_limit) - 1);
}
+
+gchar *
+modest_text_utils_get_color_string (GdkColor *color)
+{
+
+ return g_strdup_printf ("#%x%x%x%x%x%x%x%x%x%x%x%x",
+ (color->red >> 12) & 0xf, (color->red >> 8) & 0xf,
+ (color->red >> 4) & 0xf, (color->red) & 0xf,
+ (color->green >> 12) & 0xf, (color->green >> 8) & 0xf,
+ (color->green >> 4) & 0xf, (color->green) & 0xf,
+ (color->blue >> 12) & 0xf, (color->blue >> 8) & 0xf,
+ (color->blue >> 4) & 0xf, (color->blue) & 0xf);
+}