diff options
author | Jon Trowbridge <trow@ximian.com> | 2001-07-31 05:06:45 +0800 |
---|---|---|
committer | Jon Trowbridge <trow@src.gnome.org> | 2001-07-31 05:06:45 +0800 |
commit | 6f7ec6c07dfe9c01977cf685832871c45d7e2b17 (patch) | |
tree | 10840789813c6e20f270d54c5f6027feb213d418 /addressbook/backend/ebook | |
parent | ef6000b227427ac4f3e9180df3046a29f219dec8 (diff) | |
download | gsoc2013-evolution-6f7ec6c07dfe9c01977cf685832871c45d7e2b17.tar.gz gsoc2013-evolution-6f7ec6c07dfe9c01977cf685832871c45d7e2b17.tar.zst gsoc2013-evolution-6f7ec6c07dfe9c01977cf685832871c45d7e2b17.zip |
Properly handle the case where our "cleaned" completion is the empty
2001-07-30 Jon Trowbridge <trow@ximian.com>
* gui/component/select-names/e-select-names-completion.c
(e_select_names_completion_do_query): Properly handle the case
where our "cleaned" completion is the empty string. This happens,
for example, if the query text is the string "\"". (Bug #5610).
* backend/ebook/e-destination.c (e_destination_get_address_textv):
Reassure fejj that I'm not doing something stupid here.
(e_destination_get_address): Fix address quoting. This is a
stop-gap measure until I can change this code to use Camel's
superior address-handling routines. (Also Bug #5610)
svn path=/trunk/; revision=11487
Diffstat (limited to 'addressbook/backend/ebook')
-rw-r--r-- | addressbook/backend/ebook/e-destination.c | 100 |
1 files changed, 81 insertions, 19 deletions
diff --git a/addressbook/backend/ebook/e-destination.c b/addressbook/backend/ebook/e-destination.c index 9b4fbe681b..e5d41ab36d 100644 --- a/addressbook/backend/ebook/e-destination.c +++ b/addressbook/backend/ebook/e-destination.c @@ -40,7 +40,6 @@ #include <gnome-xml/parser.h> #include <gnome-xml/xmlmemory.h> - struct _EDestinationPrivate { gchar *card_uri; @@ -413,6 +412,7 @@ e_destination_get_name (const EDestination *dest) } +/* FIXME: not utf-8 safe */ const gchar * e_destination_get_email (const EDestination *dest) { @@ -454,6 +454,59 @@ e_destination_get_email (const EDestination *dest) return priv->email; } +#define NEEDS_QUOTING(c) ((c) == '.' || (c) == ',' || (c) == '<' || (c) == '>') + +/* FIXME: not utf-8 safe */ +static gboolean +needs_quotes (const gchar *str) +{ + gboolean in_quote = FALSE; + + while (*str) { + if (*str == '"') + in_quote = !in_quote; + else if (NEEDS_QUOTING (*str) && !in_quote) { + return TRUE; + } + ++str; + } + return FALSE; +} + +/* FIXME: not utf-8 safe */ +static gchar * +quote_string (const gchar *str) +{ + gchar *new_str, *t; + const gchar *s; + if (strchr (str, '\"') == NULL) { + + new_str = g_strdup_printf ("\"%s\"", str); + + } else { + + new_str = t = g_malloc (strlen (str)+3); + *t = '\"'; + ++t; + + s = str; + while (*s) { + if (*s != '"') { + *t = *s; + ++t; + } + ++s; + } + + *t = '\"'; + ++t; + *t = '\0'; + + } + + return new_str; +} + const gchar * e_destination_get_address (const EDestination *dest) { @@ -462,7 +515,7 @@ e_destination_get_address (const EDestination *dest) g_return_val_if_fail (dest && E_IS_DESTINATION (dest), NULL); priv = (struct _EDestinationPrivate *)dest->priv; /* cast out const */ - + if (priv->addr == NULL) { if (e_destination_is_evolution_list (dest)) { gchar **strv = g_new0 (gchar *, g_list_length (priv->list_dests) + 1); @@ -479,8 +532,6 @@ e_destination_get_address (const EDestination *dest) priv->addr = g_strjoinv (", ", strv); - g_message ("List address is [%s]", priv->addr); - g_free (strv); } else { const gchar *name = e_destination_get_name (dest); @@ -489,30 +540,37 @@ e_destination_get_address (const EDestination *dest) /* If this isn't set, we return NULL */ if (email) { if (name) { - /* uhm, yea... this'll work. NOT!!! */ - /* what about ','? or any of the other chars that require quoting?? */ const gchar *lt = strchr (name, '<'); - gchar *namecpy = lt ? g_strndup (name, lt-name) : g_strdup (name); - gboolean needs_quotes = (strchr (namecpy, '.') != NULL); + gchar *namestrip = lt ? g_strndup (name, lt-name) : g_strdup (name); + gchar *namecopy; - g_strstrip (namecpy); + g_strstrip (namestrip); + if (needs_quotes (namestrip)) { + namecopy = quote_string (namestrip); + } else { + namecopy = namestrip; + namestrip = NULL; + } + if (namestrip) + g_free (namestrip); - priv->addr = g_strdup_printf ("%s%s%s <%s>", - needs_quotes ? "\"" : "", - namecpy, - needs_quotes ? "\"" : "", - email); - g_free (namecpy); + priv->addr = g_strdup_printf ("%s <%s>", namecopy, email); + g_free (namecopy); + } else { priv->addr = g_strdup (email); } } else { /* Just use the name, which is the best we can do. */ - priv->addr = g_strdup (name); + if (needs_quotes (name)) { + priv->addr = quote_string (name); + } else { + priv->addr = g_strdup (name); + } } } } - + return priv->addr; } @@ -578,9 +636,13 @@ e_destination_get_address_textv (EDestination **destv) g_return_val_if_fail (destv, NULL); - /* FIXME: please tell me this is only for assertion + /* Q: Please tell me this is only for assertion reasons. If this is considered to be ok behavior then you - shouldn't use g_return's. Just a reminder ;-) */ + shouldn't use g_return's. Just a reminder ;-) + + A: Yes, this is just an assertion. (Though it does find the + length of the vector in the process...) + */ while (destv[len]) { g_return_val_if_fail (E_IS_DESTINATION (destv[len]), NULL); ++len; |