]> git.notmuchmail.org Git - notmuch/commitdiff
lib: Fix name reordering to handle commas without spaces
authorAdam Wolfe Gordon <awg+notmuch@xvx.ca>
Mon, 25 Feb 2013 22:47:13 +0000 (15:47 -0700)
committerDavid Bremner <bremner@unb.ca>
Fri, 29 Mar 2013 13:24:29 +0000 (09:24 -0400)
Notmuch automatically re-orders names of the format "Last, First" to
"First Last" when the associated email address is
First.Last@example.com. But, if a name is of the format "Last,First"
then notmuch will format the name as "irst Last". Handle any number of
spaces after the comma, including none.

lib/thread.cc

index c126aac8cc8b945e9018f7505f7910174c83535e..50bdef11aa8cba0f2240a142052a2ee249d74df1 100644 (file)
@@ -190,8 +190,16 @@ _thread_cleanup_author (notmuch_thread_t *thread,
     if (comma && strlen(comma) > 1) {
        /* let's assemble what we think is the correct name */
        lname = comma - author;
     if (comma && strlen(comma) > 1) {
        /* let's assemble what we think is the correct name */
        lname = comma - author;
-       fname = strlen(author) - lname - 2;
-       strncpy(clean_author, comma + 2, fname);
+
+       /* Skip all the spaces after the comma */
+       fname = strlen(author) - lname - 1;
+       comma += 1;
+       while (*comma == ' ') {
+           fname -= 1;
+           comma += 1;
+       }
+       strncpy(clean_author, comma, fname);
+
        *(clean_author+fname) = ' ';
        strncpy(clean_author + fname + 1, author, lname);
        *(clean_author+fname+1+lname) = '\0';
        *(clean_author+fname) = ' ';
        strncpy(clean_author + fname + 1, author, lname);
        *(clean_author+fname+1+lname) = '\0';