Exporting a single email as JSON

Ciprian Dorin Craciun ciprian.craciun at gmail.com
Sat Dec 10 17:03:57 PST 2011


On Sun, Dec 11, 2011 at 01:19, Jameson Graef Rollins
<jrollins at finestructure.net> wrote:
> On Sun, 11 Dec 2011 00:46:51 +0200, Ciprian Dorin Craciun <ciprian.craciun at gmail.com> wrote:
>>     * in my use-case I would need each line of the output to be a
>> standalone JSON object of an individual message; (thus I can script
>> with Bash `notmuch ... | while read message ; do ... ; done`;)
>
> This is actually a slightly different idea than what I thought you were
> originally proposing.  Outputting a series of json objects rather than a
> single list has been talked about for notmuch search as well.  I'm don't
> have a good sense of whether this is a sensible idea or not.
>
>>     * maybe someone else would need that the output to contain
>> **exactly one** such message (maybe the first);
>
> This is what I thought we were talking about.  This is an option I would
> like to see, at least.


    Indeed exporting multiple messages as top / root JSON objects
isn't quite usable except limited import / export use-cases, thus what
you propose is more sensible. And in the end by having this
possibility I could easily implement the solution I'm seeking as
simple as:
~~~~
notmuch --output=messages -- {criteria} \
| xargs -L 1 -- notmuch show --format=json -- \
| while read message_json ; do ... ; done
~~~~

    But there is only one problem with such an approach: efficiency.
With the snippet above I'll have as many `notmuch` process executions
as messages. (And I do have quite a few of them.) Thus although
Notmuch is quite fast -- as in human imperceptible -- still opening
and closing the Xapian database so many times does have quite an
overhead.

    So in the end I think a discussion about the needed (/ wanted)
use-cases would be better.

    Ciprian.

    P.S.: I could help implement (or at least prototype) some of these
use-cases. Thus I'll watch over the thread you've pointed me to.


More information about the notmuch mailing list