1 Return-Path: <teythoon@jade-hamburg.de>
\r
2 X-Original-To: notmuch@notmuchmail.org
\r
3 Delivered-To: notmuch@notmuchmail.org
\r
4 Received: from localhost (localhost [127.0.0.1])
\r
5 by olra.theworths.org (Postfix) with ESMTP id 83D59429E49
\r
6 for <notmuch@notmuchmail.org>; Wed, 21 Dec 2011 05:15:32 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=0.001 tagged_above=-999 required=5
\r
12 tests=[UNPARSEABLE_RELAY=0.001] autolearn=disabled
\r
13 Received: from olra.theworths.org ([127.0.0.1])
\r
14 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
15 with ESMTP id rSLoOzEkR-Gj for <notmuch@notmuchmail.org>;
\r
16 Wed, 21 Dec 2011 05:15:32 -0800 (PST)
\r
17 Received: from mail.cryptobitch.de (cryptobitch.de [88.198.7.68])
\r
18 (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits))
\r
19 (No client certificate requested)
\r
20 by olra.theworths.org (Postfix) with ESMTPS id 83817429E4E
\r
21 for <notmuch@notmuchmail.org>; Wed, 21 Dec 2011 05:15:31 -0800 (PST)
\r
22 Received: from mail.jade-hamburg.de (unknown [85.183.11.228])
\r
23 (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits))
\r
24 (No client certificate requested)
\r
25 by mail.cryptobitch.de (Postfix) with ESMTPSA id 54B895102BE
\r
26 for <notmuch@notmuchmail.org>; Wed, 21 Dec 2011 14:15:30 +0100 (CET)
\r
27 Received: by mail.jade-hamburg.de (Postfix, from userid 401)
\r
28 id C7EA8DF2A1; Wed, 21 Dec 2011 14:15:29 +0100 (CET)
\r
29 Received: from thinkbox.jade-hamburg.de (unknown
\r
30 [IPv6:fe80::216:d3ff:fe3e:5058%br0])
\r
31 (using TLSv1 with cipher AES256-SHA (256/256 bits))
\r
32 (No client certificate requested) (Authenticated sender: teythoon)
\r
33 by mail.jade-hamburg.de (Postfix) with ESMTPSA id C74DBDF29F;
\r
34 Wed, 21 Dec 2011 14:15:18 +0100 (CET)
\r
35 Received: from teythoon by thinkbox.jade-hamburg.de with local (Exim 4.77)
\r
36 (envelope-from <teythoon@thinkbox.jade-hamburg.de>)
\r
37 id 1RdM0r-00033S-Uh; Wed, 21 Dec 2011 14:15:18 +0100
\r
38 From: Justus Winter <4winter@informatik.uni-hamburg.de>
\r
39 To: notmuch@notmuchmail.org
\r
40 Subject: [PATCH 1/2] python: refactor print_messages into format_messages and
\r
42 Date: Wed, 21 Dec 2011 14:15:01 +0100
\r
44 <1324473302-10869-2-git-send-email-4winter@informatik.uni-hamburg.de>
\r
45 X-Mailer: git-send-email 1.7.7.3
\r
47 <1324473302-10869-1-git-send-email-4winter@informatik.uni-hamburg.de>
\r
48 References: <87sjm79e3d.fsf@SSpaeth.de>
\r
49 <1324473302-10869-1-git-send-email-4winter@informatik.uni-hamburg.de>
\r
50 X-BeenThere: notmuch@notmuchmail.org
\r
51 X-Mailman-Version: 2.1.13
\r
53 List-Id: "Use and development of the notmuch mail system."
\r
54 <notmuch.notmuchmail.org>
\r
55 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
56 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
57 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
58 List-Post: <mailto:notmuch@notmuchmail.org>
\r
59 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
60 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
61 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
62 X-List-Received-Date: Wed, 21 Dec 2011 13:15:32 -0000
\r
65 bindings/python/notmuch/message.py | 37 +++++++++++++++++++++++++----------
\r
66 1 files changed, 26 insertions(+), 11 deletions(-)
\r
68 diff --git a/bindings/python/notmuch/message.py b/bindings/python/notmuch/message.py
\r
69 index ce8e718..cc9fc2a 100644
\r
70 --- a/bindings/python/notmuch/message.py
\r
71 +++ b/bindings/python/notmuch/message.py
\r
72 @@ -186,14 +186,17 @@ class Messages(object):
\r
73 if self._msgs is not None:
\r
74 self._destroy(self._msgs)
\r
76 - def print_messages(self, format, indent=0, entire_thread=False):
\r
77 - """Outputs messages as needed for 'notmuch show' to sys.stdout
\r
78 + def format_messages(self, format, indent=0, entire_thread=False):
\r
79 + """Formats messages as needed for 'notmuch show'.
\r
81 :param format: A string of either 'text' or 'json'.
\r
82 :param indent: A number indicating the reply depth of these messages.
\r
83 :param entire_thread: A bool, indicating whether we want to output
\r
84 whole threads or only the matching messages.
\r
85 + :return: a list of lines
\r
89 if format.lower() == "text":
\r
92 @@ -207,36 +210,48 @@ class Messages(object):
\r
96 - sys.stdout.write(set_start)
\r
97 + result.append(set_start)
\r
99 # iterate through all toplevel messages in this thread
\r
104 - sys.stdout.write(set_sep)
\r
105 + result.append(set_sep)
\r
108 - sys.stdout.write(set_start)
\r
109 + result.append(set_start)
\r
110 match = msg.is_match()
\r
111 next_indent = indent
\r
113 if (match or entire_thread):
\r
114 if format.lower() == "text":
\r
115 - sys.stdout.write(msg.format_message_as_text(indent))
\r
116 + result.append(msg.format_message_as_text(indent))
\r
118 - sys.stdout.write(msg.format_message_as_json(indent))
\r
119 + result.append(msg.format_message_as_json(indent))
\r
120 next_indent = indent + 1
\r
122 # get replies and print them also out (if there are any)
\r
123 replies = msg.get_replies()
\r
124 if not replies is None:
\r
125 - sys.stdout.write(set_sep)
\r
126 - replies.print_messages(format, next_indent, entire_thread)
\r
127 + result.append(set_sep)
\r
128 + result.extend(replies.format_messages(format, next_indent, entire_thread))
\r
130 + result.append(set_end)
\r
131 + result.append(set_end)
\r
133 - sys.stdout.write(set_end)
\r
134 - sys.stdout.write(set_end)
\r
137 + def print_messages(self, format, indent=0, entire_thread=False, handle=sys.stdout):
\r
138 + """Outputs messages as needed for 'notmuch show' to a file like object.
\r
140 + :param format: A string of either 'text' or 'json'.
\r
141 + :param handle: A file like object to print to (default is sys.stdout).
\r
142 + :param indent: A number indicating the reply depth of these messages.
\r
143 + :param entire_thread: A bool, indicating whether we want to output
\r
144 + whole threads or only the matching messages.
\r
146 + handle.write(''.join(self.format_messages(format, indent, entire_thread)))
\r
148 class Message(object):
\r
149 """Represents a single Email message
\r