mirror of
https://github.com/axllent/mailpit.git
synced 2026-04-26 00:35:51 +03:00
[GH-ISSUE #149] ReturnPath contains the 822.From, not the 821.From #102
Labels
No labels
awaiting feedback
bug
docker
documentation
enhancement
github_actions
invalid
pull-request
question
stale
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/mailpit#102
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @wttw on GitHub (Aug 4, 2023).
Original GitHub issue: https://github.com/axllent/mailpit/issues/149
The response to /api/v1/message/{ID} contains a field ReturnPath. I would expect that field to contain the return path - the email address provided via MAIL FROM: in the SMTP transaction. Instead it contains the address from the From: header.
e.g. when delivering an email like this
I would expect ReturnPath to contain
steve@jiji.local, while it actually containsbodyfrom@example.comIt looks like MailPit is expecting to read the return path from a Return-Path header in the stored mail, but it isn't populating that header from the contents of MAIL FROM: when it's received. Then when it can't find the header it uses the contents of the From: header instead.
@axllent commented on GitHub (Aug 4, 2023):
That's a valid point and a good observation @wttw. The only potential flaw I can find in your PR is that a
Return-Pathheader will always gets added to the mail ~ but what if aReturn-Pathalready exists in the mail headers, as this would lead to multiple Return-Paths which isn't compliant?I must admit that since I wrote Mailpit, I've come to discover that every mail server and SMTP client variant seems to work slightly differently, and many SMTP servers have fallback solutions to handle these to achieve greater compatibility and fewer delivery issues. It is also often very difficult to find black&white explanations as to how to "officially" deal with these situations. From what I can tell, a receiving SMTP server should always overwrite the Return-Path using the From envelope (as you have suggested).
I actively try to avoid removing any headers in the SMTPD as this creates complications because it reorders and groups the message headers (due to Go's map ordering). Using regular expressions to strip out a header is an option, but can lead to complications too. I wonder if the safest approach here would be to only add the
Return-Pathheader (as you have done) when there isn't already one set? Whilst not strictly compliant, it does then cater for other "mail injection" situations (for instance I use Mailpit to "archive" my regular mail accounts for testing, so emails are read from plain text files and "pushed" to the SMTP server).Keen to hear your thoughts before I make any decision on approach.
@axllent commented on GitHub (Aug 4, 2023):
Actually I think the following solution would work far better (to replace your solution):
This seems to cover all bases:
Return-Pathis already correctly set, do nothing, elseReturn-Pathexists remove itReturn-PathIf my logic makes sense, please update your MR with the above code and I'll merge it in, thanks.
@axllent commented on GitHub (Aug 6, 2023):
I've actually gone ahead and made the change, as what I provided in my earlier comment had a few issues. This has been released as v1.8.1. Please feel free to reopen if it does not do what you were expecting. I'll also close your PR as that has been superseded by the change I made. Thanks though for your info/contribution, I appreciate it!