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 0641B431FBC for ; Wed, 25 Nov 2009 13:11:52 -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 QanLcv70ysoJ for ; Wed, 25 Nov 2009 13:11:51 -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 3D355431FAE for ; Wed, 25 Nov 2009 13:11:51 -0800 (PST) Received: by ewy5 with SMTP id 5so132569ewy.30 for ; Wed, 25 Nov 2009 13:11:50 -0800 (PST) Received: by 10.213.1.7 with SMTP id 7mr7115660ebd.27.1259183507974; Wed, 25 Nov 2009 13:11:47 -0800 (PST) Received: from x61s.janakj ([213.192.30.141]) by mx.google.com with ESMTPS id 7sm225193eyb.42.2009.11.25.13.11.46 (version=TLSv1/SSLv3 cipher=RC4-MD5); Wed, 25 Nov 2009 13:11:47 -0800 (PST) Received: by x61s.janakj (Postfix, from userid 1000) id 8140C440655; Wed, 25 Nov 2009 22:11:45 +0100 (CET) From: Jan Janak To: notmuch@notmuchmail.org Date: Wed, 25 Nov 2009 22:11:45 +0100 Message-Id: <1259183505-30840-1-git-send-email-jan@ryngle.com> X-Mailer: git-send-email 1.6.3.3 In-Reply-To: <1259178195-30324-1-git-send-email-jan@ryngle.com> References: <1259178195-30324-1-git-send-email-jan@ryngle.com> 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 21:11:52 -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 | 29 ++++++++++++++++++++++++++++- 1 files changed, 28 insertions(+), 1 deletions(-) diff --git a/notmuch-new.c b/notmuch-new.c index e32b92a..10dc72b 100644 --- a/notmuch-new.c +++ b/notmuch-new.c @@ -80,6 +80,31 @@ 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++; + if (found == 3) return 1; + } + } + + return 0; +} + /* Examine 'path' recursively as follows: * * o Ask the filesystem for the mtime of 'path' (path_mtime) @@ -159,7 +184,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