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