title: Exim: Forward Based on Recipient in bcc
body: <p>Currently I am filtering incoming mails by a .forward in the following way:</p>
  
  <pre><code>if $header_to: matches "(office|info)@domain.com" then
      save Maildir/.office/
  endif
  if $header_to: matches "whatever@domain.com" then
      save Maildir/.whatever/
  endif
  </code></pre>
  
  <p>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.</p>
  
  <p>This works for mails where the recipient is in the <code>to</code>-header, but does not work if the recipient was in the <code>bcc</code>.</p>
  
  <p>When a mail is received which was sent with the <code>bcc</code>-header, only the <code>envelope-to</code>-header matches the real address the mail is delivered to and it is mentioned in a <code>Received</code>-header</p>
  
  <pre><code>Envelope-to: office@domain.com
  
  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 &lt;sender@other.domain&gt;)
      id 1RO5xc-0001TF-Qj
      for office@domain.com; Wed, 09 Nov 2011 12:04:57 +0100
  ...
  To: can_be_anything@whatever.com
  </code></pre>
  
  <p>I already tried:</p>
  
  <pre><code>if $header_envelope-to: matches ...
  </code></pre>
  
  <p>but this does not work, mails are not filtered at all even when sent with <code>To</code>-header (looks like the <code>Envelope-To</code>-header is not available in forward-files). Should I try to parse the (multiple) <code>Received</code>-headers?</p>
  
  <p>How can I move mails into a subdir of the recipient based on the <em>real</em> recipient address?</p>