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 02B43431FAE for ; Tue, 9 Feb 2010 19:23:08 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -2.599 X-Spam-Level: X-Spam-Status: No, score=-2.599 tagged_above=-999 required=5 tests=[BAYES_00=-2.599] autolearn=unavailable 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 t6LIzCYvEBo4 for ; Tue, 9 Feb 2010 19:23:06 -0800 (PST) Received: from outbound-mail04.westnet.com.au (outbound-mail04.westnet.com.au [203.10.1.245]) by olra.theworths.org (Postfix) with ESMTP id 5F6F8431FBC for ; Tue, 9 Feb 2010 19:23:05 -0800 (PST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AvsEAFCzcUvKrYlp/2dsb2JhbACaZHW9Z4RUBA X-IronPort-AV: E=Sophos;i="4.49,440,1262534400"; d="scan'208";a="19317446" Received: from dsl-202-173-137-105.sa.westnet.com.au (HELO mail.stoakes.net) ([202.173.137.105]) by outbound-mail04.westnet.com.au with ESMTP/TLS/ADH-CAMELLIA256-SHA; 10 Feb 2010 11:13:43 +0800 Received: from noodle.stoakes.net (unknown [192.168.20.220]) by mail.stoakes.net (Postfix) with ESMTP id 15CD9EE486; Wed, 10 Feb 2010 13:43:40 +1030 (CST) Received: by noodle.stoakes.net (Postfix, from userid 1000) id 7C9677F0BD; Wed, 10 Feb 2010 13:43:39 +1030 (CST) Date: Wed, 10 Feb 2010 13:43:39 +1030 From: Tim Stoakes To: Michiel Buddingh' Message-ID: <20100210031339.GH16686@mail.rocksoft.com> References: <87bpiv4t9h.fsf@yoom.home.cworth.org> <87y6lz39nd.fsf@yoom.home.cworth.org> <20091121221207.GB17268@jukie.net> <9cce5525b093b87fe74d427954ffad89@localhost> <87d43b2oif.fsf@yoom.home.cworth.org> <9bfdedddeab9c58cd45d8d448323d0fc@localhost> <87skc23327.fsf@yoom.home.cworth.org> <4b0eef22.JwxdgTGElffx149F%michiel@michielbuddingh.net> <87ws1bjpmm.fsf@yoom.home.cworth.org> <878wdfkhcl.fsf@aegir.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <878wdfkhcl.fsf@aegir.org.uk> User-Agent: Mutt/1.5.20 (2009-06-14) Cc: notmuch@notmuchmail.org Subject: Re: [notmuch] [PATCH] notmuch: Respect maildir message flags 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: Wed, 10 Feb 2010 03:23:08 -0000 Michiel Buddingh'(michiel@michielbuddingh.net)@061209-20:55: > ... > A new patch is attached. Apologies for the rather verbose Maildir > handling logic, but I couldn't find a way to minimize the calls to > is_maildir that was both neat and readable. Hi notmuch-ers, My apologies for dredging up an old thread. I don't want to restart the religious war over whether notmuch should respect Maildir flags - suffice to say that *I* want that, and the patch posted by Michiel seemed to be the best way to make that happen. Since it no longer applies cleanly, I've ported it forward to 79d3f9773c58d6fd7113871362687d8cfc0b1a59, to save someone else the trouble. It works for me, but that's all the testing I've done. Tim -- Tim Stoakes --- notmuch-new.c | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 85 insertions(+), 1 deletions(-) diff --git a/notmuch-new.c b/notmuch-new.c index f25c71f..3264653 100644 --- a/notmuch-new.c +++ b/notmuch-new.c @@ -39,6 +39,7 @@ typedef struct { int total_files; int processed_files; int added_messages; + int tag_maildir; struct timeval tv_start; _filename_list_t *removed_files; @@ -169,6 +170,60 @@ _entries_resemble_maildir (struct dirent **entries, int count) return 0; } +/* Tag new mail according to its Maildir attribute flags. + * + * Test if the mail file's filename contains any of the + * standard Maildir attributes, and translate these to + * the corresponding standard notmuch tags. + * + * If the message is not marked as 'seen', or if no + * flags are present, tag as 'inbox, unread'. + */ +static void +derive_tags_from_maildir_flags (notmuch_message_t *message, + const char * path) +{ + int seen = FALSE; + int end_of_flags = FALSE; + size_t l = strlen(path); + + /* Non-experimental message flags start with this */ + char * i = strstr(path, ":2,"); + i = (i) ? i : strstr(path, "!2,"); /* This format is used on VFAT */ + if (i != NULL) { + i += 3; + for (; i < (path + l) && !end_of_flags; i++) { + switch (*i) { + case 'F' : + notmuch_message_add_tag (message, "flagged"); + break; + case 'R': /* replied */ + notmuch_message_add_tag (message, "answered"); + break; + case 'D': + notmuch_message_add_tag (message, "draft"); + break; + case 'S': /* seen */ + seen = TRUE; + break; + case 'T': /* trashed */ + notmuch_message_add_tag (message, "deleted"); + break; + case 'P': /* passed */ + notmuch_message_add_tag (message, "forwarded"); + break; + default: + end_of_flags = TRUE; + break; + } + } + } + + if (i == NULL || !seen) { + tag_inbox_and_unread (message); + } +} + /* Examine 'path' recursively as follows: * * o Ask the filesystem for the mtime of 'path' (fs_mtime) @@ -222,6 +277,7 @@ add_files_recursive (notmuch_database_t *notmuch, notmuch_filenames_t *db_subdirs = NULL; struct stat st; notmuch_bool_t is_maildir, new_directory; + int maildir_detected = -1; if (stat (path, &st)) { fprintf (stderr, "Error reading directory %s: %s\n", @@ -301,6 +357,28 @@ add_files_recursive (notmuch_database_t *notmuch, continue; } + /* If this directory is a Maildir folder, we need to + * ignore any subdirectories marked tmp/, and scan for + * Maildir attributes on messages contained in the sub- + * directories 'new' and 'cur'. */ + if (maildir_detected != 0 && + entry->d_type == DT_DIR && + ((strcmp (entry->d_name, "tmp") == 0) || + (strcmp (entry->d_name, "new") == 0) || + (strcmp (entry->d_name, "cur") == 0))) { + + if (maildir_detected == -1) { + maildir_detected = _entries_resemble_maildir(fs_entries, num_fs_entries); + } + if (maildir_detected == 1) { + if (strcmp (entry->d_name, "tmp") == 0) { + continue; + } else { + state->tag_maildir = TRUE; + } + } + } + next = talloc_asprintf (notmuch, "%s/%s", path, entry->d_name); status = add_files_recursive (notmuch, next, state); if (status && ret == NOTMUCH_STATUS_SUCCESS) @@ -412,7 +490,12 @@ add_files_recursive (notmuch_database_t *notmuch, /* success */ case NOTMUCH_STATUS_SUCCESS: state->added_messages++; - tag_inbox_and_unread (message); + if (state->tag_maildir) { + derive_tags_from_maildir_flags (message, + entry->d_name); + } else { + tag_inbox_and_unread (message); + } break; /* Non-fatal issues (go on to next file) */ case NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID: @@ -482,6 +565,7 @@ add_files_recursive (notmuch_database_t *notmuch, status = notmuch_directory_set_mtime (directory, fs_mtime); if (status && ret == NOTMUCH_STATUS_SUCCESS) ret = status; + state->tag_maildir = FALSE; } DONE: -- 1.6.6.1