Re: Looking for a simple `Filter_classifier` program
Charles Cazabon <[email protected]> Sun, 6 Nov 2022 19:46:50 -0600
| Newsgroups | gmane.mail.getmail.user |
|---|---|
| Message-ID | <[email protected]> |
Francesco Ariis <[email protected]> wrote: > > I filter/delete/highlight messages in my email client (mutt) using simple > regexps like > > =f mergify[bot] !~b \^Merged > # getmail mergified messages Okay. Good choice with mutt. > This is fine but as I add up more regexps, everything becomes slower and > more unwieldy. So I read getmail manual and found `Filter_classifier`. > > It seems to do what I want but each example I find on the Internet is about > ham/spam, while I am looking for something slightly different (classifying > some messages in different categories). Classifier filters don't change the message, except that the output of the filter is inserted into new X-getmail-filter-classifier: header field(s). The filter program/script doesn't (and shouldn't) output any of the message, just what it wants added to the message header by getmail. So you can have your script read the message from stdin and output different things based on what it finds. It might print "mergified" or "autoresponse" or your favourite literary quote, whatever. On success - ideally always - your script should exit 0. By default, if the program exits 99 or 100, getmail will drop the message entirely, and any other nonzero exit code will be treated as an error; getmail will abort processing the message and leave it on the server so it's not lost. These values can be configured. getmail will add its output to the new header file and continue processing the message - running it through other filters, if you have them configured, or to the delivery destination. So you could configure mutt to highlight messages based on the content of the new header field, and it would automatically highlight them based on your filter's results. One tip that may not be obvious from the documentation: stdin as supplied to your filter program is actually attached to a real file, so if necessary, your script can rewind it rather than having to buffer the message content if it wants to process it more than once. Charles -- ----------------------------------------------------------------------- Charles Cazabon GPL'ed software available at: http://pyropus.ca/software/ -----------------------------------------------------------------------