Search code examples
emailfiltereximbccexim4

Exim: Forward Based on Recipient in bcc


Currently I am filtering incoming mails by a .forward in the following way:

if $header_to: matches "(office|info)@domain.com" then
    save Maildir/.office/
endif
if $header_to: matches "[email protected]" then
    save Maildir/.whatever/
endif

So I have a mail account, which receives mails for different addresses. Basically I want them to land in different subdirs based on the address the mail was sent to.

This works for mails where the recipient is in the to-header, but does not work if the recipient was in the bcc.

When a mail is received which was sent with the bcc-header, only the envelope-to-header matches the real address the mail is delivered to and it is mentioned in a Received-header

Envelope-to: [email protected]

Received: from mail.other.domain ([1.1.1.1])
    by mail.domain.com with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32)
    (Exim 4.71)
    (envelope-from <[email protected]>)
    id 1RO5xc-0001TF-Qj
    for [email protected]; Wed, 09 Nov 2011 12:04:57 +0100
...
To: [email protected]

I already tried:

if $header_envelope-to: matches ...

but this does not work, mails are not filtered at all even when sent with To-header (looks like the Envelope-To-header is not available in forward-files). Should I try to parse the (multiple) Received-headers?

How can I move mails into a subdir of the recipient based on the real recipient address?


Solution

  • looks like I finally found the answer.

    if $original_local_part matches "office|info" then
        save Maildir/.office/
    endif
    

    This checks only the local_part, but afaik could be extended to use the domain, too, with $original_domain (see the doc)