]> git.notmuchmail.org Git - notmuch/commitdiff
lib: Index name and address of from/to headers as a phrase
authorAustin Clements <amdragon@MIT.EDU>
Mon, 16 Jun 2014 02:40:32 +0000 (22:40 -0400)
committerDavid Bremner <david@tethera.net>
Wed, 18 Jun 2014 20:55:14 +0000 (17:55 -0300)
Previously, we indexed the name and address parts of from/to headers
with two calls to _notmuch_message_gen_terms.  In general, this
indicates that these parts are separate phrases.  However, because of
an implementation quirk, the two calls to _notmuch_message_gen_terms
generated adjacent term positions for the prefixed terms, which
happens to be the right thing to do in this case, but the wrong thing
to do for all other calls.  Furthermore, _notmuch_message_gen_terms
produced potentially overlapping term positions for the un-prefixed
copies of the terms, which is simply wrong.

This change indexes both the name and address in a single call to
_notmuch_message_gen_terms, indicating that they should be part of a
single phrase.  This masks the problem with the un-prefixed terms
(fixing the two known-broken tests) and puts us in a position to fix
the unintentionally phrases generated by other calls to
_notmuch_message_gen_terms.

lib/index.cc
test/T080-search.sh

index e1e2a3828f024988d59b8d28d9524a4a0ba99f28..1a2e63df58e45a2f163f7ca61ab6a7740032314a 100644 (file)
@@ -231,26 +231,22 @@ _index_address_mailbox (notmuch_message_t *message,
                        InternetAddress *address)
 {
     InternetAddressMailbox *mailbox = INTERNET_ADDRESS_MAILBOX (address);
-    const char *name, *addr;
+    const char *name, *addr, *combined;
     void *local = talloc_new (message);
 
     name = internet_address_get_name (address);
     addr = internet_address_mailbox_get_addr (mailbox);
 
-    /* In the absence of a name, we'll strip the part before the @
-     * from the address. */
-    if (! name) {
-       const char *at;
+    /* Combine the name and address and index them as a phrase. */
+    if (name && addr)
+       combined = talloc_asprintf (local, "%s %s", name, addr);
+    else if (name)
+       combined = name;
+    else
+       combined = addr;
 
-       at = strchr (addr, '@');
-       if (at)
-           name = talloc_strndup (local, addr, at - addr);
-    }
-
-    if (name)
-       _notmuch_message_gen_terms (message, prefix_name, name);
-    if (addr)
-       _notmuch_message_gen_terms (message, prefix_name, addr);
+    if (combined)
+       _notmuch_message_gen_terms (message, prefix_name, combined);
 
     talloc_free (local);
 }
index 8ed57013cd0d06088234acaeed0c1c98a40b2e5c..b63bf023de4cdae9d39991a3e49742d3c1fcfe6d 100755 (executable)
@@ -67,7 +67,6 @@ output=$(notmuch search 'from:"Search By From Name <test@example.com>"' | notmuc
 test_expect_equal "$output" "thread:XXX   2000-01-01 [1/1] Search By From Name; search by from (name) (inbox unread)"
 
 test_begin_subtest "Search by from: without prefix (name and address)"
-test_subtest_known_broken
 output=$(notmuch search '"Search By From Name <test@example.com>"' | notmuch_search_sanitize)
 test_expect_equal "$output" "thread:XXX   2000-01-01 [1/1] Search By From Name; search by from (name) (inbox unread)"
 
@@ -86,7 +85,6 @@ output=$(notmuch search 'to:"Search By To Name <test@example.com>"' | notmuch_se
 test_expect_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by to (name) (inbox unread)"
 
 test_begin_subtest "Search by to: without prefix (name and adress)"
-test_subtest_known_broken
 output=$(notmuch search '"Search By To Name <test@example.com>"' | notmuch_search_sanitize)
 test_expect_equal "$output" "thread:XXX   2000-01-01 [1/1] Notmuch Test Suite; search by to (name) (inbox unread)"