X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=index.cc;h=747a4e63334c1aa3c5602134f39ecfb1ab8d3978;hp=88634fc76ed784beb853581abf579dd595e4ac56;hb=acdc9988a2a502accad860a116b094b0a1f62008;hpb=f9bbd7baa07110c7f345c8413e2426d00382cb1c diff --git a/index.cc b/index.cc index 88634fc7..747a4e63 100644 --- a/index.cc +++ b/index.cc @@ -30,13 +30,23 @@ _index_address_mailbox (notmuch_message_t *message, InternetAddress *address) { InternetAddressMailbox *mailbox = INTERNET_ADDRESS_MAILBOX (address); - const char *name, *addr = internet_address_mailbox_get_addr (mailbox); + const char *name, *addr; + char *contact; int own_name = 0; - if (addr) - _notmuch_message_gen_terms (message, prefix_name, addr); - name = internet_address_get_name (address); + addr = internet_address_mailbox_get_addr (mailbox); + + if (addr) { + if (name) { + contact = talloc_asprintf (message, "\"%s\" <%s>", + name, addr); + _notmuch_message_add_term (message, "contact", contact); + talloc_free (contact); + } else { + _notmuch_message_add_term (message, "contact", addr); + } + } /* In the absence of a name, we'll strip the part before the @ * from the address. */ @@ -52,6 +62,8 @@ _index_address_mailbox (notmuch_message_t *message, if (name) _notmuch_message_gen_terms (message, prefix_name, name); + if (addr) + _notmuch_message_gen_terms (message, prefix_name, addr); } static void @@ -123,6 +135,60 @@ skip_re_in_subject (const char *subject) return s; } +/* Given a string representing the body of a message, generate terms + * for it, (skipping quoted portions and signatures). + * + * This function is evil in that it modifies the string passed to it, + * (changing some newlines into '\0'). + */ +static void +_index_body_text (notmuch_message_t *message, char *body) +{ + char *line, *line_end, *next_line; + + if (body == NULL) + return; + + next_line = body; + + while (1) { + line = next_line; + if (*line == '\0') + break; + + next_line = strchr (line, '\n'); + if (next_line == NULL) { + next_line = line + strlen (line); + } + line_end = next_line - 1; + + /* Get to the next non-blank line. */ + while (*next_line == '\n') + next_line++; + + /* Skip blank lines. */ + if (line_end < line) + continue; + + /* Skip lines that are quotes. */ + if (*line == '>') + continue; + + /* Also skip lines introducing a quote on the next line. */ + if (*line_end == ':' && *next_line == '>') + continue; + + /* Finally, bail as soon as we see a signature. */ + /* XXX: Should only do this if "near" the end of the message. */ + if (strncmp (line, "-- ", 3) == 0) + break; + + *(line_end + 1) = '\0'; + + _notmuch_message_gen_terms (message, NULL, line); + } +} + /* Callback to generate terms for each mime part of a message. */ static void _index_mime_part (notmuch_message_t *message, @@ -195,7 +261,7 @@ _index_mime_part (notmuch_message_t *message, g_byte_array_append (byte_array, (guint8 *) "\0", 1); body = (char *) g_byte_array_free (byte_array, FALSE); - _notmuch_message_gen_terms (message, NULL, body); + _index_body_text (message, body); free (body); }