[notmuch] [PATCH] notmuch-new: Test if directory looks like Maildir before skipping...
authorJan Janak <jan@ryngle.com>
Wed, 25 Nov 2009 21:11:45 +0000 (22:11 +0100)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:35:43 +0000 (09:35 -0800)
6a/fb1b366f9f4774aa7fbd995d7b6d1aaebadf7a [new file with mode: 0644]

diff --git a/6a/fb1b366f9f4774aa7fbd995d7b6d1aaebadf7a b/6a/fb1b366f9f4774aa7fbd995d7b6d1aaebadf7a
new file mode 100644 (file)
index 0000000..78c4edf
--- /dev/null
@@ -0,0 +1,116 @@
+Return-Path: <jan@ryngle.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 0641B431FBC\r
+       for <notmuch@notmuchmail.org>; Wed, 25 Nov 2009 13:11:52 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\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 QanLcv70ysoJ for <notmuch@notmuchmail.org>;\r
+       Wed, 25 Nov 2009 13:11:51 -0800 (PST)\r
+Received: from mail-ew0-f213.google.com (mail-ew0-f213.google.com\r
+       [209.85.219.213])\r
+       by olra.theworths.org (Postfix) with ESMTP id 3D355431FAE\r
+       for <notmuch@notmuchmail.org>; Wed, 25 Nov 2009 13:11:51 -0800 (PST)\r
+Received: by ewy5 with SMTP id 5so132569ewy.30\r
+       for <notmuch@notmuchmail.org>; Wed, 25 Nov 2009 13:11:50 -0800 (PST)\r
+Received: by 10.213.1.7 with SMTP id 7mr7115660ebd.27.1259183507974;\r
+       Wed, 25 Nov 2009 13:11:47 -0800 (PST)\r
+Received: from x61s.janakj ([213.192.30.141])\r
+       by mx.google.com with ESMTPS id 7sm225193eyb.42.2009.11.25.13.11.46\r
+       (version=TLSv1/SSLv3 cipher=RC4-MD5);\r
+       Wed, 25 Nov 2009 13:11:47 -0800 (PST)\r
+Received: by x61s.janakj (Postfix, from userid 1000)\r
+       id 8140C440655; Wed, 25 Nov 2009 22:11:45 +0100 (CET)\r
+From: Jan Janak <jan@ryngle.com>\r
+To: notmuch@notmuchmail.org\r
+Date: Wed, 25 Nov 2009 22:11:45 +0100\r
+Message-Id: <1259183505-30840-1-git-send-email-jan@ryngle.com>\r
+X-Mailer: git-send-email 1.6.3.3\r
+In-Reply-To: <1259178195-30324-1-git-send-email-jan@ryngle.com>\r
+References: <1259178195-30324-1-git-send-email-jan@ryngle.com>\r
+Subject: [notmuch] [PATCH] notmuch-new: Test if directory looks like Maildir\r
+       before skipping tmp.\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.12\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: Wed, 25 Nov 2009 21:11:52 -0000\r
+\r
+'notmuch new' skips directory entries with the name 'tmp'. This is to\r
+prevent notmuch from processing possibly incomplete Maildir messages\r
+stored in that directory.\r
+\r
+This patch attempts to refine the feature. If "tmp" entry is found,\r
+it first checks if the containing directory looks like a Maildir\r
+directory. This is done by searching for other common Maildir\r
+subdirectories. If they exist and if the entry "tmp" is a directory\r
+then it is skipped.\r
+\r
+Files and subdirectories with the name "tmp" that do not look like\r
+Maildir will still be processed by 'notmuch new'.\r
+\r
+Signed-off-by: Jan Janak <jan@ryngle.com>\r
+---\r
+ notmuch-new.c |   29 ++++++++++++++++++++++++++++-\r
+ 1 files changed, 28 insertions(+), 1 deletions(-)\r
+\r
+diff --git a/notmuch-new.c b/notmuch-new.c\r
+index e32b92a..10dc72b 100644\r
+--- a/notmuch-new.c\r
++++ b/notmuch-new.c\r
+@@ -80,6 +80,31 @@ static int ino_cmp(const struct dirent **a, const struct dirent **b)\r
+     return ((*a)->d_ino < (*b)->d_ino) ? -1 : 1;\r
+ }\r
\r
++/* Test if the directory looks like a Maildir directory.\r
++ *\r
++ * Search through the array of directory entries to see if we can find all\r
++ * three subdirectories typical for Maildir, that is "new", "cur", and "tmp".\r
++ *\r
++ * Return 1 if the directory looks like a Maildir and 0 otherwise.\r
++ */\r
++static int is_maildir (struct dirent **entries, int count)\r
++{\r
++    int i, found = 0;\r
++\r
++    for (i = 0; i < count; i++) {\r
++      if (entries[i]->d_type != DT_DIR) continue;\r
++      if (strcmp(entries[i]->d_name, "new") == 0 ||\r
++          strcmp(entries[i]->d_name, "cur") == 0 ||\r
++          strcmp(entries[i]->d_name, "tmp") == 0)\r
++      {\r
++          found++;\r
++          if (found == 3) return 1;\r
++      }\r
++    }\r
++\r
++    return 0;\r
++}\r
++\r
+ /* Examine 'path' recursively as follows:\r
+  *\r
+  *   o Ask the filesystem for the mtime of 'path' (path_mtime)\r
+@@ -159,7 +184,9 @@ add_files_recursive (notmuch_database_t *notmuch,\r
+        * user specify files to be ignored. */\r
+       if (strcmp (entry->d_name, ".") == 0 ||\r
+           strcmp (entry->d_name, "..") == 0 ||\r
+-          strcmp (entry->d_name, "tmp") == 0 ||\r
++          (entry->d_type == DT_DIR &&\r
++           (strcmp (entry->d_name, "tmp") == 0) &&\r
++           is_maildir (namelist, num_entries)) ||\r
+           strcmp (entry->d_name, ".notmuch") ==0)\r
+       {\r
+           continue;\r
+-- \r
+1.6.3.3\r
+\r