in smtp submission, if a fromid is present in the mailfrom command, use it when queueing

it's the responsibility of the sender to use unique fromid's.
we do check if that's the case, and return an error if not.

also make it more clear that "unique smtp mail from addresses" map to the
"FromIDLoginAddresses" account config field.

based on feedback from cuu508 for #31, thanks!
This commit is contained in:
Mechiel Lukkien
2024-04-28 13:18:25 +02:00
parent 32cf6500bd
commit 8cc795b2ec
12 changed files with 126 additions and 19 deletions

View File

@ -1898,3 +1898,48 @@ test email
ts.smtpErr(err, &smtpclient.Error{Permanent: true, Code: smtp.C554TransactionFailed, Secode: smtp.SeMsg6Other0})
})
}
// FromID can be specified during submission, but must be unique, with single recipient.
func TestUniqueFromID(t *testing.T) {
ts := newTestServer(t, filepath.FromSlash("../testdata/smtpfromid/mox.conf"), dns.MockResolver{})
defer ts.close()
ts.user = "mjl+fromid@mox.example"
ts.pass = password0
ts.submission = true
extraMsg := strings.ReplaceAll(`From: <mjl@mox.example>
To: <remote@example.org>
Subject: test
test email
`, "\n", "\r\n")
// Specify our own unique id when queueing.
ts.run(func(err error, client *smtpclient.Client) {
tcheck(t, err, "init client")
mailFrom := "mjl+unique@mox.example"
rcptTo := "mjl@mox.example"
err = client.Deliver(ctxbg, mailFrom, rcptTo, int64(len(extraMsg)), strings.NewReader(extraMsg), true, true, false)
ts.smtpErr(err, nil)
})
// But we can only use it once.
ts.run(func(err error, client *smtpclient.Client) {
tcheck(t, err, "init client")
mailFrom := "mjl+unique@mox.example"
rcptTo := "mjl@mox.example"
err = client.Deliver(ctxbg, mailFrom, rcptTo, int64(len(extraMsg)), strings.NewReader(extraMsg), true, true, false)
ts.smtpErr(err, &smtpclient.Error{Permanent: true, Code: smtp.C554TransactionFailed, Secode: smtp.SeAddr1SenderSyntax7})
})
// We cannot use our own fromid with multiple recipients.
ts.run(func(err error, client *smtpclient.Client) {
tcheck(t, err, "init client")
mailFrom := "mjl+unique2@mox.example"
rcptTo := []string{"mjl@mox.example", "mjl@mox.example"}
_, err = client.DeliverMultiple(ctxbg, mailFrom, rcptTo, int64(len(extraMsg)), strings.NewReader(extraMsg), true, true, false)
ts.smtpErr(err, &smtpclient.Error{Permanent: true, Code: smtp.C554TransactionFailed, Secode: smtp.SeProto5TooManyRcpts3})
})
}