Is it possible to delete all mail in which the subject matches a regex pattern?
For example, to delete message 1, you do:
d 1
But to delete all mail with subject starting with, say, [SPAM]
, I can't do:
d -s "^\[SPAM\].*$"
Is it possible to delete all mail in which the subject matches a regex pattern?
For example, to delete message 1, you do:
d 1
But to delete all mail with subject starting with, say, [SPAM]
, I can't do:
d -s "^\[SPAM\].*$"
I am answering this in case anyone comes by the same question.
It does not appear there is any way to do bulk deletion by pattern matching using mail
.
An alternative is to use the mutt
mail client, which does have such feature:
D \[SPAM\]
Thanks to @thrig and @dirkt for suggesting the alternative.
d/[SPAM]
, but I haven't tested it.
– nehcsivart
Jun 14 '19 at 18:10
mutt -f /home/user-account/mail/.email\@example_com/
, then D
, then Test
.
– rinogo
Aug 06 '21 at 13:57
According to "man mail" there are plenty of different patterns to specify the messages on which the command like "d" for deletion will work on. For the asked subject line, you can use
(subject string)
All messages that contain string in the Subject: field.
In the mail command you would write:
& d (subject Happy Birthday)
This will delete every mail that has the string "Happy Birthday" in its subject. There are also patterns for other fields and different date related criterions (It was tested with "Heirloom Mail version 12.4 7/29/08.")
Bad SEARCH criterion "Birthday": >>> (subject Happy Birthday) <<<
– rinogo
Aug 06 '21 at 13:50
I was looking for the same without success, so I decided to try like this:
echo 'f 1-$' | mail -N | grep 'SPAM' | awk '{print $1}'
Or print $0
to see the full header to show the mail number with the string 'SPAM'.
So if you think is ok you can delete all of this.
echo 'd #1 #2 #3 ...' | mail -N
Or make a full script.
mutt
? That can match-and-then-delete by pattern. – thrig Jan 17 '17 at 18:24mutt
:D
to delete all messages matching a pattern, and you can more generally and flexible tag messages according to your needs, and then apply some action to them. – dirkt Jan 17 '17 at 18:24mutt
. – nehcsivart Jan 17 '17 at 18:28