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

diff --git a/cd/2c113a554ee1e21ad0627715252093025f3e28 b/cd/2c113a554ee1e21ad0627715252093025f3e28
new file mode 100644 (file)
index 0000000..d028d4f
--- /dev/null
@@ -0,0 +1,230 @@
+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 356DD431FBD\r
+       for <notmuch@notmuchmail.org>; Thu,  2 Feb 2012 14:26:34 -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 vZOyfN+2k5cd for <notmuch@notmuchmail.org>;\r
+       Thu,  2 Feb 2012 14:26:33 -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 15E96431FAF\r
+       for <notmuch@notmuchmail.org>; Thu,  2 Feb 2012 14:26:33 -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 1Rt56p-0008K9-Hy; Thu, 02 Feb 2012 22:26:28 +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 1Rt56p-000215-3F; Thu, 02 Feb 2012 22:26:27 +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: <87k444yk6i.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>\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 22:27:36 +0000\r
+Message-ID: <871uqcswfb.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: c06bf66a9bb8f38f50fa2995921d640d (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 22:26:34 -0000\r
+\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
+> >  /* 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
+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
+> >    _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.) 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
+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