#!/bin/bash

dir=$(mktemp -d)
trap "rm -rf $dir" EXIT

mkdir "$dir"/sent

notmuch search --output=files to:notmuch from:jrollins \
    | head -1 \
    | xargs -I'{}' cp '{}' "$dir"/sent/

export NOTMUCH_CONFIG="$dir"/config

cat <<EOF >"$NOTMUCH_CONFIG"
[database]
path=$dir
EOF

notmuch new

echo "== notmuch search '*':"
notmuch search '*'

echo "== notmuch search 'folder:sent':"
notmuch search 'folder:sent'

echo "== python search '*':"
python -c "import notmuch
db = notmuch.Database()
q = notmuch.Query(db, '*')
for msg in q.search_messages():
    print msg
"

echo "== python search 'folder:sent':"
python -c "import notmuch
db = notmuch.Database()
q = notmuch.Query(db, 'folder:sent')
for msg in q.search_messages():
    print msg
"
