Re: [python] get all messages of a thread
authorBrian May <brian@microcomaustralia.com.au>
Wed, 1 Jun 2011 05:35:35 +0000 (15:35 +1000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:38:28 +0000 (09:38 -0800)
3e/cf346faee42d28cf32635b7a7ae96a4bb33696 [new file with mode: 0644]

diff --git a/3e/cf346faee42d28cf32635b7a7ae96a4bb33696 b/3e/cf346faee42d28cf32635b7a7ae96a4bb33696
new file mode 100644 (file)
index 0000000..73bb5ce
--- /dev/null
@@ -0,0 +1,147 @@
+Return-Path: <brian@microcomaustralia.com.au>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id 95727431FD0\r
+       for <notmuch@notmuchmail.org>; Tue, 31 May 2011 22:35:39 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.799\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5\r
+       tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
+       HTML_MESSAGE=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id VUTZKYIGCkoc for <notmuch@notmuchmail.org>;\r
+       Tue, 31 May 2011 22:35:37 -0700 (PDT)\r
+Received: from mail-bw0-f53.google.com (mail-bw0-f53.google.com\r
+       [209.85.214.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 4B4AB431FB6\r
+       for <notmuch@notmuchmail.org>; Tue, 31 May 2011 22:35:37 -0700 (PDT)\r
+Received: by bwg12 with SMTP id 12so4795130bwg.26\r
+       for <notmuch@notmuchmail.org>; Tue, 31 May 2011 22:35:35 -0700 (PDT)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
+       d=microcomaustralia.com.au; s=google;\r
+       h=domainkey-signature:mime-version:x-originating-ip:in-reply-to\r
+       :references:date:message-id:subject:from:to:cc:content-type;\r
+       bh=pZHC8uqvQZee5XReK4U8LuXTkm+Rz8mOwycGQf+YVbU=;\r
+       b=W5vQ+2KisPe7G7EMCuJm3mFuoJWQ9D7kkY6qPZSyDxcHAIpoRTcPCmnZ4R5YoyKm8Q\r
+       lzTbMOioVtIeDeW8q3loZGacDxfS6m63qcp3V6xuogxCAPX/P9pd36MJ0AAx4Xof6mSG\r
+       wUw1QEBRFXf5TipBA68H9O/Ez6Bayvfa09FoI=\r
+DomainKey-Signature: a=rsa-sha1; c=nofws; d=microcomaustralia.com.au;\r
+ s=google;     h=mime-version:x-originating-ip:in-reply-to:references:date\r
+       :message-id:subject:from:to:cc:content-type;\r
+       b=bnwzHsdSUwplVXB5Xy/Sjo0xx7fK9olrQDLnGSg3uPXjZQ4EdLV1Q/nqNU4WRAFx0U\r
+       3UZtOykLORTH7eI0HRP3UKQoujkkfXREdJjuRthNytoVlCYcRm6O0MxIz6cIUZvb2i/C\r
+       aYeN4KvDUn3hBeNFbHesW3bVLVd8N8FzpuBtA=\r
+MIME-Version: 1.0\r
+Received: by 10.204.172.66 with SMTP id k2mr6239203bkz.125.1306906535558; Tue,\r
+       31 May 2011 22:35:35 -0700 (PDT)\r
+Received: by 10.204.82.147 with HTTP; Tue, 31 May 2011 22:35:35 -0700 (PDT)\r
+X-Originating-IP: [128.250.103.228]\r
+In-Reply-To: <1306588052-sup-9838@brick>\r
+References: <1306588052-sup-9838@brick>\r
+Date: Wed, 1 Jun 2011 15:35:35 +1000\r
+Message-ID: <BANLkTikEJ9dJ5kLg2QJQ+egHg2sh7S1wiA@mail.gmail.com>\r
+Subject: Re: [python] get all messages of a thread\r
+From: Brian May <brian@microcomaustralia.com.au>\r
+To: Patrick Totzke <patricktotzke@googlemail.com>\r
+Content-Type: multipart/alternative; boundary=bcaec52c5c8dce7d8804a49fe3bc\r
+Cc: notmuch <notmuch@notmuchmail.org>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Wed, 01 Jun 2011 05:35:39 -0000\r
+\r
+--bcaec52c5c8dce7d8804a49fe3bc\r
+Content-Type: text/plain; charset=ISO-8859-1\r
+\r
+On 28 May 2011 23:18, Patrick Totzke <patricktotzke@googlemail.com> wrote:\r
+\r
+>    if r: #because we cant iterate on NoneType\r
+>\r
+\r
+I don't understand why, but this line sets r._msgs to None. So it crashes,\r
+because it has no message ids to look for.\r
+\r
+If you change it to\r
+\r
+if r is not None:\r
+\r
+... then it works for me.\r
+\r
+Oh, I see, for your code, there is a implied call to __len__, and the\r
+__len__ function is completely broken for the reasons described in the\r
+documentation:\r
+\r
+      .. note:: As this iterates over the messages, we will not be able to=\r
+               iterate over them again! So this will fail::\r
+\r
+                 #THIS FAILS\r
+                 msgs = Database().create_query('').search_message()\r
+                 if len(msgs) > 0:              #this 'exhausts' msgs\r
+                     # next line raises\r
+NotmuchError(STATUS.NOT_INITIALIZED)!!!\r
+                     for msg in msgs: print msg\r
+\r
+               Most of the time, using the\r
+               :meth:`Query.count_messages` is therefore more\r
+               appropriate (and much faster). While not guaranteeing\r
+               that it will return the exact same number than len(),\r
+               in my tests it effectively always did so.\r
+\r
+\r
+\r
+-- \r
+Brian May <brian@microcomaustralia.com.au>\r
+\r
+--bcaec52c5c8dce7d8804a49fe3bc\r
+Content-Type: text/html; charset=ISO-8859-1\r
+Content-Transfer-Encoding: quoted-printable\r
+\r
+<div class=3D"gmail_quote">On 28 May 2011 23:18, Patrick Totzke <span dir=\r
+=3D"ltr">&lt;<a href=3D"mailto:patricktotzke@googlemail.com">patricktotzke@=\r
+googlemail.com</a>&gt;</span> wrote:<br><blockquote class=3D"gmail_quote" s=\r
+tyle=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">\r
+=A0 =A0if r: #because we cant iterate on NoneType<br></blockquote><div><br>=\r
+</div><div>I don&#39;t understand why, but this line sets r._msgs to None. =\r
+So it crashes, because it has no message ids to look for.</div><div><br></d=\r
+iv>\r
+<div>If you change it to</div><div><br></div><div>if r is not None:</div><d=\r
+iv><br></div><div>... then it works for me.=A0</div><div><br></div><div>Oh,=\r
+ I see, for your code, there is a implied call to __len__, and the __len__ =\r
+function is completely broken for the reasons described in the documentatio=\r
+n:</div>\r
+<div><br></div><div><div>=A0 =A0 =A0 .. note:: As this iterates over the me=\r
+ssages, we will not be able to=3D</div><div>=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=\r
+iterate over them again! So this will fail::</div><div><br></div><div>=A0 =\r
+=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0#THIS FAILS</div>\r
+<div>=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0msgs =3D Database().create_query(&#=\r
+39;&#39;).search_message()</div><div>=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if =\r
+len(msgs) &gt; 0: =A0 =A0 =A0 =A0 =A0 =A0 =A0#this &#39;exhausts&#39; msgs<=\r
+/div><div>=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0# next line raises Not=\r
+muchError(STATUS.NOT_INITIALIZED)!!!</div>\r
+<div>=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0for msg in msgs: print msg<=\r
+/div><div><br></div><div>=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0Most of the time, u=\r
+sing the</div><div>=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0:meth:`Query.count_messag=\r
+es` is therefore more</div><div>=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0appropriate =\r
+(and much faster). While not guaranteeing</div>\r
+<div>=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0that it will return the exact same numb=\r
+er than len(),</div><div>=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0in my tests it effe=\r
+ctively always did so.</div></div><div><br></div><div><br></div><div><br></=\r
+div></div>-- <br>Brian May &lt;<a href=3D"mailto:brian@microcomaustralia.co=\r
+m.au">brian@microcomaustralia.com.au</a>&gt;<br>\r
+\r
+\r
+--bcaec52c5c8dce7d8804a49fe3bc--\r