From 990f73de5d244a8033ab173ba156778127e824c4 Mon Sep 17 00:00:00 2001 From: Adam Wolfe Gordon Date: Tue, 26 Feb 2013 15:47:13 +1700 Subject: [PATCH] [PATCH v2] lib: Fix name reordering to handle commas without spaces --- 2e/25c5bbc02908174ee9cf610ae5485dc8fc70fb | 90 +++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 2e/25c5bbc02908174ee9cf610ae5485dc8fc70fb diff --git a/2e/25c5bbc02908174ee9cf610ae5485dc8fc70fb b/2e/25c5bbc02908174ee9cf610ae5485dc8fc70fb new file mode 100644 index 000000000..127c6b16c --- /dev/null +++ b/2e/25c5bbc02908174ee9cf610ae5485dc8fc70fb @@ -0,0 +1,90 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id 957BB431FB6 + for ; Mon, 25 Feb 2013 14:48:52 -0800 (PST) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: 0 +X-Spam-Level: +X-Spam-Status: No, score=0 tagged_above=-999 required=5 + tests=[RCVD_IN_DNSWL_NONE=-0.0001] autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id 8JL1VGnlOQtl for ; + Mon, 25 Feb 2013 14:48:52 -0800 (PST) +Received: from smtp-out-04.shaw.ca (smtp-out-04.shaw.ca [64.59.134.12]) + by olra.theworths.org (Postfix) with ESMTP id EA1B8431FAF + for ; Mon, 25 Feb 2013 14:48:51 -0800 (PST) +X-Cloudmark-SP-Filtered: true +X-Cloudmark-SP-Result: v=1.1 cv=6HkG4LK5i0ZTEQwzSfMqnsQ8WbrxJ2NwB1mI+RNtyjI= + c=1 sm=1 + a=MY12FBClXswA:10 a=BLceEmwcHowA:10 a=gumk1giGF0obp6xRQyl7Yg==:17 + a=A1X0JdhQAAAA:8 a=m7NE1Zox25VmYJf3OS4A:9 a=9Mll2h4CvCUA:10 + a=Y6qChIQXU1wA:10 a=FHn133utvqvlW6fs:21 a=RDXoABUQQL8Ji2za:21 + a=HpAAvcLHHh0Zw7uRqdWCyQ==:117 +Received: from unknown (HELO lagos.xvx.ca) ([68.150.39.45]) + by smtp-out-04.shaw.ca with ESMTP; 25 Feb 2013 15:48:51 -0700 +Received: by lagos.xvx.ca (Postfix, from userid 1000) + id 237E280031A5; Mon, 25 Feb 2013 15:48:51 -0700 (MST) +From: Adam Wolfe Gordon +To: notmuch@notmuchmail.org +Subject: [PATCH v2] lib: Fix name reordering to handle commas without spaces +Date: Mon, 25 Feb 2013 15:47:13 -0700 +Message-Id: <1361832433-13036-1-git-send-email-awg+notmuch@xvx.ca> +X-Mailer: git-send-email 1.7.9.5 +In-Reply-To: +References: +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Mon, 25 Feb 2013 22:48:52 -0000 + +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. +--- + +Good idea, Tomi. This version handles any number of spaces. + +lib/thread.cc | 12 ++++++++++-- + 1 file changed, 10 insertions(+), 2 deletions(-) + +diff --git a/lib/thread.cc b/lib/thread.cc +index e976d64..ce6b0ef 100644 +--- a/lib/thread.cc ++++ b/lib/thread.cc +@@ -186,8 +186,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; +- 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'; +-- +1.7.9.5 + -- 2.26.2