unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Dirk Hohndel <hohndel@infradead.org>
To: notmuch <notmuch@notmuchmail.org>
Subject: [PATCH] Clean up author display for some "Last, First" cases
Date: Wed, 21 Apr 2010 22:04:39 -0700	[thread overview]
Message-ID: <m3633kyt5k.fsf@x200.gr8dns.org> (raw)


We specifically check if this is one of these two patterns:
 "Last, First" <first.last@company.com>
 "Last, First MI" <first.mi.last@company.com>
If this is the case, we rewrite the author name in a more
reader friendly manner

Signed-off-by: Dirk Hohndel <hohndel@infradead.org>
---
 lib/thread.cc |   51 +++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 49 insertions(+), 2 deletions(-)

diff --git a/lib/thread.cc b/lib/thread.cc
index baa0d7f..7e72114 100644
--- a/lib/thread.cc
+++ b/lib/thread.cc
@@ -144,6 +144,51 @@ _thread_move_matched_author (notmuch_thread_t *thread,
     return;
 }
 
+/* clean up the uggly "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" <first.last@company.com>
+ * "Last, First MI" <first.mi.last@company.com>
+ */
+char *
+_thread_cleanup_author (notmuch_thread_t *thread,
+			const char *author, const char *from)
+{
+    char *cleanauthor,*testauthor;
+    const char *comma;
+    char *blank;
+    int fname,lname;
+
+    cleanauthor = talloc_strdup(thread, author);
+    if (cleanauthor == NULL)
+	return NULL;
+    comma = strchr(author,',');
+    if (comma) {
+	/* let's assemble what we think is the correct name */
+	lname = comma - author;
+	fname = strlen(author) - lname - 2;
+	strncpy(cleanauthor, comma + 2, fname);
+	*(cleanauthor+fname) = ' ';
+	strncpy(cleanauthor + fname + 1, author, lname);
+	*(cleanauthor+fname+1+lname) = '\0';
+	/* make a temporary copy and see if it matches the email */
+	testauthor = xstrdup(cleanauthor);
+	
+	blank=strchr(testauthor,' ');
+	while (blank != NULL) {
+	    *blank = '.';
+	    blank=strchr(testauthor,' ');
+	}
+	if (strcasestr(from, testauthor) == NULL)
+	    /* we didn't identify this as part of the email address 
+	    * so let's punt and return the original author */
+	    strcpy (cleanauthor, author);
+	       
+    }
+    return cleanauthor;
+}
+
 /* Add 'message' as a message that belongs to 'thread'.
  *
  * The 'thread' will talloc_steal the 'message' and hold onto a
@@ -158,6 +203,7 @@ _thread_add_message (notmuch_thread_t *thread,
     InternetAddressList *list;
     InternetAddress *address;
     const char *from, *author;
+    char *cleanauthor;
 
     _notmuch_message_list_add_message (thread->message_list,
 				       talloc_steal (thread, message));
@@ -178,8 +224,9 @@ _thread_add_message (notmuch_thread_t *thread,
 		mailbox = INTERNET_ADDRESS_MAILBOX (address);
 		author = internet_address_mailbox_get_addr (mailbox);
 	    }
-	    _thread_add_author (thread, author);
-	    notmuch_message_set_author (message, author);
+	    cleanauthor = _thread_cleanup_author (thread, author, from);
+	    _thread_add_author (thread, cleanauthor);
+	    notmuch_message_set_author (message, cleanauthor);
 	}
 	g_object_unref (G_OBJECT (list));
     }
-- 
1.6.6.1


-- 
Dirk Hohndel
Intel Open Source Technology Center

             reply	other threads:[~2010-04-22  5:04 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-04-22  5:04 Dirk Hohndel [this message]
2010-04-24 15:30 ` [PATCH] Clean up author display for some "Last, First" cases Carl Worth
2010-04-24 16:57   ` Dirk Hohndel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m3633kyt5k.fsf@x200.gr8dns.org \
    --to=hohndel@infradead.org \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).