[GH-ISSUE #245] reply not working when envelope-from / return-path is sent by client #782

Closed
opened 2026-03-14 10:34:03 +03:00 by kerem · 3 comments
Owner

Originally created by @eleith on GitHub (Dec 29, 2021).
Original GitHub issue: https://github.com/anonaddy/anonaddy/issues/245

in the documentation, anonaddy has postfix pass emails to the application as such

anonaddy unix - n n - - pipe
  flags=F user=johndoe argv=php /var/www/anonaddy/artisan anonaddy:receive-email --sender=${sender} --recipient=${recipient} --local_part=${user} --extension=${extension} --domain=${domain} --size=${size}

anonaddy's reply logic in ReceiveEmail.php depends on ${sender}

however, according to postfix's pipe documentation, ${sender} is derived from the sender envelope from (as opposed to directly using the From header).

mail clients / services that want to track bounces set the Return-Path header with an alternate email address. This email address is also referred to as the envelope-from address. Thus, when set, the ${sender} will refer to this alternate email address and not the From address.

as a result, this bounce email address will not match any valid recipients and thus all replies will fail to go through.

this issue can be worked around, if after parsing the raw email, you extract the sender using the following method

    protected function getSenderFrom()                 
    {                                                            
        $from = $this->parser->getHeader('From');     
                                                                        
        try {     
          $senderFromParsed = mailparse_rfc822_parse_addresses($from);   
          return $senderFromParsed[0]['address'];    
        } catch(\Exception $e) {  
          return $this->option('sender');                                             
        }                                
    } 

and pass that value into the various recipient verification calls used to validate and then eventually send the reply.

Originally created by @eleith on GitHub (Dec 29, 2021). Original GitHub issue: https://github.com/anonaddy/anonaddy/issues/245 in the [documentation](https://anonaddy.com/self-hosting/), anonaddy has postfix pass emails to the application as such ``` anonaddy unix - n n - - pipe flags=F user=johndoe argv=php /var/www/anonaddy/artisan anonaddy:receive-email --sender=${sender} --recipient=${recipient} --local_part=${user} --extension=${extension} --domain=${domain} --size=${size} ``` anonaddy's reply logic in [ReceiveEmail.php](https://github.com/anonaddy/anonaddy/blob/master/app/Console/Commands/ReceiveEmail.php#L144) depends on `${sender}` however, according to [postfix's pipe documentation](http://www.postfix.org/pipe.8.html), `${sender}` is derived from the sender envelope from (as opposed to directly using the `From` header). mail clients / services that want to track bounces set the `Return-Path` header with an alternate email address. This email address is also referred to as the envelope-from address. Thus, when set, the `${sender}` will refer to this alternate email address and not the `From` address. as a result, this bounce email address will not match any valid recipients and thus all replies will fail to go through. this issue can be worked around, if after [parsing the raw email](https://github.com/anonaddy/anonaddy/blob/master/app/Console/Commands/ReceiveEmail.php#L71), you extract the sender using the following method ```php protected function getSenderFrom() { $from = $this->parser->getHeader('From'); try { $senderFromParsed = mailparse_rfc822_parse_addresses($from); return $senderFromParsed[0]['address']; } catch(\Exception $e) { return $this->option('sender'); } } ``` and pass that value into the various recipient verification calls used to validate and then eventually send the reply.
kerem closed this issue 2026-03-14 10:34:08 +03:00
Author
Owner

@eleith commented on GitHub (Dec 29, 2021):

i would prefer a way to do this in postfix directly, but haven't found a way to do this yet.

<!-- gh-comment-id:1002814354 --> @eleith commented on GitHub (Dec 29, 2021): i would prefer a way to do this in postfix directly, but haven't found a way to do this yet.
Author
Owner

@willbrowningme commented on GitHub (Jan 4, 2022):

Thanks, I was aware of this but didn't think it would be an issue as the vast majority reply from an email that has the same envelope-from as the "From:" header.

I'll try to sort a fix for this soon, however since the "From:" header can easily be spoofed the server must have appropriate DMARC, SPF and DKIM checks in place if you are self-hosting. I'll check the self-hosting instructions to make sure this is added when setting up Rspamd.

<!-- gh-comment-id:1004797772 --> @willbrowningme commented on GitHub (Jan 4, 2022): Thanks, I was aware of this but didn't think it would be an issue as the vast majority reply from an email that has the same envelope-from as the "From:" header. I'll try to sort a fix for this soon, however since the "From:" header can easily be spoofed the server must have appropriate DMARC, SPF and DKIM checks in place if you are self-hosting. I'll check the self-hosting instructions to make sure this is added when setting up Rspamd.
Author
Owner

@willbrowningme commented on GitHub (Feb 4, 2022):

This has been fixed in the latest release v0.9.0.

<!-- gh-comment-id:1029921564 --> @willbrowningme commented on GitHub (Feb 4, 2022): This has been fixed in the latest release [v0.9.0](https://github.com/anonaddy/anonaddy/releases/tag/v0.9.0).
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/anonaddy#782
No description provided.