fix delivery from/to smtp addresses with double quotes

found while adding tests for smtp and imap for address with empty double (double
quoted) localparts.
This commit is contained in:
Mechiel Lukkien 2023-06-03 15:29:18 +02:00
parent 77d78191f8
commit 5a4f35ad5f
No known key found for this signature in database
5 changed files with 39 additions and 1 deletions

View file

@ -387,8 +387,12 @@ func TestLogin(t *testing.T) {
tc.close() tc.close()
tc = start(t) tc = start(t)
defer tc.close()
tc.transactf("ok", `login "mjl@mox.example" "testtest"`) tc.transactf("ok", `login "mjl@mox.example" "testtest"`)
tc.close()
tc = start(t)
tc.transactf("ok", `login "\"\"@mox.example" "testtest"`)
defer tc.close()
tc.transactf("bad", "logout badarg") tc.transactf("bad", "logout badarg")
tc.transactf("ok", "logout") tc.transactf("ok", "logout")

View file

@ -336,6 +336,7 @@ func (p *parser) xlocalpart() smtp.Localpart {
// ../rfc/5321:2324 // ../rfc/5321:2324
func (p *parser) xquotedString(islocalpart bool) string { func (p *parser) xquotedString(islocalpart bool) string {
p.xtake(`"`)
var s string var s string
var esc bool var esc bool
for { for {

View file

@ -1133,3 +1133,34 @@ func TestPostmaster(t *testing.T) {
testDeliver("postmaster@mox.example", nil) // Postmaster address without explicitly configured destination. testDeliver("postmaster@mox.example", nil) // Postmaster address without explicitly configured destination.
testDeliver("postmaster@unknown.example", &smtpclient.Error{Code: smtp.C550MailboxUnavail, Secode: smtp.SeAddr1UnknownDestMailbox1}) testDeliver("postmaster@unknown.example", &smtpclient.Error{Code: smtp.C550MailboxUnavail, Secode: smtp.SeAddr1UnknownDestMailbox1})
} }
// Test to address with empty localpart.
func TestEmptylocalpart(t *testing.T) {
resolver := dns.MockResolver{
A: map[string][]string{
"other.example.": {"127.0.0.10"}, // For mx check.
},
PTR: map[string][]string{
"127.0.0.10": {"other.example."},
},
}
ts := newTestServer(t, "../testdata/smtp/mox.conf", resolver)
defer ts.close()
testDeliver := func(rcptTo string, expErr *smtpclient.Error) {
t.Helper()
ts.run(func(err error, client *smtpclient.Client) {
t.Helper()
mailFrom := `""@other.example`
if err == nil {
err = client.Deliver(ctxbg, mailFrom, rcptTo, int64(len(deliverMessage)), strings.NewReader(deliverMessage), false, false)
}
var cerr smtpclient.Error
if expErr == nil && err != nil || expErr != nil && (err == nil || !errors.As(err, &cerr) || cerr.Code != expErr.Code || cerr.Secode != expErr.Secode) {
t.Fatalf("got err %#v, expected %#v", err, expErr)
}
})
}
testDeliver(`""@mox.example`, nil)
}

View file

@ -6,6 +6,7 @@ Accounts:
Domain: mox.example Domain: mox.example
Destinations: Destinations:
mjl@mox.example: nil mjl@mox.example: nil
""@mox.example: nil
JunkFilter: JunkFilter:
Threshold: 0.95 Threshold: 0.95
Params: Params:

View file

@ -7,6 +7,7 @@ Accounts:
Destinations: Destinations:
mjl@mox.example: nil mjl@mox.example: nil
mjl@mox2.example: nil mjl@mox2.example: nil
""@mox.example: nil
JunkFilter: JunkFilter:
Threshold: 0.9 Threshold: 0.9
Params: Params: