From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1.migadu.com ([2001:41d0:403:4876::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms13.migadu.com with LMTPS id 2HvnHrCw4WY3rgAA62LTzQ:P1 (envelope-from ) for ; Wed, 11 Sep 2024 15:01:04 +0000 Received: from aspmx1.migadu.com ([2001:41d0:403:4876::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1.migadu.com with LMTPS id 2HvnHrCw4WY3rgAA62LTzQ (envelope-from ) for ; Wed, 11 Sep 2024 17:01:04 +0200 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 2a01:4f9:c011:7a79::1 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1726066862; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-owner:list-unsubscribe:list-subscribe:list-post; bh=e7VEtAo/GnosOq2tzTvIX6sRMG9bDLJ9qrhAqzwnxs0=; b=OAVsZnXmSduoBC8MTWqU0fm0XxUjRDDm/iaFZCPvmbJIBDR95Pf9CZyxUr6aLOcXCrHiNB F2j22I3unLeQ2x4kSP7NDwbGZBvXACLBFpZRytexOzban5ofRVs5OAWTDvDrORh4PE6yy9 OnUPrHngCL3aLGa27FETVreRm/RxyzjbRGIB8XpYfVjDmfdAWNlglpNW6dqlzw5m6IET39 eBLVMDQoZRRSb/BNIrWsho/fv3TS+C0kWu2zQ+ytUaFfF5A19c61uuC+3OQ9Hkr5y6Hqsf OmRL74n+H1Das+atjtgjCCRQguzUfOpIph1K9Gyp8PgMFA8atRuAOVBE0AeNsQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 2a01:4f9:c011:7a79::1 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org; dmarc=none ARC-Seal: i=1; s=key1; d=yhetil.org; t=1726066862; a=rsa-sha256; cv=none; b=nwj6FC6HBj/MA/MxzJWB9TgjNGcLTJVmJ9oET0PYqnYzNcykpvweQtUQUIGQcuOpt27rdE oJqC2ePBhUC+nApmeX9Z8OsNiK4yYVXhjvGAtJdtewDTIrDSsuxsanICXgXi354Ksu9x77 g9VimEw7pqMLYDmmqcgkMuckEuNOqdT/9qFxb8fzrX6T5w858mJICPLU3CeWv+YrxCxHLV zpJBEl14D5LRznta7t9nK/UezmijvAkOo90zJEtkQ6+g6upIMhWoddgVnHJWLtu97RWk5U miFzif31KdXd36tFrFCHDKTVjkHfM0Rb0xt5sCVYKTHOJlUQcvwb9KOVFLw3HA== Received: from mail.notmuchmail.org (yantan.tethera.net [IPv6:2a01:4f9:c011:7a79::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 94891C40C for ; Wed, 11 Sep 2024 17:01:02 +0200 (CEST) Received: from yantan.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 389E05E527; Wed, 11 Sep 2024 15:00:53 +0000 (UTC) Received: from smtp.umanwizard.com (smtp.umanwizard.com [54.203.248.109]) by mail.notmuchmail.org (Postfix) with ESMTP id E3D525E517 for ; Wed, 11 Sep 2024 15:00:48 +0000 (UTC) Received: from localhost ([174.229.41.125]) by smtp.umanwizard.com ; 11 Sep 2024 15:00:47 +0000 X-Fes-Received-For: notmuch@notmuchmail.org X-Fes-Received-From: From: Brennan Vincent To: notmuch@notmuchmail.org Subject: [PATCH v2] Add --emit-message-id flag to notmuch-insert. In-Reply-To: <87plpbtfj2.fsf@taipei.mail-host-address-is-not-set> References: <87plpbtfj2.fsf@taipei.mail-host-address-is-not-set> X-Envelope-From: 508a062d987179f1827ef5a2d4c769dd544dc649 Mon Sep 17 00:00:00 2001 Date: Wed, 11 Sep 2024 11:00:45 -0400 Message-ID: <87msketeua.fsf@taipei.mail-host-address-is-not-set> MIME-Version: 1.0 X-Fes-Encrypted: true X-Fes-Ehlo-Domain: localhost Message-ID-Hash: 46IUI6HX3TYMQAA44K7YAB2ZTLXMBCO5 X-Message-ID-Hash: 46IUI6HX3TYMQAA44K7YAB2ZTLXMBCO5 X-MailFrom: brennan@umanwizard.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-notmuch.notmuchmail.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.3 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Migadu-Country: DE X-Migadu-Flow: FLOW_IN X-Spam-Score: -1.56 X-Migadu-Queue-Id: 94891C40C X-Migadu-Scanner: mx10.migadu.com X-Migadu-Spam-Score: -1.56 X-TUID: IqtN+cY11/bU --- doc/man1/notmuch-insert.rst | 5 +++++ notmuch-insert.c | 26 +++++++++++++++++++++----- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/doc/man1/notmuch-insert.rst b/doc/man1/notmuch-insert.rst index e05bd0b5..3848b8f6 100644 --- a/doc/man1/notmuch-insert.rst +++ b/doc/man1/notmuch-insert.rst @@ -66,6 +66,11 @@ Supported options for **insert** include umask. By default, delivered mail is only readable by the current user. +.. option:: --emit-message-id + + On successful exit (or with ``--keep``), + print the message ID of the newly indexed message. + .. option:: --decrypt=(true|nostash|auto|false) If ``true`` and the message is encrypted, try to decrypt the diff --git a/notmuch-insert.c b/notmuch-insert.c index e44607ad..5554245b 100644 --- a/notmuch-insert.c +++ b/notmuch-insert.c @@ -399,9 +399,10 @@ maildir_write_new (const void *ctx, int fdin, const char *maildir, bool world_re * database results in error status regardless of keep. */ static notmuch_status_t -add_file (notmuch_database_t *notmuch, const char *path, tag_op_list_t *tag_ops, +add_file (const void *ctx, notmuch_database_t *notmuch, const char *path, tag_op_list_t *tag_ops, bool synchronize_flags, bool keep, - notmuch_indexopts_t *indexopts) + notmuch_indexopts_t *indexopts, + char **message_id_out) { notmuch_message_t *message; notmuch_status_t status; @@ -441,8 +442,6 @@ add_file (notmuch_database_t *notmuch, const char *path, tag_op_list_t *tag_ops, } DONE: - notmuch_message_destroy (message); - if (status) { if (keep) { status = NOTMUCH_STATUS_SUCCESS; @@ -458,6 +457,15 @@ add_file (notmuch_database_t *notmuch, const char *path, tag_op_list_t *tag_ops, } } } + if (message_id_out) { + if (!status) { + *message_id_out = talloc_strdup(ctx, notmuch_message_get_message_id(message)); + } else { + *message_id_out = NULL; + } + } + notmuch_message_destroy (message); + FAIL: return status; @@ -477,10 +485,12 @@ notmuch_insert_command (notmuch_database_t *notmuch, int argc, char *argv[]) bool keep = false; bool hooks = true; bool world_readable = false; + bool emit_message_id = false; notmuch_bool_t synchronize_flags; char *maildir; char *newpath; int opt_index; + char *message_id; notmuch_indexopts_t *indexopts = notmuch_database_get_default_indexopts (notmuch); void *local = talloc_new (NULL); @@ -491,6 +501,7 @@ notmuch_insert_command (notmuch_database_t *notmuch, int argc, char *argv[]) { .opt_bool = &keep, .name = "keep" }, { .opt_bool = &hooks, .name = "hooks" }, { .opt_bool = &world_readable, .name = "world-readable" }, + { .opt_bool = &emit_message_id, .name = "emit-message-id" }, { .opt_inherit = notmuch_shared_indexing_options }, { .opt_inherit = notmuch_shared_options }, { } @@ -580,7 +591,8 @@ notmuch_insert_command (notmuch_database_t *notmuch, int argc, char *argv[]) } /* Index the message. */ - status = add_file (notmuch, newpath, tag_ops, synchronize_flags, keep, indexopts); + status = add_file (local, notmuch, newpath, tag_ops, synchronize_flags, keep, indexopts, + emit_message_id ? &message_id : NULL); /* Commit changes. */ close_status = notmuch_database_close (notmuch); @@ -606,6 +618,10 @@ notmuch_insert_command (notmuch_database_t *notmuch, int argc, char *argv[]) } } + if (!status && emit_message_id && message_id) { + printf("%s\n", message_id); + } + if (hooks && status == NOTMUCH_STATUS_SUCCESS) { /* Ignore hook failures. */ notmuch_run_hook (notmuch, "post-insert"); -- 2.45.2