[PATCH 3/3] tags_to_maildir_flags: Don't rename if no flags change
authorLouis Rilling <l.rilling@av7.net>
Tue, 12 Jul 2011 13:59:50 +0000 (15:59 +0200)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:39:06 +0000 (09:39 -0800)
9b/22b286d293280bec6eca8d08c4a34237866b76 [new file with mode: 0644]

diff --git a/9b/22b286d293280bec6eca8d08c4a34237866b76 b/9b/22b286d293280bec6eca8d08c4a34237866b76
new file mode 100644 (file)
index 0000000..d7394f6
--- /dev/null
@@ -0,0 +1,130 @@
+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 B37FE431FD0\r
+       for <notmuch@notmuchmail.org>; Tue, 12 Jul 2011 07:00:35 -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 PpU7gBoijRCw for <notmuch@notmuchmail.org>;\r
+       Tue, 12 Jul 2011 07:00:34 -0700 (PDT)\r
+Received: from mail-ey0-f181.google.com (mail-ey0-f181.google.com\r
+       [209.85.215.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id C60FD429E38\r
+       for <notmuch@notmuchmail.org>; Tue, 12 Jul 2011 07:00:32 -0700 (PDT)\r
+Received: by mail-ey0-f181.google.com with SMTP id 5so1740488eyh.26\r
+       for <notmuch@notmuchmail.org>; Tue, 12 Jul 2011 07:00:32 -0700 (PDT)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma;\r
+       h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to\r
+       :references; bh=IZVJr5JgARn5FlbO2vGr36PUJ2aM1HhbFBtX0wNAidw=;\r
+       b=r2e1H/rGbagjmtJupYutinDFfTFuvewN1O+r1hqHS5BOpobRLSqfyKsthyWynXeTHx\r
+       49slllVL3VpP3XVcKCZioyE7sZG+3/acLDYR9/kyybkESfVshYV4EEPsv0jYMhKe8hPq\r
+       S8EPR17WqXQT/CO4vkH3XhEDnHcPOtp6xh7zs=\r
+Received: by 10.14.9.231 with SMTP id 79mr1746632eet.241.1310479232435;\r
+       Tue, 12 Jul 2011 07:00:32 -0700 (PDT)\r
+Received: from osdor.le-roi-du-couscous.fr ([78.222.14.116])\r
+       by mx.google.com with ESMTPS id z49sm1538190eef.33.2011.07.12.07.00.31\r
+       (version=SSLv3 cipher=OTHER); Tue, 12 Jul 2011 07:00:31 -0700 (PDT)\r
+Sender: Louis Rilling <lrilling@gmail.com>\r
+From: Louis Rilling <l.rilling@av7.net>\r
+To: Carl Worth <cworth@cworth.org>\r
+Subject: [PATCH 3/3] tags_to_maildir_flags: Don't rename if no flags change\r
+Date: Tue, 12 Jul 2011 15:59:50 +0200\r
+Message-Id: <1310479190-6973-4-git-send-email-l.rilling@av7.net>\r
+X-Mailer: git-send-email 1.7.2.5\r
+In-Reply-To: <1310479190-6973-1-git-send-email-l.rilling@av7.net>\r
+References: <1310479190-6973-1-git-send-email-l.rilling@av7.net>\r
+Cc: notmuch@notmuchmail.org, Austin Clements <amdragon@MIT.EDU>\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: Tue, 12 Jul 2011 14:00:35 -0000\r
+\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
+Changelog:\r
+* v2: Fix bool type as well as NULL returned despite having no errors (Austin\r
+      Clements)\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 b1b2942..c003729 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
++    notmuch_bool_t flags_changed = FALSE;\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 talloc_strdup (ctx, filename);\r
++\r
+     filename_new = (char *) talloc_size (ctx,\r
+                                        info - filename +\r
+                                        strlen (":2,") + flags_in_map + 1);\r
+-- \r
+1.7.2.5\r
+\r