Re: [PATCH v4 07/11] lib: added interface notmuch_thread_get_flag_messages
authorMark Walters <markwalters1009@gmail.com>
Thu, 2 Feb 2012 23:24:56 +0000 (23:24 +0000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:43:59 +0000 (09:43 -0800)
57/10c67f06df7547b4bff8096348fdede5a50480 [new file with mode: 0644]

diff --git a/57/10c67f06df7547b4bff8096348fdede5a50480 b/57/10c67f06df7547b4bff8096348fdede5a50480
new file mode 100644 (file)
index 0000000..b24b354
--- /dev/null
@@ -0,0 +1,260 @@
+Return-Path: <m.walters@qmul.ac.uk>\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 CEA4E431FBD\r
+       for <notmuch@notmuchmail.org>; Thu,  2 Feb 2012 15:23:50 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -1.098\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-1.098 tagged_above=-999 required=5\r
+       tests=[DKIM_ADSP_CUSTOM_MED=0.001, FREEMAIL_FROM=0.001,\r
+       NML_ADSP_CUSTOM_MED=1.2, RCVD_IN_DNSWL_MED=-2.3] 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 Uvpgz3b8l+gt for <notmuch@notmuchmail.org>;\r
+       Thu,  2 Feb 2012 15:23:49 -0800 (PST)\r
+Received: from mail2.qmul.ac.uk (mail2.qmul.ac.uk [138.37.6.6])\r
+       (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 8A9AC431FAF\r
+       for <notmuch@notmuchmail.org>; Thu,  2 Feb 2012 15:23:49 -0800 (PST)\r
+Received: from smtp.qmul.ac.uk ([138.37.6.40])\r
+       by mail2.qmul.ac.uk with esmtp (Exim 4.71)\r
+       (envelope-from <m.walters@qmul.ac.uk>)\r
+       id 1Rt60J-0002yi-Pm; Thu, 02 Feb 2012 23:23:48 +0000\r
+Received: from 94-192-233-223.zone6.bethere.co.uk ([94.192.233.223]\r
+       helo=localhost)\r
+       by smtp.qmul.ac.uk with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.69)\r
+       (envelope-from <m.walters@qmul.ac.uk>)\r
+       id 1Rt60J-0002v8-61; Thu, 02 Feb 2012 23:23:47 +0000\r
+From: Mark Walters <markwalters1009@gmail.com>\r
+To: Jani Nikula <jani@nikula.org>, notmuch@notmuchmail.org, amdragon@MIT.EDU\r
+Subject: Re: [PATCH v4 07/11] lib: added interface\r
+       notmuch_thread_get_flag_messages\r
+In-Reply-To: <87d39wygts.fsf@nikula.org>\r
+References: <874nv9rv79.fsf@qmul.ac.uk>\r
+       <1328204619-25046-7-git-send-email-markwalters1009@gmail.com>\r
+       <87k444yk6i.fsf@nikula.org> <871uqcswfb.fsf@qmul.ac.uk>\r
+       <87d39wygts.fsf@nikula.org>\r
+User-Agent: Notmuch/0.11+140~gb5e1cf0 (http://notmuchmail.org) Emacs/23.2.1\r
+       (i486-pc-linux-gnu)\r
+Date: Thu, 02 Feb 2012 23:24:56 +0000\r
+Message-ID: <87sjisrf7b.fsf@qmul.ac.uk>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\r
+X-Sender-Host-Address: 94.192.233.223\r
+X-QM-SPAM-Info: Sender has good ham record.  :)\r
+X-QM-Body-MD5: 213c140df5c652a3c95276e07c1279d6 (of first 20000 bytes)\r
+X-SpamAssassin-Score: -1.8\r
+X-SpamAssassin-SpamBar: -\r
+X-SpamAssassin-Report: The QM spam filters have analysed this message to\r
+       determine if it is\r
+       spam. We require at least 5.0 points to mark a message as spam.\r
+       This message scored -1.8 points.\r
+       Summary of the scoring: \r
+       * -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/,\r
+       *      medium trust\r
+       *      [138.37.6.40 listed in list.dnswl.org]\r
+       * 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail\r
+       provider *      (markwalters1009[at]gmail.com)\r
+       * -0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay\r
+       *      domain\r
+       *  0.5 AWL AWL: From: address is in the auto white-list\r
+X-QM-Scan-Virus: ClamAV says the message is clean\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: Thu, 02 Feb 2012 23:23:50 -0000\r
+\r
+On Fri, 03 Feb 2012 01:07:59 +0200, Jani Nikula <jani@nikula.org> wrote:\r
+> On Thu, 02 Feb 2012 22:27:36 +0000, Mark Walters <markwalters1009@gmail.com> wrote:\r
+> > On Thu, 02 Feb 2012 23:55:33 +0200, Jani Nikula <jani@nikula.org> wrote:\r
+> > > \r
+> > > Hi Mark -\r
+> > > \r
+> > > This is my first look at any version of the series; apologies if I'm\r
+> > > clueless about some details... Please find some comments below.\r
+> > > \r
+> > > BR,\r
+> > > Jani.\r
+> > > \r
+> > > \r
+> > > On Thu,  2 Feb 2012 17:43:35 +0000, Mark Walters <markwalters1009@gmail.com> wrote:\r
+> > > > The function is\r
+> > > > notmuch_thread_get_flag_messages\r
+> > > > (notmuch_thread_t *thread, unsigned int flag_mask, unsigned int flags)\r
+> > > > \r
+> > > > and returns the number of messages with the specified flags on flag_mask.\r
+> > > \r
+> > > Is the purpose of this function to get the count of messages that have\r
+> > > certain flags set, certain flags not set, and certain flags don't-care?\r
+> > \r
+> > Yes: I was trying to follow Austin's suggestion from\r
+> > id:"20120124025331.GZ16740@mit.edu" (although stupidly I didn't\r
+> > follow his suggestion of a function name).\r
+> > \r
+> > > At the very least, I think the documentation of the function should be\r
+> > > greatly improved.\r
+> > > \r
+> > > I think the name of the function should be notmuch_thread_count_messages\r
+> > > which is like notmuch_query_count_messages, but for messages in threads\r
+> > > (and with some extra restrictions).\r
+> > \r
+> > Yes I like your name; before I change it do you (and others) prefer it\r
+> > to Austin's suggestion of notmuch_thread_count_flags. Or we could even\r
+> > be more verbose with something like\r
+> > notmuch_thread_count_messages_with_flags\r
+> \r
+> I'd like to make it clear that it's about message count. Not about\r
+> getting flags, not about flag counts. _with_flags is a matter of taste,\r
+> no strong opinions there.\r
+\r
+I think I will go with notmuch_thread_count_messages as you suggest.\r
+\r
+> > > >  /* Message flags */\r
+> > > >  typedef enum _notmuch_message_flag {\r
+> > > > -    NOTMUCH_MESSAGE_FLAG_MATCH,\r
+> > > > -    NOTMUCH_MESSAGE_FLAG_EXCLUDED\r
+> > > > +    NOTMUCH_MESSAGE_FLAG_MATCH = (1<<0),\r
+> > > > +    NOTMUCH_MESSAGE_FLAG_EXCLUDED = (1<<1),\r
+> > > > +    NOTMUCH_MESSAGE_FLAG_MAX  = (1<<2)\r
+> > > \r
+> > > How are these used by the current lib users at the moment? How will they\r
+> > > break with this change?\r
+\r
+I will just comment on this: the *only* reason I put in\r
+NOTMUCH_MESSAGE_FLAG_MAX was as a way of keeping track of the size of\r
+the bitfield. If there is a better way do say!\r
+\r
+> > The only existing flag is NOTMUCH_MESSAGE_FLAG_MATCH: that is currently\r
+> > zero but in the current code that is the bit offset of the flag; in my\r
+> > version it is the actual bit for the flag (otherwise I think flag masks\r
+> > end up very ugly). I believe all callers use notmuch_message_set_flag\r
+> > and notmuch_message_get_flag so they should not notice the difference.\r
+> > \r
+> > > Please align the assignments. \r
+> > \r
+> > Will do.\r
+> > \r
+> > > > @@ -457,8 +452,8 @@ _notmuch_thread_create (void *ctx,\r
+> > > >      thread->message_hash = g_hash_table_new_full (g_str_hash, g_str_equal,\r
+> > > >                                                  free, NULL);\r
+> > > >  \r
+> > > > -    thread->total_messages = 0;\r
+> > > > -    thread->matched_messages = 0;\r
+> > > > +    for (i = 0; i < NOTMUCH_MESSAGE_FLAG_MAX; i++)\r
+> > > > +      thread->flag_count_messages[i] = 0;\r
+> > > \r
+> > > memset (thread->flag_count_messages, 0, sizeof(thread->flag_count_messages));\r
+> > \r
+> > \r
+> > Will do \r
+> > \r
+> > > >      thread->oldest = 0;\r
+> > > >      thread->newest = 0;\r
+> > > >  \r
+> > > > @@ -473,6 +468,7 @@ _notmuch_thread_create (void *ctx,\r
+> > > >         notmuch_messages_move_to_next (messages))\r
+> > > >      {\r
+> > > >        unsigned int doc_id;\r
+> > > > +      unsigned int message_flags;\r
+> > > >  \r
+> > > >        message = notmuch_messages_get (messages);\r
+> > > >        doc_id = _notmuch_message_get_doc_id (message);\r
+> > > > @@ -485,6 +481,10 @@ _notmuch_thread_create (void *ctx,\r
+> > > >            _notmuch_doc_id_set_remove (match_set, doc_id);\r
+> > > >            _thread_add_matched_message (thread, message, sort);\r
+> > > >        }\r
+> > > > +      message_flags =\r
+> > > > +          notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_MATCH) |\r
+> > > > +          notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_EXCLUDED);\r
+> > > > +      thread->flag_count_messages[message_flags]++;\r
+> > > \r
+> > > The first impression of using a set of flags as index is that there's a\r
+> > > bug. But this is to keep count of messages with certain flag sets rather\r
+> > > than total for each flag, right? I think this needs more comments, more\r
+> > > documentation. Already naming the field flag_set_message_counts or\r
+> > > similar would help greatly.\r
+> > \r
+> > I will try and document it better: on first reading I parsed your name\r
+> > as flag set (as verb) message counts whereas I assume you mean "flag\r
+> > set" as a noun! I will see if I can come up with something though.\r
+> \r
+> Yes, as a noun! :)\r
+\r
+I haven't come up with a good name: the best I have come up with is\r
+flagset_message_count so if you have any suggestions...\r
+\r
+> > > >        _notmuch_message_close (message);\r
+> > > >      }\r
+> > > > @@ -511,15 +511,28 @@ notmuch_thread_get_thread_id (notmuch_thread_t *thread)\r
+> > > >  }\r
+> > > >  \r
+> > > >  int\r
+> > > > +notmuch_thread_get_flag_messages (notmuch_thread_t *thread, unsigned int flag_mask, unsigned int flags)\r
+> > > > +{\r
+> > > > +    unsigned int i;\r
+> > > > +    int count = 0;\r
+> > > > +    for (i = 0; i < NOTMUCH_MESSAGE_FLAG_MAX; i++)\r
+> > > \r
+> > > ARRAY_SIZE (thread->flag_count_messages)\r
+> > \r
+> > ok\r
+> > \r
+> > > \r
+> > > > +      if ((i & flag_mask) == (flags & flag_mask))\r
+> > > > +          count += thread->flag_count_messages[i];\r
+> > > > +    return count;\r
+> > > > +}\r
+> > > \r
+> > > I wonder if the same could be accomplished by using two flag mask\r
+> > > parameters, include_flag_mask and exclude_flag_mask. I'm thinking of the\r
+> > > usage, would it be easier to use:\r
+> > > \r
+> > > notmuch_query_count_messages (thread, NOTMUCH_MESSAGE_FLAG_MATCH, NOTMUCH_MESSAGE_FLAG_EXCLUDED);\r
+> > > \r
+> > > to get number of messages that have MATCH but not EXCLUDED? 0 as\r
+> > > include_flag_mask could still be special for "all", and you could use:\r
+> > > \r
+> > > notmuch_query_count_messages (thread, 0, NOTMUCH_MESSAGE_FLAG_EXCLUDED);\r
+> > > \r
+> > > Note the name change according to my earlier suggestion. It might be\r
+> > > wise to not export the function before the API is chrystal clear if\r
+> > > there is no pressing need to do so.\r
+> > \r
+> > (I assume you mean notmuch_thread_count_messages.)\r
+> \r
+> Doh! Yes.\r
+> \r
+> > Can I just check this\r
+> > would return the number of messages which have all the flags  in\r
+> > include_flag_mask and none of the flags in exclude_flag_mask?\r
+\r
+Yes I think this works better: these are the flags I want, these are the\r
+ones I don't want seems natural (versus here are the ones I care about\r
+and here are the ones of those I want). But I will wait to see if anyone\r
+else has an opinion.\r
+\r
+> Yes, but only if it makes sense to you! :)\r
+> \r
+> > \r
+> > I completely agree about leaving it until we have the API well worked\r
+> > out. I wrote it in response to Austin's suggestion and then it looked\r
+> > like it would useful in my attempts to remove the\r
+> > notmuch_query_set_omit_excluded_messages API. However, those attempts\r
+> > failed so it doesn't have any users yet.\r
+> > \r
+> > Best wishes\r
+> > \r
+> > Mark\r