Skip to content

Commit

Permalink
add "RcptTo" to webapi MessageGet result
Browse files Browse the repository at this point in the history
otherwise, if the recipient was a bcc, there's no good way to see why the
message was received.

incoming webhooks already have this rcptto field, but that's not always the
moment you want to process it.

for mattanja on matrix, thanks for reporting!
  • Loading branch information
mjl- committed Sep 30, 2024
1 parent a7bdc41 commit b0c4b09
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
5 changes: 3 additions & 2 deletions webapi/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,10 @@ Get a message in parsed form:
"$notjunk",
"\seen"
],
"MailFrom": "",
"MailFrom": "mox@localhost",
"RcptTo": "mox@localhost",
"MailFromValidated": false,
"MsgFrom": "",
"MsgFrom": "mox@localhost",
"MsgFromValidated": false,
"DKIMVerifiedDomains": [],
"RemoteIP": "",
Expand Down
5 changes: 3 additions & 2 deletions webapi/gendoc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,10 @@ Get a message in parsed form:
"\$notjunk",
"\\seen"
],
"MailFrom": "",
"MailFrom": "mox@localhost",
"RcptTo": "mox@localhost",
"MailFromValidated": false,
"MsgFrom": "",
"MsgFrom": "mox@localhost",
"MsgFromValidated": false,
"DKIMVerifiedDomains": [],
"RemoteIP": "",
Expand Down
3 changes: 2 additions & 1 deletion webapi/webapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,9 @@ type MessageMeta struct {
Size int64 // Total size of raw message file.
DSN bool // Whether this message is a DSN.
Flags []string // Standard message flags like \seen, \answered, $forwarded, $junk, $nonjunk, and custom keywords.
MailFrom string // Address used during SMTP "MAIL FROM" command.
MailFrom string // Address used during SMTP "MAIL FROM" command. Unicode.
MailFromValidated bool // Whether SMTP MAIL FROM address was SPF-validated.
RcptTo string // Address delivered to with SMTP "RCPT TO" command. Unicode.
MsgFrom string // Address used in message "From" header.
MsgFromValidated bool // Whether address in message "From"-header was DMARC(-like) validated.
DKIMVerifiedDomains []string // Verified domains from DKIM-signature in message. Can be different domain than used in addresses.
Expand Down
5 changes: 5 additions & 0 deletions webapisrv/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1245,12 +1245,17 @@ func (s server) MessageGet(ctx context.Context, req webapi.MessageGetRequest) (r
if d, err := dns.ParseDomain(m.MsgFromDomain); err == nil {
msgFrom = smtp.NewAddress(m.MsgFromLocalpart, d).Pack(true)
}
var rcptTo string
if m.RcptToDomain != "" {
rcptTo = m.RcptToLocalpart.String() + "@" + m.RcptToDomain
}
meta := webapi.MessageMeta{
Size: m.Size,
DSN: m.DSN,
Flags: append(m.Flags.Strings(), m.Keywords...),
MailFrom: m.MailFrom,
MailFromValidated: m.MailFromValidated,
RcptTo: rcptTo,
MsgFrom: msgFrom,
MsgFromValidated: m.MsgFromValidated,
DKIMVerifiedDomains: m.DKIMDomains,
Expand Down

0 comments on commit b0c4b09

Please sign in to comment.