Re: [feature request] emacs: use `notmuch insert` for FCC
[notmuch-archives.git] / a1 / 3e3c74ac06dfaee079f5f19b496d0aa1d175c5
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 E71C2429E50\r
6         for <notmuch@notmuchmail.org>; Wed, 21 Dec 2011 05:15:31 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 0.001\r
10 X-Spam-Level: \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 47dOUTYycNOW for <notmuch@notmuchmail.org>;\r
16         Wed, 21 Dec 2011 05:15:31 -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 39490429E49\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 7AC7D510349\r
26         for <notmuch@notmuchmail.org>; Wed, 21 Dec 2011 14:15:29 +0100 (CET)\r
27 Received: by mail.jade-hamburg.de (Postfix, from userid 401)\r
28         id C01F8DF2A3; Wed, 21 Dec 2011 14:15:28 +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 C9B08DF2A0;\r
34         Wed, 21 Dec 2011 14:15:20 +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 1RdM0t-00033X-S3; Wed, 21 Dec 2011 14:15:19 +0100\r
38 From: Justus Winter <4winter@informatik.uni-hamburg.de>\r
39 To: notmuch@notmuchmail.org\r
40 Subject: [PATCH 2/2] python: make the result of Message.get_replies() more\r
41         pythonic\r
42 Date: Wed, 21 Dec 2011 14:15:02 +0100\r
43 Message-Id:\r
44  <1324473302-10869-3-git-send-email-4winter@informatik.uni-hamburg.de>\r
45 X-Mailer: git-send-email 1.7.7.3\r
46 In-Reply-To:\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
52 Precedence: list\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
63 \r
64 Formerly Message.get_replies() returned an iterator or None forcing\r
65 users to check the result before iterating over it leading to strange\r
66 looking code at the call site.\r
67 \r
68 Fix this flaw by adding an EmptyMessagesResult class that behaves like\r
69 the Messages class but immediatly raises StopIteration if used as an\r
70 iterator and returning objects of this type from Message.get_replies()\r
71 to indicate that there are no replies.\r
72 ---\r
73  bindings/python/notmuch/message.py |   22 +++++++++++++++-------\r
74  1 files changed, 15 insertions(+), 7 deletions(-)\r
75 \r
76 diff --git a/bindings/python/notmuch/message.py b/bindings/python/notmuch/message.py\r
77 index cc9fc2a..975db1c 100644\r
78 --- a/bindings/python/notmuch/message.py\r
79 +++ b/bindings/python/notmuch/message.py\r
80 @@ -232,10 +232,10 @@ class Messages(object):\r
81                  next_indent = indent + 1\r
82  \r
83              # get replies and print them also out (if there are any)\r
84 -            replies = msg.get_replies()\r
85 -            if not replies is None:\r
86 +            replies = msg.get_replies().format_messages(format, next_indent, entire_thread)\r
87 +            if replies:\r
88                  result.append(set_sep)\r
89 -                result.extend(replies.format_messages(format, next_indent, entire_thread))\r
90 +                result.extend(replies)\r
91  \r
92              result.append(set_end)\r
93          result.append(set_end)\r
94 @@ -253,6 +253,15 @@ class Messages(object):\r
95          """\r
96          handle.write(''.join(self.format_messages(format, indent, entire_thread)))\r
97  \r
98 +class EmptyMessagesResult(Messages):\r
99 +    def __init__(self, parent):\r
100 +        self._msgs = None\r
101 +        self._parent = parent\r
102 +\r
103 +    def __next__(self):\r
104 +        raise StopIteration()\r
105 +    next = __next__\r
106 +\r
107  class Message(object):\r
108      """Represents a single Email message\r
109  \r
110 @@ -383,10 +392,9 @@ class Message(object):\r
111              number of subsequent calls to :meth:`get_replies`). If this message\r
112              was obtained through some non-thread means, (such as by a call to\r
113              :meth:`Query.search_messages`), then this function will return\r
114 -            `None`.\r
115 +            an empty Messages iterator.\r
116  \r
117 -        :returns: :class:`Messages` or `None` if there are no replies to\r
118 -            this message.\r
119 +        :returns: :class:`Messages`.\r
120          :exception: :exc:`NotmuchError` STATUS.NOT_INITIALIZED if the message\r
121                      is not initialized.\r
122          """\r
123 @@ -396,7 +404,7 @@ class Message(object):\r
124          msgs_p = Message._get_replies(self._msg)\r
125  \r
126          if msgs_p is None:\r
127 -            return None\r
128 +            return EmptyMessagesResult(self)\r
129  \r
130          return Messages(msgs_p, self)\r
131  \r
132 -- \r
133 1.7.7.3\r
134 \r