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 043224196F2 for ; Sat, 10 Apr 2010 08:03:07 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -1.899 X-Spam-Level: X-Spam-Status: No, score=-1.899 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001] 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 EUKbabgtfdu2 for ; Sat, 10 Apr 2010 08:03:06 -0700 (PDT) Received: from mail-yw0-f187.google.com (mail-yw0-f187.google.com [209.85.211.187]) by olra.theworths.org (Postfix) with ESMTP id D6FEE431FC1 for ; Sat, 10 Apr 2010 08:03:05 -0700 (PDT) Received: by ywh17 with SMTP id 17so816203ywh.22 for ; Sat, 10 Apr 2010 08:03:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:sender:received:date :x-google-sender-auth:received:message-id:subject:from:to :content-type; bh=WQWH5nAUZwnz1o9Vj12pWs+XAS/tDeOKUqxcSY6dHPk=; b=fEj49pk9mMO4GLMRZgHE/Ahb8g+aeM6k0TJaOZCOSS5V/Xn3+NbBftw7nyA0PJwubb AcWcWRhdEPqdkOAuFJQQB6W+6mtiyWVuPUDBVkQITIX98dz95lXSrRDXv5eyXmIdvCWa C1KLKft/CL4O7GKxJqkbL8nFfoKOJdG1cAb04= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:date:x-google-sender-auth:message-id:subject :from:to:content-type; b=kPGxo3HrT3L/NQrGHPPy7Ls4bQ/osUPUKKZg0Z+cGpYv0NW5jfD9tO0Qw/wA4BoWmo FM4IC6/lg8vIvp2GXictL19ln3RCZ09fz8caxpe3/BI/XbdbtqwI2KfW1cFD6jJZ/HeL tXcMh/qzhgPz8QVAT/HKUPq4J51WYcCfHfWh8= MIME-Version: 1.0 Sender: anthony.j.towns@gmail.com Received: by 10.90.114.1 with HTTP; Sat, 10 Apr 2010 08:03:04 -0700 (PDT) Date: Sun, 11 Apr 2010 01:03:04 +1000 X-Google-Sender-Auth: 5bef8ae0e3f058d7 Received: by 10.91.1.2 with SMTP id d2mr680895agi.121.1270911784490; Sat, 10 Apr 2010 08:03:04 -0700 (PDT) Message-ID: Subject: [PATCH] notmuch new --new-tags=tags... From: Anthony Towns To: notmuch Content-Type: text/plain; charset=ISO-8859-1 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: Sat, 10 Apr 2010 15:03:07 -0000 Hi *, The attached patch makes "notmuch new --new-tags=unread,new" set the "unread" and "new" tags on any new mail it finds rather than "unread" and "inbox". Or whatever other tags you happen to specify. Signed-off-by: Anthony Towns --- NEWS | 3 +++ notmuch-new.c | 49 +++++++++++++++++++++++++++++++++++++++++++++---- notmuch.1 | 19 ++++++++++++++++++- notmuch.c | 7 ++++++- 4 files changed, 72 insertions(+), 6 deletions(-) diff --git a/NEWS b/NEWS index f29ac27..cbfae5a 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,6 @@ +The "notmuch new" command accepts a "--new-tags=tags..." option to override +the default tags applied to new mail. + Notmuch 0.1 (2010-04-05) ======================== This is the first release of the notmuch mail system. diff --git a/notmuch-new.c b/notmuch-new.c index 44b50aa..77c99e0 100644 --- a/notmuch-new.c +++ b/notmuch-new.c @@ -32,6 +32,11 @@ typedef struct _filename_list { _filename_node_t **tail; } _filename_list_t; +typedef struct _tag_list { + char *tag; + struct _tag_list *next; +} _tag_list_t; + typedef struct { int output_is_a_tty; int verbose; @@ -41,6 +46,8 @@ typedef struct { int added_messages; struct timeval tv_start; + _tag_list_t *new_msg_tags; + _filename_list_t *removed_files; _filename_list_t *removed_directories; } add_files_state_t; @@ -93,11 +100,40 @@ _filename_list_add (_filename_list_t *list, list->tail = &node->next; } +static _tag_list_t * +_parse_tags (void *ctx, const char *orig_str) +{ + _tag_list_t *tag_head = NULL, **tag_tail = &tag_head; + char *dupe_str, *start, *comma; + + dupe_str = talloc_strdup(ctx, orig_str); + start = dupe_str; + + do { + comma = strchr(start, ','); + if (comma) + *(comma++) = '\0'; + + if (*start != '\0') { + *tag_tail = talloc(dupe_str, _tag_list_t); + (*tag_tail)->tag = start; + (*tag_tail)->next = NULL; + tag_tail = &(*tag_tail)->next; + } + + start = comma; + } while (start); + + return tag_head; +} + static void -tag_inbox_and_unread (notmuch_message_t *message) +tag_new_message (add_files_state_t *state, notmuch_message_t *message) { - notmuch_message_add_tag (message, "inbox"); - notmuch_message_add_tag (message, "unread"); + _tag_list_t *cur; + for (cur = state->new_msg_tags; cur; cur = cur->next) { + notmuch_message_add_tag (message, cur->tag); + } } static void @@ -412,7 +448,7 @@ add_files_recursive (notmuch_database_t *notmuch, /* success */ case NOTMUCH_STATUS_SUCCESS: state->added_messages++; - tag_inbox_and_unread (message); + tag_new_message (state, message); break; /* Non-fatal issues (go on to next file) */ case NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID: @@ -714,6 +750,7 @@ notmuch_new_command (void *ctx, int argc, char *argv[]) struct stat st; const char *db_path; char *dot_notmuch_path; + const char *new_msg_tags = "inbox,unread"; struct sigaction action; _filename_node_t *f; int renamed_files, removed_files; @@ -726,12 +763,16 @@ notmuch_new_command (void *ctx, int argc, char *argv[]) for (i = 0; i < argc && argv[i][0] == '-'; i++) { if (STRNCMP_LITERAL (argv[i], "--verbose") == 0) { add_files_state.verbose = 1; + } else if (STRNCMP_LITERAL (argv[i], "--new-tags=") == 0) { + new_msg_tags = argv[i]+strlen("--new-tags="); } else { fprintf (stderr, "Unrecognized option: %s\n", argv[i]); return 1; } } + add_files_state.new_msg_tags = _parse_tags(ctx, new_msg_tags); + config = notmuch_config_open (ctx, NULL, NULL); if (config == NULL) return 1; diff --git a/notmuch.1 b/notmuch.1 index 86830f4..3bab17c 100644 --- a/notmuch.1 +++ b/notmuch.1 @@ -85,7 +85,7 @@ The command is used to incorporate new mail into the notmuch database. .RS 4 .TP 4 -.B new +.BR new " [options...]" Find and import any new messages to the database. @@ -109,6 +109,23 @@ whenever new mail is delivered and you wish to incorporate it into the database. These subsequent runs will be much quicker than the initial run. +Supported options for +.B new +include: +.RS 4 +.TP 4 +.BR \-\-new\-tags= tags... + +Set the listed tags (separated by commas) on new messages +instead of the default +.B "inbox" +and +.B "unread" +tags. + +.RE +.RS 4 + Invoking .B notmuch with no command argument will run diff --git a/notmuch.c b/notmuch.c index dcfda32..f7b16e3 100644 --- a/notmuch.c +++ b/notmuch.c @@ -126,7 +126,7 @@ command_t commands[] = { "\tInvoking notmuch with no command argument will run setup if\n" "\tthe setup command has not previously been completed." }, { "new", notmuch_new_command, - "[--verbose]", + "[--verbose] [--new-tags=inbox,unread]", "Find and import new messages to the notmuch database.", "\tScans all sub-directories of the mail directory, performing\n" "\tfull-text indexing on new messages that are found. Each new\n" @@ -148,6 +148,11 @@ command_t commands[] = { "\t\tVerbose operation. Shows paths of message files as\n" "\t\tthey are being indexed.\n" "\n" + "\t--new-tags=tags...\n" + "\n" + "\t\tSet the listed tags (separated by commas) on new messages\n" + "\t\tinstead of the default \"inbox\" and \"unread\" tags.\n" + "\n" "\tInvoking notmuch with no command argument will run new if\n" "\tthe setup command has previously been completed, but new has\n" "\tnot previously been run." }, -- 1.7.0