Cyrus Patch for Sieve

This patch adds a feature that enables the change of the MAIL FROM envelope address on redirect and vacation messages. Currently, in a redirection message, only the RCPT TO address is modified by cyrus. This way, MTAs generate logs using the MAIL FROM header of the original message, which makes accounting impossible for these messages.

A similar problem exists for vacation messages, in which cyrus uses the null-sender as the MAIL FROM address.

A patch was developed to change cyrus' behaviour, so that the address on the MAIL FROM address is the email of the user the message is being sent on behalf of. The email address is obtained from the RCPT TO address of the original message.

The patch is available here.

Test cases

Below are some test cases, to compare the results with and without the patch. The sievemailfromasuser parameter was added to the imapd.conf file. If set as "no" (the default value), the behaviour is the same as how cyrus currently works.

Redirection

Email from boss@test.mz.digirati.com.br to andre@test.mz.digirati.com.br, which is redirected to test@test.mz.digirati.com.br.

With the parameter turned off:

MTA log:

Original message:

Oct 18 09:22:48 localhost postfix/qmgr[3270]: 4D433404713: from=<boss@test.mz.digirati.com.br>, size=557, nrcpt=1 (queue active)
Oct 18 09:22:48 localhost postfix/pipe[3958]: 4D433404713: to=<andre@test.mz.digirati.com.br>, relay=cyrus, delay=0, status=sent (test.mz.digirati.com.br)
    

Redirect message:

Oct 18 09:22:48 localhost postfix/qmgr[3270]: 850F0404718: from=<boss@test.mz.digirati.com.br>, size=850, nrcpt=1 (queue active)
Oct 18 09:22:48 localhost postfix/pipe[3964]: 850F0404718: to=<test@test.mz.digirati.com.br>, relay=cyrus, delay=0, status=sent (test.mz.digirati.com.br)
    

Note that the redirection didn't touch the "MAIL FROM" envelope address -- the redirect message uses the same address. This is a problem for mail accounting systems, because both addresses are potentially external to the accounting system (that is, not known by the accounting system).

With the parameter set to "yes", the redirect and auto-response messages will have the MAIL FROM address changed to the user the message is being sent on behalf of:

MTA log:

Original message:

Oct 18 09:27:08 localhost postfix/qmgr[3270]: 21CBF404713: from=<boss@test.mz.digirati.com.br>, size=576, nrcpt=1 (queue active)
Oct 18 09:27:08 localhost postfix/pipe[4049]: 21CBF404713: to=<andre@test.mz.digirati.com.br>, relay=cyrus, delay=0, status=sent (test.mz.digirati.com.br)
    

Redirect message:

Oct 18 09:27:08 localhost postfix/qmgr[3270]: 3F224404718: from=<andre@test.mz.digirati.com.br>, size=869, nrcpt=1 (queue active)
Oct 18 09:27:08 localhost postfix/pipe[4055]: 3F224404718: to=<test@test.mz.digirati.com.br>, relay=cyrus, delay=0, status=sent (test.mz.digirati.com.br)
    

Vacation

The vacation situation is similar. In this case, bar@test.mz.digirati.com.br receives a vacation message. The MTA logs for this message are shown below:

Parameter set to "no":

Oct 18 09:41:12 localhost postfix/qmgr[3270]: 48384404718: from=<>, size=539, nrcpt=1 (queue active)
Oct 18 09:41:12 localhost postfix/pipe[4261]: 48384404718: to=<bar@test.mz.digirati.com.br>, relay=cyrus, delay=0, status=sent (test.mz.digirati.com.br)
    

Parameter set to "yes". The auto-response was sent to blah@test.mz.digirati.com.br:

Oct 18 09:57:42 localhost postfix/qmgr[3270]: 1026A404718: from=<andre@test.mz.digirati.com.br>, size=541, nrcpt=1 (queue active)
Oct 18 09:57:42 localhost postfix/pipe[4497]: 1026A404718: to=<blah@test.mz.digirati.com.br>, relay=cyrus, delay=0, status=sent (test.mz.digirati.com.br)
    

Note the change from the null-sender to the user email address.


Below are other interesting test cases, used with the sievemailfromasuser set to "yes":

1 - Message sent to many recipients:

Original message:

Oct 18 10:14:35 localhost postfix/qmgr[3270]: C900D404713: from=<boss@test.mz.digirati.com.br>, size=630, nrcpt=3 (queue active)
Oct 18 10:14:35 localhost postfix/pipe[4686]: C900D404713: to=<bar@test.mz.digirati.com.br>, relay=cyrus, delay=0, status=sent (test.mz.digirati.com.br)
Oct 18 10:14:35 localhost postfix/pipe[4683]: C900D404713: to=<blah@test.mz.digirati.com.br>, relay=cyrus, delay=0, status=sent (test.mz.digirati.com.br)
Oct 18 10:14:35 localhost postfix/pipe[4681]: C900D404713: to=<andre@test.mz.digirati.com.br>, relay=cyrus, delay=0, status=sent (test.mz.digirati.com.br)
    

Redirect message:

Oct 18 10:14:35 localhost postfix/qmgr[3270]: E62CE404718: from=<andre@test.mz.digirati.com.br>, size=923, nrcpt=1 (queue active)
Oct 18 10:14:35 localhost postfix/pipe[4686]: E62CE404718: to=<test@test.mz.digirati.com.br>, relay=cyrus, delay=0, status=sent (test.mz.digirati.com.br)
    

2 - Message sent to many recipients, on the "To" and "Cc" fields. The user with the sieve redirection rule was added on the "Cc" field.

Original message:

Oct 18 10:23:44 localhost postfix/qmgr[3270]: 21FCF404713: from=<boss@test.mz.digirati.com.br>, size=660, nrcpt=3 (queue active)
Oct 18 10:23:44 localhost postfix/pipe[4805]: 21FCF404713: to=<bar@test.mz.digirati.com.br>, relay=cyrus, delay=0, status=sent (test.mz.digirati.com.br)
Oct 18 10:23:44 localhost postfix/pipe[4808]: 21FCF404713: to=<blah@test.mz.digirati.com.br>, relay=cyrus, delay=0, status=sent (test.mz.digirati.com.br)
Oct 18 10:23:44 localhost postfix/pipe[4803]: 21FCF404713: to=<andre@test.mz.digirati.com.br>, relay=cyrus, delay=0, status=sent (test.mz.digirati.com.br)
    

Mensagem de redirecionamento:

Oct 18 10:23:44 localhost postfix/qmgr[3270]: 59F82404718: from=<andre@test.mz.digirati.com.br>, size=953, nrcpt=1 (queue active)
Oct 18 10:23:44 localhost postfix/pipe[4805]: 59F82404718: to=<test@test.mz.digirati.com.br>, relay=cyrus, delay=0, status=sent (test.mz.digirati.com.br)