X-Git-Url: http://git.maemo.org/git/?p=modest;a=blobdiff_plain;f=src%2Fmodest-text-utils.c;h=51e340ebde976d00b48e2ffeff5790010296a226;hp=3c633851d08dffe10422afb076eb052e78c713a6;hb=92bef44ea70f8b4e16c78591bc12f58fac9a7c53;hpb=addd1287234fa35a521c56e6d6472de35739b3a2 diff --git a/src/modest-text-utils.c b/src/modest-text-utils.c index 3c63385..51e340e 100644 --- a/src/modest-text-utils.c +++ b/src/modest-text-utils.c @@ -28,8 +28,14 @@ */ + +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif /*_GNU_SOURCE*/ +#include /* for strcasestr */ + + #include -#include #include #include #include @@ -242,9 +248,9 @@ modest_text_utils_derived_subject (const gchar *subject, const gchar *prefix) gchar *tmp; g_return_val_if_fail (prefix, NULL); - - if (!subject) - return g_strdup (prefix); + + if (!subject || subject[0] == '\0') + subject = _("mail_va_no_subject"); tmp = g_strchug (g_strdup (subject)); @@ -1071,6 +1077,53 @@ modest_text_utils_get_display_date (time_t date) gboolean +modest_text_utils_validate_folder_name (const gchar *folder_name) +{ + /* based on http://msdn2.microsoft.com/en-us/library/aa365247.aspx, + * with some extras */ + + guint len; + const gchar **cursor; + const gchar *forbidden_chars[] = { + "<", ">", ":", "\"", "/", "\\", "|", "?", "*", "^", "%", "$", NULL + }; + const gchar *forbidden_names[] = { /* windows does not like these */ + "CON", "PRN", "AUX", "NUL", "COM1", "COM2", "COM3", "COM4", "COM5", "COM6", + "COM7", "COM8", "COM9", "LPT1", "LPT2", "LPT3", "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", "LPT9", + ".", "..", NULL + }; + + /* cannot be NULL */ + if (!folder_name) + return FALSE; + + /* cannot be empty */ + len = strlen(folder_name); + if (len == 0) + return FALSE; + + /* cannot start or end with a space */ + if (g_ascii_isspace(folder_name[0]) || g_ascii_isspace(folder_name[len - 1])) + return FALSE; + + /* cannot contain a forbidden char */ + for (cursor = forbidden_chars; cursor && *cursor; ++cursor) + if (strstr(folder_name, *cursor) != NULL) + return FALSE; + + /* cannot contain a forbidden word */ + if (len <= 4) { + for (cursor = forbidden_names; cursor && *cursor; ++cursor) { + if (g_ascii_strcasecmp (folder_name, *cursor) == 0) + return FALSE; + } + } + return TRUE; /* it's valid! */ +} + + + +gboolean modest_text_utils_validate_domain_name (const gchar *domain) { gboolean valid = FALSE; @@ -1104,7 +1157,14 @@ modest_text_utils_validate_email_address (const gchar *email_address, const gcha if (invalid_char_position != NULL) *invalid_char_position = NULL; - + + /* check that the email adress contains exactly one @ */ + if (!strstr(email_address, "@") || + (strstr(email_address, "@") != g_strrstr(email_address, "@"))) + { + return FALSE; + } + /* first we validate the name portion (name@domain) */ for (c = email_address; *c; c++) { if (*c == '\"' &&