]> git.notmuchmail.org Git - notmuch/blobdiff - notmuch-index-message.cc
notmuch-index-message: Use local-part of email addres in lieu of name.
[notmuch] / notmuch-index-message.cc
index f7ea340f977329d5da7354a2a613ec5766259720..913306582e74fc8cd29f778318d2c03e39b3a8cb 100644 (file)
@@ -139,11 +139,29 @@ gen_terms_address_name (Xapian::TermGenerator term_gen,
                        const char *prefix_name)
 {
     const char *name;
+    int own_name = 0;
 
     name = internet_address_get_name (address);
 
+    /* In the absence of a name, we'll strip the part before the @
+     * from the address. */
+    if (! name) {
+       InternetAddressMailbox *mailbox = INTERNET_ADDRESS_MAILBOX (address);
+       const char *addr = internet_address_mailbox_get_addr (mailbox);
+       const char *at;
+
+       at = strchr (addr, '@');
+       if (at) {
+           name = strndup (addr, at - addr);
+           own_name = 1;
+       }
+    }
+
     if (name)
        gen_terms (term_gen, prefix_name, name);
+
+    if (own_name)
+       free ((void *) name);
 }
 
 static void
@@ -307,30 +325,22 @@ find_thread_id (Xapian::Database db,
  * message. */
 static void
 parse_references (GPtrArray *array,
-                 const char *refs)
+                 const char *refs_str)
 {
-    const char *end, *next;
+    GMimeReferences *refs, *r;
+    const char *message_id;
 
-    if (refs == NULL)
+    if (refs_str == NULL)
        return;
 
-    while (*refs) {
-       while (*refs && isspace (*refs))
-           refs++;
-       if (*refs == '<')
-           refs++;
-       end = refs;
-       while (*end && !isspace (*end))
-           end++;
-       next = end;
-       end--;
-       if (end > refs && *end == '>')
-           end--;
-       if (end > refs) {
-           g_ptr_array_add (array, g_strndup (refs, end - refs + 1));
-       }
-       refs = next;
+    refs = g_mime_references_decode (refs_str);
+
+    for (r = refs; r; r = r->next) {
+       message_id = g_mime_references_get_message_id (r);
+       g_ptr_array_add (array, g_strdup (message_id));
     }
+
+    g_mime_references_free (refs);
 }
 
 /* Given a string representing the body of a message, generate terms