Re: search query "replytoid:<blah>"

Subject: Re: search query "replytoid:<blah>"

Date: Sun, 14 Jun 2015 10:22:58 +0200

To: notmuch@notmuchmail.org

Cc:

From: Suvayu Ali


On Sat, Jun 13, 2015 at 10:55:52PM +0200, Suvayu Ali wrote:
> On Sat, Jun 13, 2015 at 02:47:00PM -0400, Xu Wang wrote:
> > 
> > Is it possible to search based on which message ID a message
> > *responds* to? For example, suppose message id is MESSAGEID. I want to
> > find all emails that responded to MESSAGEID. How to enter such a query
> > into notmuch?
> 
> AFAIK, this is not possible.  Notmuch does not allow searching special
> headers.  You could probably write a script using the threads output
> format to get the thread, and then use formail to find the responses.

Try the attached script.  It accepts notmuch queries by message id.
E.g. to get the responses to your OP, you can do:

  $ ./nm-ack id:CAJhTkNhYew6H-bptACTew3gN3DLWg6agTYu8hAkdwFS=z4VFWg@mail.gmail.com
  id:877fr79upd.fsf@maritornes.cs.unb.ca id:20150613205552.GC17381@chitra.no-ip.org

The first one is David's response, the second one is mine.

Hope this helps,

-- 
Suvayu

Open source is the future. It sets us free.
#!/bin/bash

# Return responses to message id query
#
# $ nm-ack id:msgid@domain
# id:response1@domain1 id:response2@domain2 ...
#
# Author: Suvayu Ali

# debug
# set -o xtrace

declare query="$1" thread=$(notmuch search --output=threads -- "$1")
declare -a msgs=$(notmuch search --output=messages -- "$thread") responses

function strip_mid() {
    sed -e 's/[<> ]//g'
}

for m in ${msgs[@]}; do
    [[ $query == $m ]] && continue
    r=id:$(notmuch show --format=raw -- $m | formail -x In-Reply-To: | strip_mid)
    [[ $query == $r ]] && responses+=($m)
done

echo ${responses[@]}

Thread: