Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 0F189431FBC for ; Wed, 25 Nov 2009 11:43:25 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id CYVJ5MPfqnTr for ; Wed, 25 Nov 2009 11:43:22 -0800 (PST) Received: from mail-ew0-f213.google.com (mail-ew0-f213.google.com [209.85.219.213]) by olra.theworths.org (Postfix) with ESMTP id 08280431FAE for ; Wed, 25 Nov 2009 11:43:21 -0800 (PST) Received: by ewy5 with SMTP id 5so40973ewy.30 for ; Wed, 25 Nov 2009 11:43:21 -0800 (PST) Received: by 10.213.1.5 with SMTP id 5mr8475979ebd.9.1259178200376; Wed, 25 Nov 2009 11:43:20 -0800 (PST) Received: from x61s.janakj ([213.192.30.141]) by mx.google.com with ESMTPS id 23sm138356eya.11.2009.11.25.11.43.19 (version=TLSv1/SSLv3 cipher=RC4-MD5); Wed, 25 Nov 2009 11:43:19 -0800 (PST) Received: by x61s.janakj (Postfix, from userid 1000) id D2EE6440655; Wed, 25 Nov 2009 20:43:15 +0100 (CET) From: Jan Janak To: notmuch@notmuchmail.org Date: Wed, 25 Nov 2009 20:43:15 +0100 Message-Id: <1259178195-30324-1-git-send-email-jan@ryngle.com> X-Mailer: git-send-email 1.6.3.3 Subject: [notmuch] [PATCH] notmuch-new: Test if directory looks like Maildir before skipping tmp. X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 25 Nov 2009 19:43:25 -0000 'notmuch new' skips directory entries with the name 'tmp'. This is to prevent notmuch from processing possibly incomplete Maildir messages stored in that directory. This patch attempts to refine the feature. If "tmp" entry is found, it first checks if the containing directory looks like a Maildir directory. This is done by searching for other common Maildir subdirectories. If they exist and if the entry "tmp" is a directory then it is skipped. Files and subdirectories with the name "tmp" that do not look like Maildir will still be processed by 'notmuch new'. Signed-off-by: Jan Janak --- notmuch-new.c | 28 +++++++++++++++++++++++++++- 1 files changed, 27 insertions(+), 1 deletions(-) diff --git a/notmuch-new.c b/notmuch-new.c index e32b92a..3e1c9a7 100644 --- a/notmuch-new.c +++ b/notmuch-new.c @@ -80,6 +80,30 @@ static int ino_cmp(const struct dirent **a, const struct dirent **b) return ((*a)->d_ino < (*b)->d_ino) ? -1 : 1; } +/* Test if the directory looks like a Maildir directory. + * + * Search through the array of directory entries to see if we can find all + * three subdirectories typical for Maildir, that is "new", "cur", and "tmp". + * + * Return 1 if the directory looks like a Maildir and 0 otherwise. + */ +static int is_maildir (struct dirent **entries, int count) +{ + int i, found = 0; + + for (i = 0; i < count; i++) { + if (entries[i]->d_type != DT_DIR) continue; + if (strcmp(entries[i]->d_name, "new") == 0 || + strcmp(entries[i]->d_name, "cur") == 0 || + strcmp(entries[i]->d_name, "tmp") == 0) + { + found++; + } + } + + return found >= 3; +} + /* Examine 'path' recursively as follows: * * o Ask the filesystem for the mtime of 'path' (path_mtime) @@ -159,7 +183,9 @@ add_files_recursive (notmuch_database_t *notmuch, * user specify files to be ignored. */ if (strcmp (entry->d_name, ".") == 0 || strcmp (entry->d_name, "..") == 0 || - strcmp (entry->d_name, "tmp") == 0 || + (entry->d_type == DT_DIR && + (strcmp (entry->d_name, "tmp") == 0) && + is_maildir (namelist, num_entries)) || strcmp (entry->d_name, ".notmuch") ==0) { continue; -- 1.6.3.3