How to forward only emails with PDF attachments to another address & IMAP folder — others to INBOX? (mapping/delivery bug?)

Hi all,

I’m running into a persistent Virtualmin/Postfix/Dovecot issue after trying to set up advanced mail processing for a single mailbox (invoice@…).
Initial goal:

  • If an incoming email has a PDF attachment: forward it to an external address (for example, Zenvoices) andmove it to a specific IMAP folder (Doorgestuurd naar ZenVoices).
  • If no PDF is attached: deliver normally to INBOX.

I tried to achieve this using Dovecot Sieve (managesieve) scripts, in combination with Virtualmin’s “forward to other address” GUI option.
At some point, after toggling forwards and adjusting Sieve/procmail logic several times, mail delivery for this user stopped entirely:

  • Local and external emails to this user no longer arrive.
  • No delivery attempt or errors appear in /var/log/procmail.log.
  • Other users/mailboxes on the same domain work fine — receive local shell mail and external mail without issues.
  • Disabling/removing forwards and Sieve scripts doesn’t resolve it.
  • Removing dovecot-sieve and dovecot-managesieved (package removal) didn’t help.
  • File and mailbox permissions, quota, directory structure — all correct.

Only removing and recreating the user in Virtualmin solves it, but that resets all mapping and I’d prefer a less destructive approach.

Main question:

  • How can I achieve conditional forwarding/filing like this (PDF → forward & move to folder, rest → INBOX) in Virtualmin with Postfix/Dovecot?
  • What’s the best method for this: Sieve, Procmail, or something else? (GUI integration preferred, but I’ll take any robust approach.)
  • And: Is there a way to “refresh” or repair Virtualmin/Postfix user mapping/index after Sieve/forwarding experiments, without removing the user?

My setup:

  • Debian 12
  • Virtualmin/Webmin (latest)
  • Dovecot + Postfix (Maildir, local delivery via procmail-wrapper)
  • No user-specific .procmailrc for this user (just global defaults)

Would really appreciate:

  • A proven Sieve or procmail recipe for this conditional delivery (PDF vs not PDF)
  • How to avoid “ghost mailbox”/mapping problems after toggling Sieve/forwards in Virtualmin
  • Any command or workflow to re-index/refresh users and aliases without deleting the mailbox

Many thanks in advance!

Woozy

This may help

  1. log into usermin as the mail user
  2. select manage folders & add a new folder you want the emails with attachments to go to
  3. select email filters and create a new filter


so test the header for Content-Type that contains multipart/mixed; boundary= (this indicates an attachment)
if there is a match save it to the folder you made earlier.
There is a gotcha here, if an incoming email contains any attachment it will be placed in the selected folder. So this may help you out or make things worse depending on if you receive loads of different attachments to that email address