Better parsing support
authorSergio Villar Senin <svillar@igalia.com>
Fri, 11 Sep 2009 08:30:32 +0000 (10:30 +0200)
committerSergio Villar Senin <svillar@igalia.com>
Fri, 11 Sep 2009 08:30:32 +0000 (10:30 +0200)
Contacts added from addressbook are now properly quoted
This is fix 1/2 for NB#137187

src/hildon2/modest-address-book.c
src/modest-text-utils.c
src/widgets/modest-recpt-editor.c

index 20fdd2b..4e19d89 100644 (file)
@@ -340,10 +340,9 @@ ui_get_formatted_email_id(gchar * current_given_name,
        } else if ((current_sur_name != NULL) && (strlen(current_sur_name) != 0)) {
                g_string_append_printf(email_id_str, "%s", current_sur_name);
        }
-       if (g_utf8_strchr (email_id_str->str, -1, ' ')) {
-               g_string_prepend_c (email_id_str, '\"');
-               g_string_append_c (email_id_str, '\"');
-       }
+       g_string_prepend_c (email_id_str, '\"');
+       g_string_append_c (email_id_str, '\"');
+
        g_string_append_printf (email_id_str, " %c%s%c", '<', current_email_id, '>');
        return g_string_free (email_id_str, FALSE);
 }
index 99cb710..15405e8 100644 (file)
@@ -1699,6 +1699,7 @@ modest_text_utils_validate_recipient (const gchar *recipient, const gchar **inva
 
        /* quoted string */
        if (*current == '\"') {
+               gchar *last_quote = NULL;
                current = g_utf8_next_char (current);
                has_error = TRUE;
                for (; *current != '\0'; current = g_utf8_next_char (current)) {
@@ -1714,9 +1715,11 @@ modest_text_utils_validate_recipient (const gchar *recipient, const gchar **inva
                        } else if (*current == '\"') {
                                has_error = FALSE;
                                current = g_utf8_next_char (current);
-                               break;
+                               last_quote = current;
                        }
                }
+               if (last_quote)
+                       current = last_quote;
        } else {
                has_error = TRUE;
                for (current = stripped ; *current != '\0'; current = g_utf8_next_char (current)) {
@@ -1736,6 +1739,9 @@ modest_text_utils_validate_recipient (const gchar *recipient, const gchar **inva
        g_free (stripped);
        right_part = g_strstrip (right_part);
 
+       if (g_str_has_suffix (right_part, ",") || g_str_has_suffix (right_part, ";"))
+               right_part [(strlen (right_part) - 1)] = '\0';
+
        if (g_str_has_prefix (right_part, "<") &&
            g_str_has_suffix (right_part, ">")) {
                gchar *address;
index 0136388..14c8d11 100644 (file)
@@ -196,7 +196,7 @@ modest_recpt_editor_add_recipients (ModestRecptEditor *recpt_editor, const gchar
        g_signal_handlers_block_by_func (buffer, modest_recpt_editor_on_insert_text_after, recpt_editor);
 
        gtk_text_buffer_insert (buffer, &iter, string_to_add, -1);
-       
+
        g_signal_handlers_unblock_by_func (buffer, modest_recpt_editor_on_insert_text, recpt_editor);
        g_signal_handlers_unblock_by_func (buffer, modest_recpt_editor_on_insert_text_after, recpt_editor);
 
@@ -632,19 +632,32 @@ create_valid_text (const gchar *text, gint len)
                        next_c = g_utf8_get_char (g_utf8_next_char (current));
                else
                        next_c = 0;
-               if (c != 0x2022 && c != 0xfffc && 
+               if (c != 0x2022 && c != 0xfffc &&
                    c != g_utf8_get_char ("\n") &&
                    c != g_utf8_get_char ("\t"))
                        str = g_string_append_unichar (str, c);
                if (!quoted && ((c == g_utf8_get_char(",") || c == g_utf8_get_char (";")))) {
-                       if ((next_c != 0) && (next_c != g_utf8_get_char ("\n")))
-                               str = g_string_append_c (str, '\n');
+                       if ((next_c != 0) && (next_c != g_utf8_get_char ("\n"))) {
+                               gchar *last_separator = MAX (g_utf8_strrchr(str->str, -1, g_utf8_get_char (",")),
+                                                            g_utf8_strrchr(str->str, -1, g_utf8_get_char (";")));
+                               if (last_separator) {
+                                       gchar *last_at = g_utf8_strrchr (str->str, -1, g_utf8_get_char ("@"));
+                                       if (last_at) {
+                                               if (last_at > last_separator)
+                                                       str = g_string_append_c (str, '\n');
+                                       }
+                               } else {
+                                       if (g_utf8_strrchr (str->str, -1, g_utf8_get_char ("@")))
+                                               str = g_string_append_c (str, '\n');
+                               }
+                       }
                }
                if (c == g_utf8_get_char ("\""))
                        quoted = !quoted;
                current = g_utf8_next_char (current);
                i = current - text;
        }
+
        return g_string_free (str, FALSE);
 }