First, start by reading RFC 3834. It gives some good insights into what you care about. (It covers autoresponders, not forwarding, but it's still useful.)
In general, you'll want to add an X-header to the message during forwarding to indicate that the message has been delivered to the user's mailbox once. (This is what the Sieve RFC mentions in its redirect section.) If a message comes in for bob@example.com
and there's an X-header mentioning bob@example.com
, you have a loop. So something like this:
X-YourServer-Delivered: bob@example.com
You'll also want to avoid forwarding message delivery notifications, which should have <>
as the SMTP MAIL FROM. And don't forward autoresponder messages, which should have an Auto-Submitted
header with a value other than "no".
Look over RFC 3834 for more ideas on what not to forward, but the above should cover most cases.