I want to be able to delete specific email message from all mailboxes of one domain, does Dovecot has this type of functionality OR are there any known good solution for this? It's Maildir
format and the domain is represented as /var/vmail/domain.tld/
.
The problem
many disposable, one-shot bulk emails, often with multi-megabyte attachments.
What have I tried
I have looked to doveadm Batch, Altmove, Expunge commands, none of which seems to do the (exactly this type of) job?
What I'd like to avoid if possible
The last resort: grep
recursively by either Message-ID
header or ESMTP id
part of one of the multiple Received
headers.
EDIT: Thanks for comments and answer so far, by reading them I realize that I failed to make a point: it is not a SPAM issue - those bulk emails are perfectly legitimate but after a while completely unnecessary and since they weigh multi MBs the storage problem needs to be prevented.
Doveadm can move or expunge mails, offering pretty much all the filters needed for this task.
First, try your filters using a read-only command, such as
fetch
, so you do not move or delete more mail than intended:The syntax for the search is documented in
man doveadm-search-query
, but the precise query is still up to you - what is a good selection for you?Note that deleting purely by message-id leads to unpleasant side-effects in the form of lost mail, as spammers and/or software bugs occasionally recycle meant-to-be-unique IDs.
When selecting copies or variants of essentially the same mail, you probably want to use some combination of date, relaying server and header value. If you only care about size, selecting by age and size should do the trick.
How to limit your command to a single domain?
If your mail account names look like
[email protected]
, pass a wildcard:If your mail account names are less predictable names, supply a fixed list:
Try doveadm fetch -u *@yourdomain.com 'hdr.from hdr.subject' FROM [email protected]
Using doveadm -u will bring up an error as it doesn't know it's subset to run with.