From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2.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 eMFVIG1w92auRwAAe85BDQ:P1 (envelope-from ) for ; Sat, 28 Sep 2024 02:56:45 +0000 Received: from aspmx1.migadu.com ([2001:41d0:403:4876::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2.migadu.com with LMTPS id eMFVIG1w92auRwAAe85BDQ (envelope-from ) for ; Sat, 28 Sep 2024 04:56:45 +0200 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=ofb.net header.s=ofb header.b=s8oPdf+1; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 135.181.149.255 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1727492205; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:list-id:list-help:list-owner:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=9NARgVlMknIo9nwuNuvrR5pyKa98gRyOTpkCKZzFKBY=; b=F6qriMRyh2/om4AaUxweU+LJKWqvreK1YGuFve/3XF26qWOfHn41Mf8gaZ9eBJaD497Sa9 e+PaZs8rTdhJFUk1NHFvm5M+4Itcd7zZ3+kDBp5dbfys7bPkpvYJ4O/iNJTxQ7yJgWd8I7 u7AzggbR6FL3JCx1e/3f8GsJm8KCOlbzmiwoOtkIgyxHdr/XGfq1D+jyo1D2+BePZ/jgFG 2bSo7rMngCzW+znSABLCtnvmMg+p9zaqUUi070lYJAmHTCp2jwjqe1HYCkyOfVd4x11z0k xRFpmRdu31Xf46LvJAKRajnrucIm/d2V/O8NQKTir6Kx/GyLdQFAyYt9a2LfUQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=ofb.net header.s=ofb header.b=s8oPdf+1; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 135.181.149.255 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org ARC-Seal: i=1; s=key1; d=yhetil.org; t=1727492205; a=rsa-sha256; cv=none; b=lCiigcXx3nNyuGfpffrHD0qcCoSPbeSYXfTYf92tBppQrk4YNWjYNi7LmrpVFEVIErUs5Z Mrh4Ueemh/7wnUyKfgeqD5Nyd28X6+YHCLvIF/oxRS9lhudof7wpoJzxXo6VGx/l7AENBY BOEuR01DxKlEjpiBJ8ltUrGuEWMF8yIbh5g/LLMgC1tRhn2P3DyMgnNpzgEMaOqndybUhO Mj5CVZ8Hk2TlbEOZdN1HQI3HYFBIaQJvk/hwcD54vB7FS8OX8YHjwnUEUqJeIve4w27QTe VA++qO2gFSyX+pknr2UOd+IgQN5M40KfZYYYDk/dn5XKZpNRLGiCwRzHTga9Pg== Received: from mail.notmuchmail.org (yantan.tethera.net [135.181.149.255]) (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 28D2187CF7 for ; Sat, 28 Sep 2024 04:56:44 +0200 (CEST) Received: from yantan.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 869A05F821; Sat, 28 Sep 2024 02:56:41 +0000 (UTC) Received: from egnor-2020.ofb.net (egnor-2020.ofb.net [IPv6:2600:3c01:e000:3d3::1]) by mail.notmuchmail.org (Postfix) with ESMTPS id 42AA05E2A8 for ; Sat, 28 Sep 2024 02:56:37 +0000 (UTC) Received: from ofb.net (ofb.net [104.197.242.163]) by egnor-2020.ofb.net (Postfix) with ESMTP id 727534E26E7; Sat, 28 Sep 2024 02:56:32 +0000 (UTC) Received: from localhost (unknown [50.247.104.190]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by ofb.net (Postfix) with ESMTPSA id B01E040AF1; Fri, 27 Sep 2024 19:56:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ofb.net; s=ofb; t=1727492191; bh=xsEAY1C5KTIx7pHzI5rYPjsG7X8JNi/Nar7VfGcMY4k=; h=Date:From:To:Cc:Subject:Reply-To:In-Reply-To:From; b=s8oPdf+1WEZfTYi1gI2CB4mYC9l+kE53TfZ5kjq6NkX+lSIi32F94aWi6YNHcUcR7 Zy2769m1fwtEFArV4eGu2RJtSROggbTrmxwniOJ2OaPcRtksBZVPBE3H/RNTV3r40e XclhDeNpOWhIvCWESt77y91cr5/jKHo4Ss6w979M5dPIWnib7sjJj3d/kL2efWw753 DCXxoM+pnRDATyEbjOrq/R0O5wOeC0Q9XRvqwrQFwADSxVI8bLTaRgqAumQmHGcYAv QcPO3nQyDn7pnT1G6ETTlnwhJl4oUU7IsivwpJpD5MQEHxEGNAZIoBo2gVITOEBZx4 SYQROoUypTRCA== Date: Fri, 27 Sep 2024 19:56:30 -0700 From: Frederick Eaton To: Michael J Gruber Subject: Re: searching for a message by path Message-ID: <20240928025630.km2tcgjgt3xub4jo@localhost> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Message-ID-Hash: MITPOODGGJLCRIHV4R2A56FICBOEQLQR X-Message-ID-Hash: MITPOODGGJLCRIHV4R2A56FICBOEQLQR X-MailFrom: frederik@ofb.net X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-notmuch.notmuchmail.org-0 CC: Pengji Zhang , notmuch@notmuchmail.org, Panayotis Manganaris X-Mailman-Version: 3.3.3 Precedence: list Reply-To: frederik@ofb.net 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"; format="flowed" Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_IN X-Migadu-Country: DE X-Migadu-Queue-Id: 28D2187CF7 X-Migadu-Scanner: mx10.migadu.com X-Migadu-Spam-Score: 2.42 X-Spam-Score: 2.42 X-TUID: Xm0xVbpLep6z Thank you all for your helpful replies. It seems pretty clear that the recommended Notmuch usage for someone who wants to incorporate a script that classifies a batch of messages, is either to write the whole script to use Notmuch from the beginning, and to have the messages specified as a list of "id:" IDs or even a general Notmuch query; or, if you are using an existing script that accepts a list of files, to try to extract the message ID from each file at the end so that the new tags can be communicated from the script back to Notmuch. Both options seem a little hacky - especially since it is rather common to receive multiple distinct messages with the same ID, for example when someone replies to a mailing list post and Cc's me, and I would want these to be separately viewable (they are linked together ith an "=" in the Mutt thread view) for security reasons. If Notmuch is meant to function as an abstraction layer over message files stored on the file system, then why doesn't it p rovide a standard way to go from file paths to Notmuch messages? As for why it would be a security issue to ignore new messages with duplicate message IDs, consider that one can apparently play the following game on a Notmuch user. (1) Send a private email that the user will never see because it contains spam keywords. (2) Send a public email to a mailing list with the same ID. The Notmuch user will not see the second email, and everyone will think he is unable to reply to the allegations it presumably contains, and that he is therefore guilty and should be arrested. My recommendation would be to split the Notmuch project into three teams: one to work on the source code, another on the documentation, and a third on test cases. There should be separate Git repositories for each team, so that I can for example run current test cases against a fork of the source repo, or use recent manual pages with an older version of the source. This way, the documentation team will be able to document deficiencies in various source releases as well as standardizing proposed new features or syntax. Or, someone would submit a pull request to the source team, that would then be discussed on the mailing list or in the issue tracker, and someone on another team would then use that discussion to write documentation or test cases before the PR is accepted. The teams would have a "checks and balances" relationship, like with the three branches of government. (I think that all software projects should be run this way, so please don't be offended.) I wrote some Perl scripts a long time ago, which work together to tag mail and put links to each message in a tag-specific directory for each of its tags. The script would add headers to the message, however, and it rewrote the Message-ID if it wasn't unique. It did not create a full-text index like Notmuch does. It did seem fairly reliable. I am trying to adapt it to send the tags to Notmuch. I am having to use Notmuch because of a third piece of software that depends on it. It is somewhat perplexing to me that no one else has had my use case before. Best wishes, Frederick On Sat, Sep 21, 2024 at 11:38:18AM +0200, Michael J Gruber wrote: >Am Sa., 21. Sept. 2024 um 05:23 Uhr schrieb Frederick Eaton : >> >> Thank you for your response, Pengji. >> >> On Sat, Sep 21, 2024 at 08:25:10AM +0800, Pengji Zhang wrote: >> >Hi Frederick, >> > >> >Frederick Eaton writes: >> > >> >>I am trying to figure out how to adapt a script I wrote for >> >>filtering messages, to apply notmuch tags to each message. A >> >>difficulty is that the messages are already in the Notmuch database, >> >>because another tool has delivered them to a maildir and run >> >>"notmuch new". >> >> >> >>Now, Notmuch can provide me with the paths of all the new >> >>(unfiltered) messages, which I can give to my script. The question I >> >>have is, once the filter is done, how can the script tell Notmuch >> >>which message to apply the tags to? >> > >> > >> >I am not sure if I understand you correctly. If the problem here is to >> >distinguish existing messages and new messages, would the config >> >option 'new.tags' work? For example, use >> > >> > notmuch config set new.tags new >> > >> >to give all new messages a 'new' tag. >> >> No, I already have that configuration. The first sentence described what I already know how to do, the second sentence is what I'm trying to do. > >It seems that we're still guess-working-out what your script is >doing/trying to do. Do you mind sharing a trimmed down version? > >> It might be useful for the reasons I stated, namely in case the Message-ID does not exist or is not unique. > >This is probably at the heart of the problem. Within notmuch, a >"message" is something identified by a message-id (mid), and all >information in the notmuch database is tied to a mid. > >When you speak about a message, you probably mean the content of an >individual "message file" - which is a natural, but different notion. >A "path:" refers to a message file, a "mid:" to message id. > >When "notmuch new" encounters a new message files, it >- checks if it contains a valid "Message-ID" header >- used that as mid or generates a mid using a sha1 checksum of the message file >- checks whether that mid (!) is in the database already >- adds the path to the existing db entry, or creates a new db entry > >So, you may have several files (path entries) for the same mid, and >which one is used for indexing purposes depends on the order of >arrival (or, in the case of reindexing, probably on file system >ordering). notmuch assumes that this makes no difference - same mid >same "message". This assumption can break, for example for list >copies, different headers on sent versus received etc. > >I"m elaborating on this because we have to guess about your script - >what is a "new message" for your script, and which kind of information >does it want to process? > >Typical processing would be done in a notmuch post-hook, and it would: >- check for new messages (tag:new) >- get their file paths form `notmuch search --output=files mid:XYZ` or such >- do whatever it needs using the file if you really need to parse that yourself > >I guess most of us have some sort of script running on new messages as >part of a hook, be it `afew` or something homegrown, and this >typically clears the new tag afterwards. > >Michael > On Tue, Sep 24, 2024 at 11:09:26AM +0200, Michael J Gruber wrote: >Am Sa., 21. Sept. 2024 um 18:24 Uhr schrieb Panayotis Manganaris >: >... >> notmuch search --output=messages 'tag:new' > /tmp/msgs >> notmuch search --output=files 'tag:new' |\ >> bogofilter -o0.7,0.7 -bt |\ >> paste - /tmp/msgs |\ >> awk '$1 ~ /S/ { print "-new +spam", "-", $3 }' |\ >> notmuch tag --batch >> >... >> This script operates on the assumption that the order of results from notmuch queries are >> always the same, which is fortunately true. > >It also operates under the assumption that you receive no duplicate >messages with the same message-id (such as list copies, >sent/reveived), or else `paste` will have a hard time matching lines. > >Note that you can loop over the msgs, treat them individually, and >still collect input for `notmuch tag --batch`, which solves both the >problem with duplicate messages and potential ordering instability >while keeping batch efficiency. > >> Your instinct to use batch tagging and id: queries is correct. I collect my new message ids in >> /tmp/msgs. These ids are unique, they are definitely unique enough to be used to tag individual >> messages on a daily basis. > >I'm sorry, but either they're unique or not. What's unique enough? I'm >pestering on this because part of the OP's problem is being clear >about the notion of message, which is uniquely identified by a message >id in the notmuch db. I tried to clear that up in my previous answer >in this thread. > > >> > It might be useful for the reasons I stated, namely in case the Message-ID does not exist or >> > is not unique. >> >> I think mail that is successfully transmitted through a mail host necessarily obtains a message >> id, but I might be wrong. I believe notmuch indexes on both it's own unique thread ids and the >> message ids. Thereby further decreasing the already minuscule chance of message id collisions. > >No. Messages can arrive without mid. In that case, notmuch creates one >(without altering the message file) and uses it for indexing. >"Thread-id" is something completely different from message-ids. They >do not identify a message uniquely (but a thread of messages "joint" >by references), albeit indirectly (such as "root message of the >thread", assuming one root). > >Cheers >Michael >