Migrating Apple Mail filters to Sieve scripts with Dovecot

How I migrated all my Apple Mail filters to Sieve scripts running on my email server, so that my email inbox is clean on my phone and does not depend on my laptop to apply filtering.