Re: I don't understand the results of this search query, is this a bug?

Subject: Re: I don't understand the results of this search query, is this a bug?

Date: Mon, 13 May 2024 14:38:10 -0700

To: Renaud B.,


From: Carl Worth

Hi Renaud,

I was able to see similar behavior in my own mail store. And I agree
that this behavior is confusing!

The documentation for the --files option of notmuch search documents the
cause (and predicts that this will be confusing):

        Note that each message may have multiple filenames associ‐
        ated  with it. All of them are included in the output (un‐
        less limited with the --duplicate=N option). This  may  be
        particularly  confusing for folder: or path: searches in a
        specified directory, as the messages may  have  duplicates
        in  other directories that are included in the output, al‐
        though these files alone would not match the search.

For my case, I ran a little shell-script one-liner to verify that the
duplicated messages where causing this behavior. This one-liner will
loop over each message-id matched by the path: pattern and will print
all filenames for each:

for id in $(notmuch search --output=messages path:YOUR_PATTERN_HERE); do \
    echo "=== $id ==="; \
    notmuch search --output=files $id; \
    echo; \

If you run the above with your own pattern substituted for
YOUR_PATTERN_HERE I imagine you'll see the same thing I did, (that for
any filename paths that don't match the pattern, they have a message-id
which _also_ appears in the database for another path that _does_ match
the pattern).

In general, I'm not a fan of software documenting "this may be
confusing". That suggests the authors of the documentation know that the
software is not behaving as the user intends, so it would be preferable
for the software to behave as intended. That said, I also understand the
implementation details that lead to this behavior. So I wouldn't be
opposed to improving the behavior of notmuch to reduce this behavior,
(but that implementation might not be trivial or even fully feasible).

Hopefully, the duplicate message-id issue explains what you're
seeing. And further, I hope that you just being aware of this issue
gives you a way to cleanly solve your problem, (either by filtering the
output of "notmuch search --output=files" or by instead doing something
along the lines of the "notmuch search --output=messages" approach I
show above).

Let us know if you need anything further. And good luck!


On Mon, May 13 2024, Renaud B. wrote:
> Hello,
> If I do:
> notmuch search --output=files**
> I get the following results:
> /home/rb/.mail/,U=2:2,S
> /home/rb/.mail/
> /home/rb/.mail/,U=4:2,S
> /home/rb/.mail/
> /home/rb/.mail/,U=1:2,S
> /home/rb/.mail/,U=1:2,S
> /home/rb/.mail/,U=3:2,S
> /home/rb/.mail/,U=2:2,S
> /home/rb/.mail/,U=1:2,S
> As you can see, two of these files are located under "~/.mail/
>". It shouldn't be the case, because of the "
>**" which means explicitly "everything under the
> ~/.mail/ directory" (if I understand correctly).
> Likewise, if I do:
> notmuch search --output=files**
> It returns:
> /home/rb/.mail/
> /home/rb/.mail/,U=4:2,S
> /home/rb/.mail/
> /home/rb/.mail/,U=1:2,S
> Again, there are 2 false results.
> Do you have any idea what's happening? My goal is simply to get all emails
> under each directories in my "~/.mail" folder, one at a time.
> Thanks,
> Renaud B.
> _______________________________________________
> notmuch mailing list --
> To unsubscribe send an email to
notmuch mailing list --
To unsubscribe send an email to