search query "replytoid:<blah>"

Suvayu Ali fatkasuvayu+linux at gmail.com
Sun Jun 14 01:22:58 PDT 2015


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 at mail.gmail.com
  id:877fr79upd.fsf at maritornes.cs.unb.ca id:20150613205552.GC17381 at 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.
-------------- next part --------------
#!/bin/bash

# Return responses to message id query
#
# $ nm-ack id:msgid at domain
# id:response1 at domain1 id:response2 at 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[@]}


More information about the notmuch mailing list