From 3efafe586b428af5061eb619abcfb5cb79c3dff0 Mon Sep 17 00:00:00 2001 From: Jeffrey Stedfast Date: Mon, 25 Sep 2000 21:49:55 +0000 Subject: Updated to use Nat's ENameWestern parser. 2000-09-25 Jeffrey Stedfast * message-list.c (address_compare): Updated to use Nat's ENameWestern parser. * Makefile.am: link against e-util/ename/libename.la svn path=/trunk/; revision=5583 --- mail/ChangeLog | 7 +++++++ mail/Makefile.am | 1 + mail/message-list.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++------ 3 files changed, 54 insertions(+), 6 deletions(-) diff --git a/mail/ChangeLog b/mail/ChangeLog index 200f4df407..e3e3ccdb46 100644 --- a/mail/ChangeLog +++ b/mail/ChangeLog @@ -1,3 +1,10 @@ +2000-09-25 Jeffrey Stedfast + + * message-list.c (address_compare): Updated to use Nat's + ENameWestern parser. + + * Makefile.am: link against e-util/ename/libename.la + 2000-09-25 Dan Winship * mail-ops.c: CamelException is not for compile-time errors. diff --git a/mail/Makefile.am b/mail/Makefile.am index 3e198c1d9e..83ae9cf4be 100644 --- a/mail/Makefile.am +++ b/mail/Makefile.am @@ -87,6 +87,7 @@ evolution_mail_LDADD = \ $(CAMEL_OBJS_EXTRA) \ $(top_builddir)/camel/libcamel.la \ $(top_builddir)/e-util/libeutil.la \ + $(top_builddir)/e-util/ename/libename.la \ $(top_builddir)/libibex/libibex.la \ $(top_builddir)/filter/libfilter.la \ $(BONOBO_VFS_GNOME_LIBS) \ diff --git a/mail/message-list.c b/mail/message-list.c index 4fc773e77e..82915ea528 100644 --- a/mail/message-list.c +++ b/mail/message-list.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -131,9 +132,9 @@ internet_address_new_from_string (const gchar *string) g_return_val_if_fail (string != NULL, NULL); g_return_val_if_fail (*string != '\0', NULL); - + padding = NULL; - + ptr = string; while (isspace (*ptr)) ptr++; @@ -233,11 +234,14 @@ static gint address_compare (gconstpointer address1, gconstpointer address2) { InternetAddress *ia1, *ia2; - gint retval; + gint retval = 0; ia1 = internet_address_new_from_string ((const char *) address1); ia2 = internet_address_new_from_string ((const char *) address2); + g_return_val_if_fail (ia1 != NULL, -1); + g_return_val_if_fail (ia2 != NULL, 1); + if (!ia1->name && !ia2->name) { /* if neither has a name we should compare addresses */ retval = g_strcasecmp (ia1->address, ia2->address); @@ -247,9 +251,45 @@ address_compare (gconstpointer address1, gconstpointer address2) else if (!ia2->name) retval = 1; else { - /* FIXME: use Nat's e-western-name parser - * so we can compare last name then first */ - retval = g_strcasecmp (ia1->name, ia2->name); + ENameWestern *name1, *name2; + + name1 = e_name_western_parse (ia1->name); + name2 = e_name_western_parse (ia2->name); + + if (!name1->last && !name2->last) { + /* neither has a last name */ + + retval = g_strcasecmp (ia1->name, ia2->name); + } else { + /* compare last names */ + + if (!name1->last) + retval = -1; + else if (!name2->last) + retval = 1; + else { + retval = g_strcasecmp (name1->last, name2->last); + if (!retval) { + /* last names are identical - compare first names */ + + if (!name1->first) + retval = -1; + else if (!name2->first) + retval = 1; + else { + retval = g_strcasecmp (name1->first, name2->first); + if (!retval) { + /* first names are identical - compare addresses */ + + retval = g_strcasecmp (ia1->address, ia2->address); + } + } + } + } + } + + e_name_western_free (name1); + e_name_western_free (name2); } } -- cgit