#include "notmuch-private.h"
#include "database-private.h"
-#include <xapian.h>
-
#include <gmime/gmime.h>
#include <glib.h> /* GHashTable */
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" <first.last@company.com>
* "Last, First MI" <first.mi.last@company.com>
*/
-char *
+static char *
_thread_cleanup_author (notmuch_thread_t *thread,
const char *author, const char *from)
{
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;
/* 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;
}
date = notmuch_message_get_date (message);
- if (date < thread->oldest || ! thread->matched_messages)
+ if (date < thread->oldest || ! thread->matched_messages) {
thread->oldest = date;
+ if (sort == NOTMUCH_SORT_OLDEST_FIRST)
+ _thread_set_subject_from_message (thread, message);
+ }
- if (date > thread->newest || ! thread->matched_messages)
+ if (date > thread->newest || ! thread->matched_messages) {
thread->newest = date;
+ if (sort != NOTMUCH_SORT_OLDEST_FIRST)
+ _thread_set_subject_from_message (thread, message);
+ }
thread->matched_messages++;
}
_thread_add_matched_author (thread, notmuch_message_get_author (hashed_message));
-
- if ((sort == NOTMUCH_SORT_OLDEST_FIRST && date <= thread->newest) ||
- (sort != NOTMUCH_SORT_OLDEST_FIRST && date == thread->newest))
- {
- _thread_set_subject_from_message (thread, message);
- }
}
static void