For cases like the one you have in mind, it is necessary to use a
milter.
Thank you for saving me some head scratching. It wouldn't be the end
of the world to spin up an Exim VM (its system_filtering is capable of
this black magic), but would prefer staying in Postfix.
Do you have a milter in mind for this task?
MIMEDefang could do it: a few lines of Perl in the filter() callback.
Yes, that would be the standard milter to do what you want. But if I were
you I would ask myself if what you'd like to do is really necessary, and
worth the price of maintaining a specific tool for it.
Note also that, if you control more than Postfix, it might be possible to
do what you want outside of Postfix. For example, if you have a Dovecot
server behind your Postfix, you could do what you want with Sieve filters.
Gregory