Searching for an Exact Email Address

classic Classic list List threaded Threaded
6 messages Options
Kevin Foley Kevin Foley
Reply | Threaded
Open this post in threaded view
|

Searching for an Exact Email Address

Hi,

I'm getting unexpected results when trying to search for messages
associated with an email address.

An example search is:

$ notmuch search to:"[hidden email]"

which is returning messages that seem to have nothing to do with the
address I'm looking for.

My understanding is this should be treated as a phrase which means that
exact phrase will be searched for, is this correct?  If not is there a
way to search for an exact email address in the to field?

Thanks,
Kevin

_______________________________________________
notmuch mailing list
[hidden email]
https://notmuchmail.org/mailman/listinfo/notmuch
David Bremner-2 David Bremner-2
Reply | Threaded
Open this post in threaded view
|

Re: Searching for an Exact Email Address

Kevin Foley <[hidden email]> writes:

> Hi,
>
> I'm getting unexpected results when trying to search for messages
> associated with an email address.
>
> An example search is:
>
> $ notmuch search to:"[hidden email]"

See the subsection Quoting in notmuch-search-terms(7). I suspect you
need to double-quote your query, as the examples in the documentation are.

>
> which is returning messages that seem to have nothing to do with the
> address I'm looking for.
>
> My understanding is this should be treated as a phrase which means that
> exact phrase will be searched for, is this correct?  If not is there a
> way to search for an exact email address in the to field?
>

You can also do regex searches, although they are are measurably
slower. The syntax is also discussed in notmuch-search-terms(7).

_______________________________________________
notmuch mailing list
[hidden email]
https://notmuchmail.org/mailman/listinfo/notmuch
Teemu Likonen Teemu Likonen
Reply | Threaded
Open this post in threaded view
|

Re: Searching for an Exact Email Address

In reply to this post by Kevin Foley
Kevin Foley [2020-02-01T16:29:25-05] wrote:

> I'm getting unexpected results when trying to search for messages
> associated with an email address.

> $ notmuch search to:"[hidden email]"

> My understanding is this should be treated as a phrase which means
> that exact phrase will be searched for, is this correct?

Double quotes are special characters in your shell and it interprets
them so that notmuch doesn't get them. There are different ways in shell
to escape special characters:

    to:\"[hidden email]\"
    'to:"[hidden email]"'

The shell built-in "set" is useful for testing parameters:

    $ set -- to:"[hidden email]" to:\"[hidden email]\"
    $ printf '%s\n' "$@"
    to:[hidden email]
    to:"[hidden email]"

--
///  OpenPGP key: 4E1055DC84E9DFF613D78557719D69D324539450
//  https://keys.openpgp.org/search?q=tlikonen@...
/  https://keybase.io/tlikonen  https://github.com/tlikonen

_______________________________________________
notmuch mailing list
[hidden email]
https://notmuchmail.org/mailman/listinfo/notmuch

signature.asc (707 bytes) Download Attachment
David Bremner-2 David Bremner-2
Reply | Threaded
Open this post in threaded view
|

Re: Searching for an Exact Email Address

Teemu Likonen <[hidden email]> writes:

> The shell built-in "set" is useful for testing parameters:
>
>     $ set -- to:"[hidden email]" to:\"[hidden email]\"
>     $ printf '%s\n' "$@"
>     to:[hidden email]
>     to:"[hidden email]"


Also useful is setting NOTMUCH_DEBUG_QUERY in the environment. This will
show the parsed Xapian query. In my case this shows both
'to:"[hidden email]"' and to:"[hidden email]" end up parsed the
same way, so I guess the problem is elsewhere.  Maybe you can try it
with your actual query.

d
_______________________________________________
notmuch mailing list
[hidden email]
https://notmuchmail.org/mailman/listinfo/notmuch
Kevin Foley Kevin Foley
Reply | Threaded
Open this post in threaded view
|

Re: Searching for an Exact Email Address


David Bremner <[hidden email]> writes:

> Also useful is setting NOTMUCH_DEBUG_QUERY in the environment. This will
> show the parsed Xapian query. In my case this shows both
> 'to:"[hidden email]"' and to:"[hidden email]" end up parsed the
> same way, so I guess the problem is elsewhere.

I should have mentioned that I tried using NOTMUCH_DEBUG_QUERY with many
different quoting variations and kept getting the same final query:

Query((Tmail AND (XTOexample@1 PHRASE 3 XTOemail@2 PHRASE 3 XTOcom@3)))

It looks like the punctuation is being stripped; I get the same final
query for `notmuch search 'to:"example email com"'`.  Is this the
expected behavior?

David Bremner <[hidden email]> writes:

>  You can also do regex searches, although they are are measurably
>  slower. The syntax is also discussed in notmuch-search-terms(7).

I tried this as well but per notmuch-search-terms(7) it looks like regex
isn't supported for the "to" field.

Also as a side note, I don't think the quoting is necessary as per the
"searching" documentation [0], "... e-mail addresses are also treated as
phrases.".

Kevin

[0] https://notmuchmail.org/searching/
_______________________________________________
notmuch mailing list
[hidden email]
https://notmuchmail.org/mailman/listinfo/notmuch
David Bremner-2 David Bremner-2
Reply | Threaded
Open this post in threaded view
|

Re: Searching for an Exact Email Address

Kevin Foley <[hidden email]> writes:

> David Bremner <[hidden email]> writes:
>
>> Also useful is setting NOTMUCH_DEBUG_QUERY in the environment. This will
>> show the parsed Xapian query. In my case this shows both
>> 'to:"[hidden email]"' and to:"[hidden email]" end up parsed the
>> same way, so I guess the problem is elsewhere.
>
> I should have mentioned that I tried using NOTMUCH_DEBUG_QUERY with many
> different quoting variations and kept getting the same final query:
>
> Query((Tmail AND (XTOexample@1 PHRASE 3 XTOemail@2 PHRASE 3 XTOcom@3)))
>
> It looks like the punctuation is being stripped; I get the same final
> query for `notmuch search 'to:"example email com"'`.  Is this the
> expected behavior?

Yes, that's how phrases work.

> I tried this as well but per notmuch-search-terms(7) it looks like regex
> isn't supported for the "to" field.

Ah right. it's really an implimentation quirk that that From: addresses
are stored in the form needed for regex searching.

> Also as a side note, I don't think the quoting is necessary as per the
> "searching" documentation [0], "... e-mail addresses are also treated as
> phrases.".

Quoting is certainly necessary for phrases containing spaces, but yes,
as documented phrases can also be built with punctuation.
_______________________________________________
notmuch mailing list
[hidden email]
https://notmuchmail.org/mailman/listinfo/notmuch