1 /* Copyright (c) 2006, Nokia Corporation
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * * Neither the name of the Nokia Corporation nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
18 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
21 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include <glib/gi18n.h>
36 #include <modest-tny-platform-factory.h>
37 #include <modest-text-utils.h>
38 #include <modest-runtime.h>
43 #endif /*HAVE_CONFIG_H */
46 #define FORWARD_STRING _("-----Forwarded Message-----")
47 #define FROM_STRING _("From:")
48 #define SENT_STRING _("Sent:")
49 #define TO_STRING _("To:")
50 #define SUBJECT_STRING _("Subject:")
51 #define EMPTY_STRING ""
54 * we need these regexps to find URLs in plain text e-mails
56 typedef struct _url_match_pattern_t url_match_pattern_t;
57 struct _url_match_pattern_t {
63 typedef struct _url_match_t url_match_t;
70 #define MAIL_VIEWER_URL_MATCH_PATTERNS { \
71 { "(file|rtsp|http|ftp|https)://[-A-Za-z0-9_$.+!*(),;:@%&=?/~#]+[-A-Za-z0-9_$%&=?/~#]",\
73 { "www\\.[-a-z0-9.]+[-a-z0-9](:[0-9]*)?(/[-A-Za-z0-9_$.+!*(),;:@%&=?/~#]*[^]}\\),?!;:\"]?)?",\
75 { "ftp\\.[-a-z0-9.]+[-a-z0-9](:[0-9]*)?(/[-A-Za-z0-9_$.+!*(),;:@%&=?/~#]*[^]}\\),?!;:\"]?)?",\
77 { "(voipto|callto|chatto|jabberto|xmpp):[-_a-z@0-9.\\+]+", \
79 { "mailto:[-_a-z0-9.\\+]+@[-_a-z0-9.]+", \
81 { "[-_a-z0-9.\\+]+@[-_a-z0-9.]+",\
86 static gchar* cite (const time_t sent_date, const gchar *from);
87 static void hyperlinkify_plain_text (GString *txt);
88 static gint cmp_offsets_reverse (const url_match_t *match1, const url_match_t *match2);
89 static void chk_partial_match (const url_match_t *match, guint* offset);
90 static GSList* get_url_matches (GString *txt);
92 static GString* get_next_line (const char *b, const gsize blen, const gchar * iter);
93 static int get_indent_level (const char *l);
94 static void unquote_line (GString * l);
95 static void append_quoted (GString * buf, const int indent, const GString * str,
97 static int get_breakpoint_utf8 (const gchar * s, const gint indent, const gint limit);
98 static int get_breakpoint_ascii (const gchar * s, const gint indent, const gint limit);
99 static int get_breakpoint (const gchar * s, const gint indent, const gint limit);
101 static gchar* modest_text_utils_quote_plain_text (const gchar *text,
105 static gchar* modest_text_utils_quote_html (const gchar *text,
110 /* ******************************************************************* */
111 /* ************************* PUBLIC FUNCTIONS ************************ */
112 /* ******************************************************************* */
115 modest_text_utils_quote (const gchar *text,
116 const gchar *content_type,
117 const gchar *signature,
119 const time_t sent_date,
122 gchar *retval, *cited;
124 g_return_val_if_fail (text, NULL);
125 g_return_val_if_fail (content_type, NULL);
127 cited = cite (sent_date, from);
129 if (content_type && strcmp (content_type, "text/html") == 0)
130 /* TODO: extract the <body> of the HTML and pass it to
132 retval = modest_text_utils_quote_html (text, cited, limit);
134 retval = modest_text_utils_quote_plain_text (text, cited, limit);
143 modest_text_utils_cite (const gchar *text,
144 const gchar *content_type,
145 const gchar *signature,
152 g_return_val_if_fail (text, NULL);
153 g_return_val_if_fail (content_type, NULL);
156 tmp_sig = g_strdup ("");
157 else if (!strcmp(content_type, "text/html")) {
158 tmp_sig = modest_text_utils_convert_to_html_body(signature);
160 tmp_sig = g_strdup (signature);
163 tmp = cite (sent_date, from);
164 retval = g_strdup_printf ("%s%s%s\n", tmp_sig, tmp, text);
172 modest_text_utils_inline (const gchar *text,
173 const gchar *content_type,
174 const gchar *signature,
178 const gchar *subject)
181 gchar *formatted_signature;
182 const gchar *plain_format = "%s%s\n%s %s\n%s %s\n%s %s\n%s %s\n\n%s";
183 const gchar *html_format = \
184 "%s%s<br>\n<table width=\"100%\" border=\"0\" cellspacing=\"2\" cellpadding=\"2\">\n" \
185 "<tr><td>%s</td><td>%s</td></tr>\n" \
186 "<tr><td>%s</td><td>%s</td></tr>\n" \
187 "<tr><td>%s</td><td>%s</td></tr>\n" \
188 "<tr><td>%s</td><td>%s</td></tr>\n" \
192 g_return_val_if_fail (text, NULL);
193 g_return_val_if_fail (content_type, NULL);
194 g_return_val_if_fail (text, NULL);
196 modest_text_utils_strftime (sent_str, 100, "%c", sent_date);
198 if (!strcmp (content_type, "text/html"))
199 /* TODO: extract the <body> of the HTML and pass it to
201 format = html_format;
203 format = plain_format;
205 if (signature != NULL) {
206 if (!strcmp (content_type, "text/html")) {
207 formatted_signature = g_strconcat (signature, "<br/>", NULL);
209 formatted_signature = g_strconcat (signature, "\n");
212 formatted_signature = "";
215 return g_strdup_printf (format, formatted_signature,
217 FROM_STRING, (from) ? from : EMPTY_STRING,
218 SENT_STRING, sent_str,
219 TO_STRING, (to) ? to : EMPTY_STRING,
220 SUBJECT_STRING, (subject) ? subject : EMPTY_STRING,
224 /* just to prevent warnings:
225 * warning: `%x' yields only last 2 digits of year in some locales
228 modest_text_utils_strftime(char *s, gsize max, const char *fmt, time_t timet)
232 /* does not work on old maemo glib:
233 * g_date_set_time_t (&date, timet);
235 localtime_r (&timet, &tm);
237 return strftime(s, max, fmt, &tm);
241 modest_text_utils_derived_subject (const gchar *subject, const gchar *prefix)
245 g_return_val_if_fail (prefix, NULL);
248 return g_strdup (prefix);
250 tmp = g_strchug (g_strdup (subject));
252 if (!strncmp (tmp, prefix, strlen (prefix))) {
256 return g_strdup_printf ("%s %s", prefix, subject);
261 modest_text_utils_remove_address (const gchar *address_list, const gchar *address)
263 gchar *dup, *token, *ptr, *result;
264 GString *filtered_emails;
266 g_return_val_if_fail (address_list, NULL);
269 return g_strdup (address_list);
271 /* search for substring */
272 if (!strstr ((const char *) address_list, (const char *) address))
273 return g_strdup (address_list);
275 dup = g_strdup (address_list);
276 filtered_emails = g_string_new (NULL);
278 token = strtok_r (dup, ",", &ptr);
280 while (token != NULL) {
281 /* Add to list if not found */
282 if (!strstr ((const char *) token, (const char *) address)) {
283 if (filtered_emails->len == 0)
284 g_string_append_printf (filtered_emails, "%s", g_strstrip (token));
286 g_string_append_printf (filtered_emails, ",%s", g_strstrip (token));
288 token = strtok_r (NULL, ",", &ptr);
290 result = filtered_emails->str;
294 g_string_free (filtered_emails, FALSE);
300 modest_text_utils_convert_buffer_to_html (GString *html, const gchar *data)
303 gboolean space_seen = FALSE;
308 /* replace with special html chars where needed*/
309 for (i = 0; i != len; ++i) {
312 if (space_seen && kar != ' ') {
313 g_string_append_c (html, ' ');
318 case 0: break; /* ignore embedded \0s */
319 case '<' : g_string_append (html, "<"); break;
320 case '>' : g_string_append (html, ">"); break;
321 case '&' : g_string_append (html, "&"); break;
322 case '"' : g_string_append (html, """); break;
323 case '\'' : g_string_append (html, "'"); break;
324 case '\n' : g_string_append (html, "<br>\n"); break;
325 case '\t' : g_string_append (html, " "); break; /* note the space at the end*/
327 if (space_seen) { /* second space in a row */
328 g_string_append (html, "  ");
334 g_string_append_c (html, kar);
340 modest_text_utils_convert_to_html (const gchar *data)
349 html = g_string_sized_new (1.5 * len); /* just a guess... */
351 g_string_append_printf (html,
353 "<meta http-equiv=\"content-type\" content=\"text/html; charset=utf8\">"
357 modest_text_utils_convert_buffer_to_html (html, data);
359 g_string_append (html, "</body></html>");
360 hyperlinkify_plain_text (html);
362 return g_string_free (html, FALSE);
366 modest_text_utils_convert_to_html_body (const gchar *data)
375 html = g_string_sized_new (1.5 * len); /* just a guess... */
377 modest_text_utils_convert_buffer_to_html (html, data);
379 hyperlinkify_plain_text (html);
381 return g_string_free (html, FALSE);
385 modest_text_utils_get_addresses_indexes (const gchar *addresses, GSList **start_indexes, GSList **end_indexes)
387 gchar *current, *start, *last_blank;
388 gint start_offset = 0, current_offset = 0;
390 g_return_if_fail (start_indexes != NULL);
391 g_return_if_fail (end_indexes != NULL);
393 start = (gchar *) addresses;
397 while (*current != '\0') {
398 if ((start == current)&&((*current == ' ')||(*current == ',')||(*current == ';'))) {
399 start = g_utf8_next_char (start);
401 last_blank = current;
402 } else if ((*current == ',')||(*current == ';')) {
403 gint *start_index, *end_index;
404 start_index = g_new0(gint, 1);
405 end_index = g_new0(gint, 1);
406 *start_index = start_offset;
407 *end_index = current_offset;
408 *start_indexes = g_slist_prepend (*start_indexes, start_index);
409 *end_indexes = g_slist_prepend (*end_indexes, end_index);
410 start = g_utf8_next_char (current);
411 start_offset = current_offset + 1;
413 } else if (*current == '"') {
414 current = g_utf8_next_char (current);
416 while ((*current != '"')&&(*current != '\0')) {
417 current = g_utf8_next_char (current);
422 current = g_utf8_next_char (current);
426 if (start != current) {
427 gint *start_index, *end_index;
428 start_index = g_new0(gint, 1);
429 end_index = g_new0(gint, 1);
430 *start_index = start_offset;
431 *end_index = current_offset;
432 *start_indexes = g_slist_prepend (*start_indexes, start_index);
433 *end_indexes = g_slist_prepend (*end_indexes, end_index);
436 *start_indexes = g_slist_reverse (*start_indexes);
437 *end_indexes = g_slist_reverse (*end_indexes);
443 modest_text_utils_split_addresses_list (const gchar *addresses)
445 gchar *current, *start, *last_blank;
446 GSList *result = NULL;
448 start = (gchar *) addresses;
452 while (*current != '\0') {
453 if ((start == current)&&((*current == ' ')||(*current == ',')||(*current == ';'))) {
454 start = g_utf8_next_char (start);
455 last_blank = current;
456 } else if ((*current == ',')||(*current == ';')) {
457 gchar *new_address = NULL;
458 new_address = g_strndup (start, current - last_blank);
459 result = g_slist_prepend (result, new_address);
460 start = g_utf8_next_char (current);
462 } else if (*current == '\"') {
463 if (current == start) {
464 current = g_utf8_next_char (current);
465 start = g_utf8_next_char (start);
467 while ((*current != '\"')&&(*current != '\0'))
468 current = g_utf8_next_char (current);
471 current = g_utf8_next_char (current);
474 if (start != current) {
475 gchar *new_address = NULL;
476 new_address = g_strndup (start, current - last_blank);
477 result = g_slist_prepend (result, new_address);
480 result = g_slist_reverse (result);
486 modest_text_utils_address_range_at_position (const gchar *recipients_list,
491 gchar *current = NULL;
492 gint range_start = 0;
495 gboolean is_quoted = FALSE;
498 for (current = (gchar *) recipients_list; *current != '\0'; current = g_utf8_find_next_char (current, NULL)) {
499 gunichar c = g_utf8_get_char (current);
501 if ((c == ',') && (!is_quoted)) {
502 if (index < position) {
503 range_start = index + 1;
507 } else if (c == '\"') {
508 is_quoted = !is_quoted;
509 } else if ((c == ' ') &&(range_start == index)) {
517 *start = range_start;
523 /* ******************************************************************* */
524 /* ************************* UTILIY FUNCTIONS ************************ */
525 /* ******************************************************************* */
528 get_next_line (const gchar * b, const gsize blen, const gchar * iter)
534 return g_string_new("");
542 gs = g_string_new_len (i0, iter - i0);
546 get_indent_level (const char *l)
563 /* if we hit the signature marker "-- ", we return -(indent + 1). This
564 * stops reformatting.
566 if (strcmp (l, "-- ") == 0) {
574 unquote_line (GString * l)
589 g_string_erase (l, 0, p - l->str);
593 append_quoted (GString * buf, int indent, const GString * str,
598 indent = indent < 0 ? abs (indent) - 1 : indent;
599 for (i = 0; i <= indent; i++) {
600 g_string_append (buf, "> ");
603 g_string_append_len (buf, str->str, cutpoint);
605 g_string_append (buf, str->str);
607 g_string_append (buf, "\n");
611 get_breakpoint_utf8 (const gchar * s, gint indent, const gint limit)
614 const gchar *pos, *last;
617 indent = indent < 0 ? abs (indent) - 1 : indent;
621 uni = g_utf8_to_ucs4_fast (s, -1, NULL);
623 if ((index + 2 * indent > limit) && last) {
627 if (g_unichar_isspace (uni[index])) {
630 pos = g_utf8_next_char (pos);
638 get_breakpoint_ascii (const gchar * s, const gint indent, const gint limit)
643 if (last + 2 * indent < limit)
646 for (i = strlen (s); i > 0; i--) {
648 if (i + 2 * indent <= limit) {
659 get_breakpoint (const gchar * s, const gint indent, const gint limit)
662 if (g_utf8_validate (s, -1, NULL)) {
663 return get_breakpoint_utf8 (s, indent, limit);
664 } else { /* assume ASCII */
665 //g_warning("invalid UTF-8 in msg");
666 return get_breakpoint_ascii (s, indent, limit);
671 cite (const time_t sent_date, const gchar *from)
675 /* format sent_date */
676 modest_text_utils_strftime (sent_str, 100, "%c", sent_date);
677 return g_strdup_printf (N_("On %s, %s wrote:\n"),
679 (from) ? from : EMPTY_STRING);
684 modest_text_utils_quote_plain_text (const gchar *text,
689 gint indent, breakpoint, rem_indent = 0;
690 GString *q, *l, *remaining;
693 /* remaining will store the rest of the line if we have to break it */
694 q = g_string_new (cite);
695 remaining = g_string_new ("");
700 l = get_next_line (text, len, iter);
701 iter = iter + l->len + 1;
702 indent = get_indent_level (l->str);
705 if (remaining->len) {
706 if (l->len && indent == rem_indent) {
707 g_string_prepend (l, " ");
708 g_string_prepend (l, remaining->str);
712 get_breakpoint (remaining->str,
715 append_quoted (q, rem_indent,
716 remaining, breakpoint);
717 g_string_erase (remaining, 0,
719 if (remaining->str[0] == ' ') {
720 g_string_erase (remaining, 0,
723 } while (remaining->len);
726 g_string_free (remaining, TRUE);
727 breakpoint = get_breakpoint (l->str, indent, limit);
728 remaining = g_string_new (l->str + breakpoint);
729 if (remaining->str[0] == ' ') {
730 g_string_erase (remaining, 0, 1);
733 append_quoted (q, indent, l, breakpoint);
734 g_string_free (l, TRUE);
735 } while ((iter < text + len) || (remaining->str[0]));
737 return g_string_free (q, FALSE);
741 modest_text_utils_quote_html (const gchar *text,
745 const gchar *format = \
746 "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n" \
750 "<blockquote type=\"cite\">\n%s\n</blockquote>\n" \
754 return g_strdup_printf (format, cite, text);
758 cmp_offsets_reverse (const url_match_t *match1, const url_match_t *match2)
760 return match2->offset - match1->offset;
766 * check if the match is inside an existing match... */
768 chk_partial_match (const url_match_t *match, guint* offset)
770 if (*offset >= match->offset && *offset < match->offset + match->len)
775 get_url_matches (GString *txt)
778 guint rv, i, offset = 0;
779 GSList *match_list = NULL;
781 static url_match_pattern_t patterns[] = MAIL_VIEWER_URL_MATCH_PATTERNS;
782 const size_t pattern_num = sizeof(patterns)/sizeof(url_match_pattern_t);
784 /* initalize the regexps */
785 for (i = 0; i != pattern_num; ++i) {
786 patterns[i].preg = g_slice_new0 (regex_t);
788 /* this should not happen */
789 g_return_val_if_fail (regcomp (patterns[i].preg, patterns[i].regex,
790 REG_ICASE|REG_EXTENDED|REG_NEWLINE) == 0, NULL);
792 /* find all the matches */
793 for (i = 0; i != pattern_num; ++i) {
797 if ((rv = regexec (patterns[i].preg, txt->str + offset, 1, &rm, 0)) != 0) {
798 g_return_val_if_fail (rv == REG_NOMATCH, NULL); /* this should not happen */
799 break; /* try next regexp */
804 /* FIXME: optimize this */
805 /* to avoid partial matches on something that was already found... */
806 /* check_partial_match will put -1 in the data ptr if that is the case */
807 test_offset = offset + rm.rm_so;
808 g_slist_foreach (match_list, (GFunc)chk_partial_match, &test_offset);
810 /* make a list of our matches (<offset, len, prefix> tupels)*/
811 if (test_offset != -1) {
812 url_match_t *match = g_slice_new (url_match_t);
813 match->offset = offset + rm.rm_so;
814 match->len = rm.rm_eo - rm.rm_so;
815 match->prefix = patterns[i].prefix;
816 match_list = g_slist_prepend (match_list, match);
822 for (i = 0; i != pattern_num; ++i) {
823 regfree (patterns[i].preg);
824 g_slice_free (regex_t, patterns[i].preg);
825 } /* don't free patterns itself -- it's static */
827 /* now sort the list, so the matches are in reverse order of occurence.
828 * that way, we can do the replacements starting from the end, so we don't need
829 * to recalculate the offsets
831 match_list = g_slist_sort (match_list,
832 (GCompareFunc)cmp_offsets_reverse);
839 hyperlinkify_plain_text (GString *txt)
842 GSList *match_list = get_url_matches (txt);
844 /* we will work backwards, so the offsets stay valid */
845 for (cursor = match_list; cursor; cursor = cursor->next) {
847 url_match_t *match = (url_match_t*) cursor->data;
848 gchar *url = g_strndup (txt->str + match->offset, match->len);
849 gchar *repl = NULL; /* replacement */
851 /* the prefix is NULL: use the one that is already there */
852 repl = g_strdup_printf ("<a href=\"%s%s\">%s</a>",
853 match->prefix ? match->prefix : EMPTY_STRING,
856 /* replace the old thing with our hyperlink
857 * replacement thing */
858 g_string_erase (txt, match->offset, match->len);
859 g_string_insert (txt, match->offset, repl);
864 g_slice_free (url_match_t, match);
867 g_slist_free (match_list);
873 modest_text_utils_get_display_address (gchar *address)
880 g_return_val_if_fail (g_utf8_validate (address, -1, NULL), NULL);
882 g_strchug (address); /* remove leading whitespace */
884 /* <email@address> from display name */
885 cursor = g_strstr_len (address, strlen(address), "<");
886 if (cursor == address) /* there's nothing else? leave it */
891 /* remove (bla bla) from display name */
892 cursor = g_strstr_len (address, strlen(address), "(");
893 if (cursor == address) /* there's nothing else? leave it */
898 g_strchomp (address); /* remove trailing whitespace */
906 modest_text_utils_get_subject_prefix_len (const gchar *sub)
909 static const gchar* prefix[] = {
910 "Re:", "RE:", "Fwd:", "FWD:", "FW:", NULL
913 if (!sub || (sub[0] != 'R' && sub[0] != 'F')) /* optimization */
919 if (g_str_has_prefix(sub, prefix[i])) {
920 int prefix_len = strlen(prefix[i]);
921 if (sub[prefix_len] == ' ')
922 ++prefix_len; /* ignore space after prefix as well */
932 modest_text_utils_utf8_strcmp (const gchar* s1, const gchar *s2, gboolean insensitive)
937 /* work even when s1 and/or s2 == NULL */
938 if (G_UNLIKELY(s1 == s2))
941 /* if it's not case sensitive */
943 return strcmp (s1 ? s1 : "", s2 ? s2 : "");
945 n1 = g_utf8_collate_key (s1 ? s1 : "", -1);
946 n2 = g_utf8_collate_key (s2 ? s2 : "", -1);
948 result = strcmp (n1, n2);
958 modest_text_utils_get_display_date (time_t date)
961 const guint BUF_SIZE = 64;
962 gchar date_buf[BUF_SIZE];
963 gchar now_buf [BUF_SIZE];
967 modest_text_utils_strftime (date_buf, BUF_SIZE, "%d/%m/%Y", date);
968 modest_text_utils_strftime (now_buf, BUF_SIZE, "%d/%m/%Y", now); /* today */
969 /* modest_text_utils_strftime (date_buf, BUF_SIZE, "%x", date); */
970 /* modest_text_utils_strftime (now_buf, BUF_SIZE, "%x", now); /\* today *\/ */
972 /* if this is today, get the time instead of the date */
973 if (strcmp (date_buf, now_buf) == 0)
974 modest_text_utils_strftime (date_buf, BUF_SIZE, "%H:%M %P", date);
976 return g_strdup(date_buf);
980 modest_text_utils_validate_email_address (const gchar *email_address)
983 const gchar *c = NULL, *domain = NULL;
984 static gchar *rfc822_specials = "()<>@,;:\\\"[]";
986 /* first we validate the name portion (name@domain) */
987 for (c = email_address; *c; c++) {
989 (c == email_address ||
995 if (*c == '\\' && (*++c == ' '))
997 if (*c <= ' ' || *c >= 127)
1010 if (*c <= ' ' || *c >= 127)
1012 if (strchr(rfc822_specials, *c))
1015 if (c == email_address || *(c - 1) == '.')
1018 /* next we validate the domain portion (name@domain) */
1019 if (!*(domain = ++c))
1023 if (c == domain || *(c - 1) == '.')
1027 if (*c <= ' ' || *c >= 127)
1029 if (strchr(rfc822_specials, *c))
1033 return (count >= 1) ? TRUE : FALSE;
1037 modest_text_utils_validate_recipient (const gchar *recipient)
1039 gchar *stripped, *current;
1041 gboolean has_error = FALSE;
1043 if (modest_text_utils_validate_email_address (recipient))
1045 stripped = g_strdup (recipient);
1046 stripped = g_strstrip (stripped);
1049 if (*current == '\0') {
1055 if (*current == '\"') {
1056 current = g_utf8_next_char (current);
1058 for (; *current != '\0'; current = g_utf8_next_char (current)) {
1059 if (*current == '\\') {
1060 /* TODO: This causes a warning, which breaks the build,
1061 * because a gchar cannot be < 0.
1063 if (current[1] <0) {
1068 } else if (*current == '\"') {
1070 current = g_utf8_next_char (current);
1076 for (current = stripped ; *current != '\0'; current = g_utf8_next_char (current)) {
1077 if (*current == '<') {
1089 right_part = g_strdup (current);
1091 right_part = g_strstrip (right_part);
1093 if (g_str_has_prefix (right_part, "<") &&
1094 g_str_has_suffix (right_part, ">")) {
1098 address = g_strndup (right_part+1, strlen (right_part) - 2);
1099 g_free (right_part);
1100 valid = modest_text_utils_validate_email_address (address);
1104 g_free (right_part);
1111 modest_text_utils_get_display_size (guint64 size)
1113 const guint KB=1024;
1114 const guint MB=1024 * KB;
1115 const guint GB=1024 * MB;
1118 return g_strdup_printf(_FM("sfil_li_size_kb"), 0);
1119 if (0 < size && size < KB)
1120 return g_strdup_printf (_FM("sfil_li_size_kb"), 1);
1121 else if (KB <= size && size < 100 * KB)
1122 return g_strdup_printf (_FM("sfil_li_size_1kb_99kb"), size / KB);
1123 else if (100*KB <= size && size < MB)
1124 return g_strdup_printf (_FM("sfil_li_size_100kb_1mb"), size / MB);
1125 else if (MB <= size && size < 10*MB)
1126 return g_strdup_printf (_FM("sfil_li_size_1mb_10mb"), size / MB);
1127 else if (10*MB <= size && size < GB)
1128 return g_strdup_printf (_FM("sfil_li_size_10mb_1gb"), size / MB);
1130 return g_strdup_printf (_FM("sfil_li_size_1gb_or_greater"), size / GB);