[PATCH] Including 'unread' tag to mails without maildir flags
authormeskio <meskio@sindominio.net>
Fri, 19 Nov 2010 15:41:04 +0000 (16:41 +0100)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:37:33 +0000 (09:37 -0800)
09/c48512e124c65b558649f406b773ace74f8d22 [new file with mode: 0644]

diff --git a/09/c48512e124c65b558649f406b773ace74f8d22 b/09/c48512e124c65b558649f406b773ace74f8d22
new file mode 100644 (file)
index 0000000..850b203
--- /dev/null
@@ -0,0 +1,178 @@
+Return-Path: <meskio@noblezabaturra.org>\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 6B15240DEED\r
+       for <notmuch@notmuchmail.org>; Fri, 19 Nov 2010 07:41:22 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -1.9\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-1.9 tagged_above=-999 required=5\r
+       tests=[BAYES_00=-1.9] autolearn=ham\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 NhrncPgbpVFI for <notmuch@notmuchmail.org>;\r
+       Fri, 19 Nov 2010 07:41:10 -0800 (PST)\r
+Received: from heal.cauterized.net (heal.cauterized.net [89.140.131.167])\r
+       by olra.theworths.org (Postfix) with ESMTP id BE70A40DEEB\r
+       for <notmuch@notmuchmail.org>; Fri, 19 Nov 2010 07:41:09 -0800 (PST)\r
+Received: from localhost.localdomain (pb-d-128-141-44-147.cern.ch\r
+       [128.141.44.147])\r
+       (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
+       (No client certificate requested)\r
+       by heal.cauterized.net (Postfix) with ESMTPSA id EAD9F7024564;\r
+       Fri, 19 Nov 2010 16:41:06 +0100 (CET)\r
+From: meskio@sindominio.net\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH] Including 'unread' tag to mails without maildir flags\r
+Date: Fri, 19 Nov 2010 16:41:04 +0100\r
+Message-Id: <1290181264-5900-1-git-send-email-meskio@sindominio.net>\r
+X-Mailer: git-send-email 1.7.1\r
+In-Reply-To: <20101118153744.GE3049@blackspot>\r
+References: <20101118153744.GE3049@blackspot>\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: Fri, 19 Nov 2010 15:41:22 -0000\r
+\r
+From: Ruben Pollan <meskio@sindominio.net>\r
+\r
+Some mail fetchers, like fetchmail, leaves the email without ':2,' at the end of\r
+the filename. Notmuch didn't detect this emails as maildir, it didn't add the\r
+maildir flags to them.\r
+\r
+Now it detects if a mail is in a maildir by the directory structure, and add its\r
+maildir flags correctly.\r
+---\r
+ lib/message.cc |   87 +++++++++++++++++++++++++++++---------------------------\r
+ 1 files changed, 45 insertions(+), 42 deletions(-)\r
+\r
+diff --git a/lib/message.cc b/lib/message.cc\r
+index 225b7e9..996c1df 100644\r
+--- a/lib/message.cc\r
++++ b/lib/message.cc\r
+@@ -854,6 +854,47 @@ notmuch_message_remove_tag (notmuch_message_t *message, const char *tag)\r
+     return NOTMUCH_STATUS_SUCCESS;\r
+ }\r
\r
++/* Is the given filename within a maildir directory?\r
++ *\r
++ * Specifically, is the final directory component of 'filename' either\r
++ * "cur" or "new". If so, return a pointer to that final directory\r
++ * component within 'filename'. If not, return NULL.\r
++ *\r
++ * A non-NULL return value is guaranteed to be a valid string pointer\r
++ * pointing to the characters "new/" or "cur/", (but not\r
++ * NUL-terminated).\r
++ */\r
++static const char *\r
++_filename_is_in_maildir (const char *filename)\r
++{\r
++    const char *slash, *dir = NULL;\r
++\r
++    /* Find the last '/' separating directory from filename. */\r
++    slash = strrchr (filename, '/');\r
++    if (slash == NULL)\r
++      return NULL;\r
++\r
++    /* Jump back 4 characters to where the previous '/' will be if the\r
++     * directory is named "cur" or "new". */\r
++    if (slash - filename < 4)\r
++      return NULL;\r
++\r
++    slash -= 4;\r
++\r
++    if (*slash != '/')\r
++      return NULL;\r
++\r
++    dir = slash + 1;\r
++\r
++    if (STRNCMP_LITERAL (dir, "cur/") == 0 ||\r
++      STRNCMP_LITERAL (dir, "new/") == 0)\r
++    {\r
++      return dir;\r
++    }\r
++\r
++    return NULL;\r
++}\r
++\r
+ notmuch_status_t\r
+ notmuch_message_maildir_flags_to_tags (notmuch_message_t *message)\r
+ {\r
+@@ -871,11 +912,14 @@ notmuch_message_maildir_flags_to_tags (notmuch_message_t *message)\r
+     {\r
+       filename = notmuch_filenames_get (filenames);\r
\r
++      if (! _filename_is_in_maildir(filename))\r
++          continue;\r
++      seen_maildir_info = 1;\r
++\r
+       flags = strstr (filename, ":2,");\r
+       if (! flags)\r
+           continue;\r
\r
+-      seen_maildir_info = 1;\r
+       flags += 3;\r
\r
+       combined_flags = talloc_strdup_append (combined_flags, flags);\r
+@@ -910,47 +954,6 @@ notmuch_message_maildir_flags_to_tags (notmuch_message_t *message)\r
+     return status;\r
+ }\r
\r
+-/* Is the given filename within a maildir directory?\r
+- *\r
+- * Specifically, is the final directory component of 'filename' either\r
+- * "cur" or "new". If so, return a pointer to that final directory\r
+- * component within 'filename'. If not, return NULL.\r
+- *\r
+- * A non-NULL return value is guaranteed to be a valid string pointer\r
+- * pointing to the characters "new/" or "cur/", (but not\r
+- * NUL-terminated).\r
+- */\r
+-static const char *\r
+-_filename_is_in_maildir (const char *filename)\r
+-{\r
+-    const char *slash, *dir = NULL;\r
+-\r
+-    /* Find the last '/' separating directory from filename. */\r
+-    slash = strrchr (filename, '/');\r
+-    if (slash == NULL)\r
+-      return NULL;\r
+-\r
+-    /* Jump back 4 characters to where the previous '/' will be if the\r
+-     * directory is named "cur" or "new". */\r
+-    if (slash - filename < 4)\r
+-      return NULL;\r
+-\r
+-    slash -= 4;\r
+-\r
+-    if (*slash != '/')\r
+-      return NULL;\r
+-\r
+-    dir = slash + 1;\r
+-\r
+-    if (STRNCMP_LITERAL (dir, "cur/") == 0 ||\r
+-      STRNCMP_LITERAL (dir, "new/") == 0)\r
+-    {\r
+-      return dir;\r
+-    }\r
+-\r
+-    return NULL;\r
+-}\r
+-\r
+ /* From the set of tags on 'message' and the flag2tag table, compute a\r
+  * set of maildir-flag actions to be taken, (flags that should be\r
+  * either set or cleared).\r
+-- \r
+1.7.1\r
+\r