Re: [PATCH 2/2] tags_to_maildir_flags: Don't rename if no flags change
authorLouis Rilling <l.rilling@av7.net>
Mon, 11 Jul 2011 22:38:05 +0000 (00:38 +0200)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:39:05 +0000 (09:39 -0800)
be/e4094ca49f7ece279b534a2109c80d39a70549 [new file with mode: 0644]

diff --git a/be/e4094ca49f7ece279b534a2109c80d39a70549 b/be/e4094ca49f7ece279b534a2109c80d39a70549
new file mode 100644 (file)
index 0000000..d861b4a
--- /dev/null
@@ -0,0 +1,174 @@
+Return-Path: <lrilling@gmail.com>\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 1B582431FD0\r
+       for <notmuch@notmuchmail.org>; Mon, 11 Jul 2011 15:38:16 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.699\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.699 tagged_above=-999 required=5\r
+       tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, FREEMAIL_FROM=0.001,\r
+       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 FSqPRRj03bqk for <notmuch@notmuchmail.org>;\r
+       Mon, 11 Jul 2011 15:38:14 -0700 (PDT)\r
+Received: from mail-fx0-f46.google.com (mail-fx0-f46.google.com\r
+       [209.85.161.46]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 28D06431FB6\r
+       for <notmuch@notmuchmail.org>; Mon, 11 Jul 2011 15:38:14 -0700 (PDT)\r
+Received: by fxh19 with SMTP id 19so4426485fxh.19\r
+       for <notmuch@notmuchmail.org>; Mon, 11 Jul 2011 15:38:12 -0700 (PDT)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma;\r
+       h=sender:date:from:to:cc:subject:message-id:references:mime-version\r
+       :content-type:content-disposition:in-reply-to:user-agent;\r
+       bh=IoB5MKBF3FvQ39ci8MYqNHzjj3scSlKTtGIgeQ583/Q=;\r
+       b=Yrj/6ZmW3SledT0IfLEcaPFiNynuhwcMbBa2ObayyINZlpCKSboSQgviDFEk45Scoz\r
+       mJJMfqC/4Wajq/dRULd1l2jGTDB/icZNVjplz3pQ+XrtuUkaEjMqKOyQte2aJvaKBHje\r
+       p7j0QPA0uwbC5Slg6ehypYxOYAJ1XwkMFhU+E=\r
+Received: by 10.223.68.22 with SMTP id t22mr8251046fai.145.1310423892619;\r
+       Mon, 11 Jul 2011 15:38:12 -0700 (PDT)\r
+Received: from localdomain ([78.222.14.116])\r
+       by mx.google.com with ESMTPS id f15sm8360242fai.46.2011.07.11.15.38.11\r
+       (version=SSLv3 cipher=OTHER); Mon, 11 Jul 2011 15:38:11 -0700 (PDT)\r
+Sender: Louis Rilling <lrilling@gmail.com>\r
+Date: Tue, 12 Jul 2011 00:38:05 +0200\r
+From: Louis Rilling <l.rilling@av7.net>\r
+To: Austin Clements <amdragon@MIT.EDU>\r
+Subject: Re: [PATCH 2/2] tags_to_maildir_flags: Don't rename if no flags\r
+ change\r
+Message-ID: <20110711223805.GC3583@localdomain>\r
+References: <87d3hzgemi.fsf@yoom.home.cworth.org>\r
+       <1310394978-11883-3-git-send-email-l.rilling@av7.net>\r
+       <20110711200712.GB25558@mit.edu>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\r
+Content-Disposition: inline\r
+In-Reply-To: <20110711200712.GB25558@mit.edu>\r
+User-Agent: Mutt/1.5.20 (2009-06-14)\r
+Cc: 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: Mon, 11 Jul 2011 22:38:16 -0000\r
+\r
+On 11/07/11 16:07 -0400, Austin Clements wrote:\r
+> I worry that this may compound the confusion caused by mutt's handling\r
+> of the new flag, but I suppose people aren't likely to manipulate any\r
+> of the other maildir-synchronized flags without also marking the\r
+> message as seen.\r
+\r
+Even if they don't mark the message as seen, any flag changed would move the message to cur/. The only buggy behavior would be from mutt, with the bug you mentioned about mutt putting messages with flags back to new/.\r
+\r
+> At any rate, the change is certainly correct\r
+> technically.  A few nits below.\r
+\r
+They should be addressed by the follow-up patch. Just a comment below.\r
+\r
+> \r
+> Quoth Louis Rilling on Jul 11 at  4:36 pm:\r
+> > notmuch_message_tags_to_maildir_flags() unconditionally moves messages from\r
+> > maildir directory "new/" to maildir directory "cur/", which makes messages lose\r
+> > their "new" status in the MUA. However some users want to keep this "new"\r
+> > status after, for instance, an auto-tagging of new messages.\r
+> > \r
+> > However, as Austin mentioned and according to the maildir specification,\r
+> > messages living in "new/" are not allowed to have flags, even if mutt allows it\r
+> > to happen. For this reason, this patch prevents moving messages from "new/" to\r
+> > "cur/", only if no flags have to be changed. It's hopefully enough to satisfy\r
+> > mutt (and maybe other MUAs showing the "new" status) users checking the "new"\r
+> > status.\r
+> > \r
+> > Signed-off-by: Louis Rilling <l.rilling@av7.net>\r
+> > ---\r
+> >  lib/message.cc |   12 +++++++++++-\r
+> >  1 files changed, 11 insertions(+), 1 deletions(-)\r
+> > \r
+> > diff --git a/lib/message.cc b/lib/message.cc\r
+> > index 64b6cf8..131d99b 100644\r
+> > --- a/lib/message.cc\r
+> > +++ b/lib/message.cc\r
+> > @@ -1139,7 +1139,7 @@ _get_maildir_flag_actions (notmuch_message_t *message,\r
+> >   * compute the new maildir filename.\r
+> >   *\r
+> >   * If the existing filename is in the directory "new", the new\r
+> > - * filename will be in the directory "cur".\r
+> > + * filename will be in the directory "cur", unless no flags are changed.\r
+> >   *\r
+> >   * After a sequence of ":2," in the filename, any subsequent\r
+> >   * single-character flags will be added or removed according to the\r
+> > @@ -1162,6 +1162,7 @@ _new_maildir_filename (void *ctx,\r
+> >      char *filename_new, *dir;\r
+> >      char flag_map[128];\r
+> >      int flags_in_map = 0;\r
+> > +    bool flags_changed = false;\r
+> \r
+> The convention in notmuch is to use notmuch_bool_t, TRUE, and FALSE\r
+> (though, admittedly, I don't know why; avoiding C99-isms?)\r
+\r
+And bool is already used at another place in message.cc:\r
+\r
+       struct maildir_flag_tag {\r
+           char flag;\r
+           const char *tag;\r
+           bool inverse;\r
+       };\r
+\r
+IIUC it should be changed to notmuch_bool_t too.\r
+\r
+> \r
+> >      unsigned int i;\r
+> >      char *s;\r
+> >  \r
+> > @@ -1202,6 +1203,7 @@ _new_maildir_filename (void *ctx,\r
+> >    if (flag_map[flag] == 0) {\r
+> >        flag_map[flag] = 1;\r
+> >        flags_in_map++;\r
+> > +      flags_changed = true;\r
+> >    }\r
+> >      }\r
+> >  \r
+> > @@ -1210,9 +1212,17 @@ _new_maildir_filename (void *ctx,\r
+> >    if (flag_map[flag]) {\r
+> >        flag_map[flag] = 0;\r
+> >        flags_in_map--;\r
+> > +      flags_changed = true;\r
+> >    }\r
+> >      }\r
+> >  \r
+> > +    /* No need to rename. Messages in new/ can be kept in new/.\r
+> > +     * Note: We don't even try to fix buggy messages having flags and living in\r
+> > +     * new/. It's not our business.\r
+> > +     */\r
+> > +    if (!flags_changed)\r
+> > +  return NULL;\r
+> > +\r
+> \r
+> NULL generally indicates an error in notmuch and is currently used\r
+> that way in _new_maildir_filename, so even though the caller currently\r
+> doesn't really care, I'd lean against overloading it to indicate that\r
+> the filename doesn't need to change.  Despite the slight inefficiency,\r
+> I would recommend returning talloc_strdup (ctx, filename).\r
+\r
+Ok.\r
+\r
+Thanks,\r
+\r
+Louis\r
+\r
+> \r
+> >      filename_new = (char *) talloc_size (ctx,\r
+> >                                     info - filename +\r
+> >                                     strlen (":2,") + flags_in_map + 1);\r