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 13563431FC2 for ; Sat, 13 Jul 2013 17:55:29 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[RCVD_IN_DNSWL_NONE=-0.0001] 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 XgI9yu5KBwMj for ; Sat, 13 Jul 2013 17:55:23 -0700 (PDT) X-Greylist: delayed 569 seconds by postgrey-1.32 at olra; Sat, 13 Jul 2013 17:55:23 PDT Received: from smtp-out-01.shaw.ca (smtp-out-01.shaw.ca [64.59.136.137]) by olra.theworths.org (Postfix) with ESMTP id 22909431FBD for ; Sat, 13 Jul 2013 17:55:23 -0700 (PDT) X-Cloudmark-SP-Filtered: true X-Cloudmark-SP-Result: v=1.1 cv=GLqYwptGXHjY6tPk5kWRtHXJM/YfZPTWiIs1znw4zms= c=1 sm=1 a=rp4hpZfak4kA:10 a=BLceEmwcHowA:10 a=gumk1giGF0obp6xRQyl7Yg==:17 a=CxbBOAgXj7yANbSEhssA:9 a=Wdz57yXjOC6DuMvi:21 a=0pJnlCBgKrPFDJOa:21 a=HpAAvcLHHh0Zw7uRqdWCyQ==:117 Received: from unknown (HELO lagos.xvx.ca) ([68.150.39.45]) by smtp-out-01.shaw.ca with ESMTP; 13 Jul 2013 18:46:04 -0600 Received: by lagos.xvx.ca (Postfix, from userid 1000) id 57CD58009323; Sat, 13 Jul 2013 18:46:04 -0600 (MDT) From: Adam Wolfe Gordon To: notmuch@notmuchmail.org Subject: [PATCH 2/3] cli: Introduce the add command Date: Sat, 13 Jul 2013 18:45:45 -0600 Message-Id: <1373762746-22308-3-git-send-email-awg+notmuch@xvx.ca> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1373762746-22308-1-git-send-email-awg+notmuch@xvx.ca> References: <1373762746-22308-1-git-send-email-awg+notmuch@xvx.ca> 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: Sun, 14 Jul 2013 00:55:29 -0000 Introduce a new add command, which works the same as insert, except that it is for adding files that already exist in the maildir. This provides an alternative to notmuch new for situations where the user knows what has changed. For example, if the user uses inotify to check for new files in the maildir, the new files can be indexed using notmuch add, avoiding the need to scan the whole maildir. --- notmuch-client.h | 3 +++ notmuch-insert.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ notmuch.c | 2 ++ 3 files changed, 54 insertions(+) diff --git a/notmuch-client.h b/notmuch-client.h index da332f3..09d7e5c 100644 --- a/notmuch-client.h +++ b/notmuch-client.h @@ -183,6 +183,9 @@ int notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[]); int +notmuch_add_command (notmuch_config_t *config, int argc, char *argv[]); + +int notmuch_reply_command (notmuch_config_t *config, int argc, char *argv[]); int diff --git a/notmuch-insert.c b/notmuch-insert.c index d32a535..c141450 100644 --- a/notmuch-insert.c +++ b/notmuch-insert.c @@ -479,3 +479,52 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[]) return (ret) ? 0 : 1; } + +int +notmuch_add_command (notmuch_config_t *config, int argc, char *argv[]) +{ + notmuch_database_t *notmuch; + const char *db_path; + const char **new_tags; + size_t new_tags_length; + tag_op_list_t *tag_ops; + const char *filename = NULL; + unsigned int i; + notmuch_bool_t ret; + + if (argc != 2) { + fprintf (stderr, "Error: no filename given.\n"); + return 1; + } + filename = argv[1]; + + db_path = notmuch_config_get_database_path (config); + new_tags = notmuch_config_get_new_tags (config, &new_tags_length); + + tag_ops = tag_op_list_create (config); + if (tag_ops == NULL) { + fprintf (stderr, "Out of memory.\n"); + return 1; + } + for (i = 0; i < new_tags_length; i++) { + if (tag_op_list_append (tag_ops, new_tags[i], FALSE)) + return 1; + } + + /* Check that the message given on the commandline is in the maildir. */ + if (strncmp (filename, db_path, strlen(db_path)) != 0) { + fprintf(stderr, "Error: file %s is not in maildir %s.\n", filename, + db_path); + return 1; + } + + if (notmuch_database_open (notmuch_config_get_database_path (config), + NOTMUCH_DATABASE_MODE_READ_WRITE, ¬much)) + return 1; + + ret = add_file_to_database (notmuch, filename, tag_ops); + + notmuch_database_destroy (notmuch); + + return (ret) ? 0 : 1; +} diff --git a/notmuch.c b/notmuch.c index 78d29a8..b61149d 100644 --- a/notmuch.c +++ b/notmuch.c @@ -46,6 +46,8 @@ static command_t commands[] = { "Find and import new messages to the notmuch database." }, { "insert", notmuch_insert_command, FALSE, "Add a new message into the maildir and notmuch database." }, + { "add", notmuch_add_command, FALSE, + "Add a message from the maildir into the notmuch database." }, { "search", notmuch_search_command, FALSE, "Search for messages matching the given search terms." }, { "show", notmuch_show_command, FALSE, -- 1.7.9.5