From b0c4b090102cfdcb3a2ef112fc3f4487ec21ea40 Mon Sep 17 00:00:00 2001 From: Mechiel Lukkien Date: Mon, 30 Sep 2024 10:43:48 +0200 Subject: [PATCH] add "RcptTo" to webapi MessageGet result 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! --- webapi/doc.go | 5 +++-- webapi/gendoc.sh | 5 +++-- webapi/webapi.go | 3 ++- webapisrv/server.go | 5 +++++ 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/webapi/doc.go b/webapi/doc.go index 0b9019fefb..73b3e7e4cc 100644 --- a/webapi/doc.go +++ b/webapi/doc.go @@ -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": "", diff --git a/webapi/gendoc.sh b/webapi/gendoc.sh index 151995aea1..e7444dd3d6 100755 --- a/webapi/gendoc.sh +++ b/webapi/gendoc.sh @@ -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": "", diff --git a/webapi/webapi.go b/webapi/webapi.go index 823cc6707d..6ddf8f4bf7 100644 --- a/webapi/webapi.go +++ b/webapi/webapi.go @@ -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. diff --git a/webapisrv/server.go b/webapisrv/server.go index a1daebdb07..448c433778 100644 --- a/webapisrv/server.go +++ b/webapisrv/server.go @@ -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,