Patch: fix recipients parsing when a recipient list has quotes
- From: Jose Dapena Paz <jdapena igalia com>
- To: tinymail-devel-list <tinymail-devel-list gnome org>
- Subject: Patch: fix recipients parsing when a recipient list has quotes
- Date: Wed, 26 Sep 2007 11:17:28 +0200
Hi,
This patch fixes the capability to create addresses lists when the
string you part from has quotes.
For example, this string address should be valid:
"Dapena Paz, Jose" <jdapena igalia com>
But this string was converted to two addresses:
"Dapena Paz
Jose " <jdapena igalia com>
We also remove the quotes in name temporary buffer as they're added in
camel side again. If we don't remove them, the quotes are escaped.
--
Jose Dapena Paz <jdapena igalia com>
Igalia
Index: libtinymail-camel/tny-camel-common.c
===================================================================
--- libtinymail-camel/tny-camel-common.c (revisión: 2805)
+++ libtinymail-camel/tny-camel-common.c (copia de trabajo)
@@ -164,6 +164,59 @@
}
void
+_remove_quotes (gchar *buffer)
+{
+ gchar *tmp = buffer;
+ gboolean first_is_quote = FALSE;
+
+ /* First we remove the first quote */
+ first_is_quote = (buffer[0] == '\"');
+ while (*tmp != '\0') {
+ if ((tmp[1] == '\"') && (tmp[2] == '\0'))
+ tmp[1] = '\0';
+ if (first_is_quote)
+ tmp[0] = tmp[1];
+ tmp++;
+ }
+
+ if ((tmp > buffer) && (*(tmp-1) == '\"'))
+ *(tmp-1) = '\0';
+
+}
+
+gchar **
+_split_recipients (gchar *buffer)
+{
+ gchar *tmp, *start;
+ gboolean is_quoted = FALSE;
+ GPtrArray *array = g_ptr_array_new ();
+
+ start = tmp = buffer;
+
+ while (*tmp != '\0') {
+ if (*tmp == '\"')
+ is_quoted = !is_quoted;
+ if (*tmp == '\\')
+ tmp++;
+ if ((!is_quoted) && ((*tmp == ',') || (*tmp == ';'))) {
+ gchar *part;
+ part = g_strndup (start, tmp - start);
+ g_ptr_array_add (array, part);
+ start = tmp+1;
+ }
+
+ tmp++;
+ }
+
+ if (start != tmp)
+ g_ptr_array_add (array, g_strdup (start));
+
+ g_ptr_array_add (array, NULL);
+ return (gchar **) g_ptr_array_free (array, FALSE);
+}
+
+
+void
_string_to_camel_inet_addr (gchar *tok, CamelInternetAddress *target)
{
char *stfnd = NULL;
@@ -193,6 +246,7 @@
if (G_LIKELY (*lname == ' '))
*lname-- = '\0';
+ _remove_quotes (name);
camel_internet_address_add (target, name, email);
} else {
@@ -215,21 +269,23 @@
_foreach_email_add_to_inet_addr (const gchar *emails, CamelInternetAddress *target)
{
char *dup = g_strdup (emails);
- char *tok, *save;
+ gchar **parts, **current;
if (!emails)
return;
- tok = strtok_r (dup, ",;", &save);
+ parts = _split_recipients (dup);
+ current = parts;
- while (G_LIKELY (tok != NULL))
+ while (G_LIKELY (*current != NULL))
{
- _string_to_camel_inet_addr (tok, target);
+ _string_to_camel_inet_addr (*current, target);
- tok = strtok_r (NULL, ",;", &save);
+ current++;
}
+ g_strfreev (parts);
g_free (dup);
return;
Index: libtinymail-camel/tny-camel-common-priv.h
===================================================================
--- libtinymail-camel/tny-camel-common-priv.h (revisión: 2805)
+++ libtinymail-camel/tny-camel-common-priv.h (copia de trabajo)
@@ -30,6 +30,8 @@
#include <tny-camel-folder.h>
#include <tny-session-camel.h>
+void _remove_quotes (gchar *buffer);
+gchar **_split_recipients (gchar *buffer);
void _string_to_camel_inet_addr (gchar *tok, CamelInternetAddress *target);
void _foreach_email_add_to_inet_addr (const gchar *emails, CamelInternetAddress *target);
gboolean _tny_folder_store_query_passes (TnyFolderStoreQuery *query, CamelFolderInfo *finfo);
Index: ChangeLog
===================================================================
--- ChangeLog (revisión: 2805)
+++ ChangeLog (copia de trabajo)
@@ -1,3 +1,16 @@
+2007-09-26 Jose Dapena Paz <jdapena igalia com>
+
+ * libtinymail-camel/tny-camel-common.c,
+ libtinymail-camel/tny-camel-common-priv.h:
+ (_foreach_email_add_to_inet_addr): now we don't use
+ strtok_r() to split the string to addresses, as we
+ weren't taking into account the quotes. I implemented
+ a new _split_recipients() method that takes quotes
+ into account.
+ (_string_to_camel_inet_addr): now we remove the quotes
+ in the name part of an address, as they are added by
+ camel part automatically.
+
2007-09-25 Mark Doffman <mark doffman codethink co uk>
* /bindings/python/*: Remove the platform generation
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]