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 5EE9D431FDE for ; Thu, 25 Oct 2012 16:33:28 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.699 X-Spam-Level: X-Spam-Status: No, score=-0.699 tagged_above=-999 required=5 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled 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 ibuNg8STPpy2 for ; Thu, 25 Oct 2012 16:33:25 -0700 (PDT) Received: from mail-qc0-f181.google.com (mail-qc0-f181.google.com [209.85.216.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 5FB81431FAE for ; Thu, 25 Oct 2012 16:33:25 -0700 (PDT) Received: by mail-qc0-f181.google.com with SMTP id x40so1058185qcp.26 for ; Thu, 25 Oct 2012 16:33:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=P7Gk2RXu8IxuwzfhcBZ2hlp/jpTkc4Pe8RllG0E+6HA=; b=vm8yvmciJVXVUIkD2yYdIjbEC+cxBX6cZjQYlkd5if1X1/SpkMd1/pw+HdOVVuyVvq 1tQNM3aHMtYErNrmtn0X7IwkKolcc9G7tEo3T7lJM4a05b+DaFLXvZbaxK7KtpDI8Bru O+kJ4wV3fS8dB2/rDaHaakqpeS6yEjmWs4PoF2p+V/9NYFyROvzmpRpRHZEXKvguZtVr H3LFdqd9QPObsjq8Jir0rBSBYpYZEdJeJ4jgqJ+5LrXbimMCmzBUz+Ns8jghdcd3VBBl +aZpxQRsvwhwx8du493PoWbeX4q27VQrYeJ7qd6fGQpPqNhZKC5ScY50Kx28yaDTgZbC bCbA== Received: by 10.224.107.3 with SMTP id z3mr1880883qao.9.1351208005203; Thu, 25 Oct 2012 16:33:25 -0700 (PDT) Received: from skynet (26-4-166.dynamic.csail.mit.edu. [18.26.4.166]) by mx.google.com with ESMTPS id gw9sm161680qab.4.2012.10.25.16.33.23 (version=SSLv3 cipher=OTHER); Thu, 25 Oct 2012 16:33:24 -0700 (PDT) Sender: Taesoo Kim Received: by skynet (sSMTP sendmail emulation); Thu, 25 Oct 2012 19:34:44 -0400 From: Taesoo Kim To: notmuch@notmuchmail.org Subject: [PATCH 1/2] Automatic tagging based on maildir Date: Thu, 25 Oct 2012 19:33:58 -0400 Message-Id: <1351208039-32293-2-git-send-email-taesoo@mit.edu> X-Mailer: git-send-email 1.8.0 In-Reply-To: <1351208039-32293-1-git-send-email-taesoo@mit.edu> References: <1351208039-32293-1-git-send-email-taesoo@mit.edu> X-Mailman-Approved-At: Thu, 25 Oct 2012 22:45:51 -0700 Cc: Taesoo Kim 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: Thu, 25 Oct 2012 23:33:28 -0000 Since gmail will provide labels as imap sub/folders, notmuch also can take advantage of labels as tags, when maildir.add_as_tag_flags is specified. Signed-off-by: Taesoo Kim --- notmuch-client.h | 7 +++++++ notmuch-config.c | 42 ++++++++++++++++++++++++++++++++++++++---- notmuch-new.c | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+), 4 deletions(-) diff --git a/notmuch-client.h b/notmuch-client.h index ae9344b..ce05e52 100644 --- a/notmuch-client.h +++ b/notmuch-client.h @@ -265,6 +265,13 @@ void notmuch_config_set_maildir_synchronize_flags (notmuch_config_t *config, notmuch_bool_t synchronize_flags); +notmuch_bool_t +notmuch_config_get_maildir_add_as_tag_flags (notmuch_config_t *config); + +void +notmuch_config_set_maildir_add_as_tag_flags (notmuch_config_t *config, + notmuch_bool_t add_as_tag_flags); + const char ** notmuch_config_get_search_exclude_tags (notmuch_config_t *config, size_t *length); diff --git a/notmuch-config.c b/notmuch-config.c index 3e37a2d..c95f9dd 100644 --- a/notmuch-config.c +++ b/notmuch-config.c @@ -88,7 +88,16 @@ static const char maildir_config_comment[] = "\n" "\tThe \"notmuch new\" command will notice flag changes in filenames\n" "\tand update tags, while the \"notmuch tag\" and \"notmuch restore\"\n" - "\tcommands will notice tag changes and update flags in filenames\n"; + "\tcommands will notice tag changes and update flags in filenames\n" + "\n" + "\tadd_as_tag_flags Valid values are true and false.\n" + "\n" + "\nIf ture, then add the lower-cased name of maildirs" + "\n(also deliminated by .) as tags" + "\n" + "\n\te.g. Life -> life" + "\n\te.g. MIT.CSAIL -> mit, csail" + "\n\te.g. Mailing.OSS.Linux -> mailing, oss, linux"; static const char search_config_comment[] = " Search configuration\n" @@ -114,6 +123,7 @@ struct _notmuch_config { const char **new_ignore; size_t new_ignore_length; notmuch_bool_t maildir_synchronize_flags; + notmuch_bool_t maildir_add_as_tag_flags; const char **search_exclude_tags; size_t search_exclude_tags_length; }; @@ -251,7 +261,7 @@ notmuch_config_open (void *ctx, fprintf (stderr, "Out of memory.\n"); return NULL; } - + talloc_set_destructor (config, notmuch_config_destructor); if (filename) { @@ -393,6 +403,14 @@ notmuch_config_open (void *ctx, g_error_free (error); } + config->maildir_add_as_tag_flags = + g_key_file_get_boolean (config->key_file, + "maildir", "add_as_tag_flags", &error); + if (error) { + notmuch_config_set_maildir_add_as_tag_flags (config, FALSE); + g_error_free (error); + } + /* Whenever we know of configuration sections that don't appear in * the configuration file, we add some comments to help the user * understand what can be done. */ @@ -438,7 +456,7 @@ notmuch_config_open (void *ctx, } /* Close the given notmuch_config_t object, freeing all resources. - * + * * Note: Any changes made to the configuration are *not* saved by this * function. To save changes, call notmuch_config_save before * notmuch_config_close. @@ -720,7 +738,7 @@ notmuch_config_command_get (void *ctx, char *item) } else if (strcmp(item, "user.other_email") == 0) { const char **other_email; size_t i, length; - + other_email = notmuch_config_get_user_other_email (config, &length); for (i = 0; i < length; i++) printf ("%s\n", other_email[i]); @@ -891,3 +909,19 @@ notmuch_config_set_maildir_synchronize_flags (notmuch_config_t *config, "maildir", "synchronize_flags", synchronize_flags); config->maildir_synchronize_flags = synchronize_flags; } + + +notmuch_bool_t +notmuch_config_get_maildir_add_as_tag_flags (notmuch_config_t *config) +{ + return config->maildir_add_as_tag_flags; +} + +void +notmuch_config_set_maildir_add_as_tag_flags (notmuch_config_t *config, + notmuch_bool_t add_as_tag_flags) +{ + g_key_file_set_boolean (config->key_file, + "maildir", "add_as_tag_flags", add_as_tag_flags); + config->maildir_add_as_tag_flags = add_as_tag_flags; +} diff --git a/notmuch-new.c b/notmuch-new.c index 56c4a6f..9ec983f 100644 --- a/notmuch-new.c +++ b/notmuch-new.c @@ -20,6 +20,7 @@ #include "notmuch-client.h" +#include #include typedef struct _filename_node { @@ -53,6 +54,7 @@ typedef struct { _filename_list_t *directory_mtimes; notmuch_bool_t synchronize_flags; + notmuch_bool_t add_as_tag_flags; } add_files_state_t; static volatile sig_atomic_t do_print_progress = 0; @@ -240,6 +242,32 @@ _entry_in_ignore_list (const char *entry, add_files_state_t *state) return FALSE; } +static void +_add_maildir_as_tag(notmuch_database_t *notmuch, + notmuch_message_t *msg, const char *path) +{ + char *tok = talloc_strdup (notmuch, path); + int len = strlen(tok); + + /* asserts path ends with /cur|/tmp|/new */ + if (len > 4 && tok[len - 4] == '/') { + char *iter = tok + len - 4; + *iter = '\0'; + while (-- iter && iter >= tok) { + char c = *iter; + if (c == '/' || c == '.') { + *iter = '\0'; + notmuch_message_add_tag (msg, iter + 1); + if (c == '/') { + break; + } + } + *iter = tolower(*iter); + } + } + talloc_free (tok); +} + /* Examine 'path' recursively as follows: * * o Ask the filesystem for the mtime of 'path' (fs_mtime) @@ -508,6 +536,9 @@ add_files (notmuch_database_t *notmuch, notmuch_message_freeze (message); for (tag=state->new_tags; *tag != NULL; tag++) notmuch_message_add_tag (message, *tag); + if (state->add_as_tag_flags == TRUE) { + _add_maildir_as_tag(notmuch, message, path); + } if (state->synchronize_flags == TRUE) notmuch_message_maildir_flags_to_tags (message); notmuch_message_thaw (message); @@ -878,6 +909,7 @@ notmuch_new_command (void *ctx, int argc, char *argv[]) add_files_state.new_tags = notmuch_config_get_new_tags (config, &add_files_state.new_tags_length); add_files_state.new_ignore = notmuch_config_get_new_ignore (config, &add_files_state.new_ignore_length); add_files_state.synchronize_flags = notmuch_config_get_maildir_synchronize_flags (config); + add_files_state.add_as_tag_flags = notmuch_config_get_maildir_add_as_tag_flags (config); db_path = notmuch_config_get_database_path (config); if (run_hooks) { -- 1.8.0