Hi Frederick,
* Frederick Eaton <frede...@ofb.net> [2024-09-20; 20:23 -07]:
> On Sat, Sep 21, 2024 at 08:25:10AM +0800, Pengji Zhang wrote:
>>Frederick Eaton <frede...@ofb.net> 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?
[...]
> Suppose the filter script reads a message from a particular file and decides 
> that it is spam. How does the filter tell Notmuch that the message 
> corresponding to that file is spam? You seem to be saying below that the 
> filter script should extract the Message-ID and use it to identify the 
> message to Notmuch, since file paths of the messages are not indexed. 
> Probably what my script should be doing for each message is appending a line 
> to a batch file like this:
>
>      +spam -new -- id:some_message_id@foo
>      +inbox -new -- id:some_other@baz
>
> and then passing the batch file to "notmuch tag"?

Yes.  I assume your script somehow loops
over directories and picks up one file
at a time investigating it and then
decides if it is spam.  Then what you
wrote above is the way to go.

The possibility that the Message-ID of
two different emails might be identical,
is real, but that's luckily mostly the
case for spam messages in my experience.

But there is a safety hatch:  While
notmuch cannot search by file names, it
is able to output file names, like so:

notmuch search --output=files -- id:"100822114556.gc10...@example.com/"

If you want to be extra cautious you
could start with a file, get the
Message-ID from it, decide upon the
email in the file, then search for file
names which notmuch associates to the
Message-ID and in case of several file
names, check them in turn...  In case of
the spam/ham decision, you then would
have to decide what to do, if some files
containing emails with the same
Message-ID are spam and others are ham,
since these are usually considered to be
mutually exclusive.
But I would be astonished if you would
find such a case in a real file corpus
of emails.


HTH, Gregor
_______________________________________________
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org

Reply via email to