unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [python] get all messages of a thread
@ 2011-05-28 13:18 Patrick Totzke
  2011-05-31 23:48 ` Carl Worth
  2011-06-01  5:35 ` Brian May
  0 siblings, 2 replies; 8+ messages in thread
From: Patrick Totzke @ 2011-05-28 13:18 UTC (permalink / raw)
  To: notmuch

[-- Attachment #1: Type: text/plain, Size: 1562 bytes --]

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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2011-06-02 14:38 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-05-28 13:18 [python] get all messages of a thread Patrick Totzke
2011-05-31 23:48 ` Carl Worth
2011-06-01  5:35 ` Brian May
2011-06-02  7:05   ` Sebastian Spaeth
2011-06-02  9:43     ` Brian May
2011-06-02 14:20       ` Sebastian Spaeth
2011-06-02 14:37         ` Sebastian Spaeth
2011-06-02 14:38         ` Austin Clements

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).