X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=lib%2Fthread.cc;h=7f15586286d9441e1199c6f63c1867944b4b645b;hp=dc74ee3e95d30e2921d267147f51820539043d95;hb=d064bd696ccc443a7ece9cfc8816999c69943223;hpb=c210d5632e7346b9c8582a93685747f201a27267 diff --git a/lib/thread.cc b/lib/thread.cc index dc74ee3e..7f155862 100644 --- a/lib/thread.cc +++ b/lib/thread.cc @@ -21,8 +21,6 @@ #include "notmuch-private.h" #include "database-private.h" -#include - #include #include /* GHashTable */ @@ -140,14 +138,14 @@ _complete_thread_authors (notmuch_thread_t *thread) thread->authors_array = NULL; } -/* clean up the uggly "Lastname, Firstname" format that some mail systems +/* clean up the ugly "Lastname, Firstname" format that some mail systems * (most notably, Exchange) are creating to be "Firstname Lastname" * To make sure that we don't change other potential situations where a * comma is in the name, we check that we match one of these patterns * "Last, First" * "Last, First MI" */ -char * +static char * _thread_cleanup_author (notmuch_thread_t *thread, const char *author, const char *from) { @@ -156,11 +154,19 @@ _thread_cleanup_author (notmuch_thread_t *thread, char *blank; int fname,lname; + if (author == NULL) + return NULL; clean_author = talloc_strdup(thread, author); if (clean_author == NULL) return NULL; + /* check if there's a comma in the name and that there's a + * component of the name behind it (so the name doesn't end with + * the comma - in which case the string that strchr finds is just + * one character long ",\0"). + * Otherwise just return the copy of the original author name that + * we just made*/ comma = strchr(author,','); - if (comma) { + if (comma && strlen(comma) > 1) { /* let's assemble what we think is the correct name */ lname = comma - author; fname = strlen(author) - lname - 2; @@ -180,7 +186,6 @@ _thread_cleanup_author (notmuch_thread_t *thread, /* we didn't identify this as part of the email address * so let's punt and return the original author */ strcpy (clean_author, author); - } return clean_author; }