[python] get all messages of a thread

Subject: [python] get all messages of a thread

Date: Sat, 28 May 2011 14:18:05 +0100

To: notmuch

Cc:

From: Patrick Totzke


Hi!
I wonder how I would get all messages of a thread with the python
bindings. The doc says one can only use Thread.get_toplevel_messages()
and then must recursively call Message.get_replies().
But look:

---------------- snip -------------------------
#/usr/bin/python
from notmuch import Database

def get_thread():
    query = Database().create_query('thread:0000000000000c48')
    return query.search_threads().next()
    
def replies(msg):
    acc = []
    r = msg.get_replies()
    if r: #because we cant iterate on NoneType
        for m in r:
            acc.append(m)
            acc += replies(m)
    return acc
    
t=get_thread()

msgs = []
for m in t.get_toplevel_messages():
    msgs.append(m)
    msgs += replies(m)

print msgs
------------------- snap --------------------
gives:

Traceback (most recent call last):
  File "replies.py", line 22, in <module>
    msgs +=replies(m)
  File "replies.py", line 12, in replies
    for m in r:
  File "/usr/local/lib/python2.7/dist-packages/notmuch/message.py", line 140, in next
    raise NotmuchError(STATUS.NOT_INITIALIZED)
notmuch.globals.NotmuchError: Operation on uninitialized object impossible.
---------------------------------------------
It seems that nobody needed this before. Even in bindings/python/notmuch.py
only Threads.get_toplevel_messages() gets called, and then a (undocumented)
Messages.print_messages is used (cf line 639, in show)

any suggestions?
I would rather not call the notmuch binary and parse its output..
Thanks!
/p
signature.asc (application/pgp-signature)

Thread: