qmail-inject sieve vacation/reject messages trouble

Last week me and a couple of friends dealed with a trouble which engaged us for many hours, until Stéphane Cottin sent me this patch after 3 minutes from my request!

The problem

Create a sieve rule which rejects the incoming messages for vacation or whatelse and you will see that it will bounce back because of a syntax error in the sender address. And if you look to the smtp conversation this is what you would see:

@400000004e2e94a60345ab5c 2604 < MAIL FROM:<"<>"@domain.xy>
@400000004e2e94a603496864 CHKUSER rejected sender: from <<>@domain.xy::> remote <domain.xy:unknown:123.456.789.123
@400000004e2e94a70352fd84 2604 > 553 5.1.7 sorry, mailbox syntax not allowed (chkuser)

The reason is in the qmail-inject man page:

Default host name.  Default:  me, if that is  supplied; otherwise  the literal name defaulthost, which is probably not what you want.  qmail-inject adds this name to any  address without a host name.

Usually the null sender <> belongs to system's messages, but in this case it has been rewrited with <>@domain.xy and this is causing the rejection.

As you can see, the patch gets qmail-inject to avoid the rewrite of the null sender:

2011-07-26 15:22:10.244210500 8001 < MAIL FROM:<>
2011-07-26 15:22:10.244465500 CHKUSER accepted sender: from <::> remote <domain.xy:unknown:123,456.789.123> rcpt <> : accepted null sender always
2011-07-26 15:22:10.245288500 8001 > 250 ok