mirror of
https://github.com/mjl-/mox.git
synced 2024-12-26 16:33:47 +03:00
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:
parent
77d78191f8
commit
5a4f35ad5f
5 changed files with 39 additions and 1 deletions
|
@ -387,8 +387,12 @@ func TestLogin(t *testing.T) {
|
|||
tc.close()
|
||||
|
||||
tc = start(t)
|
||||
defer tc.close()
|
||||
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("ok", "logout")
|
||||
|
|
|
@ -336,6 +336,7 @@ func (p *parser) xlocalpart() smtp.Localpart {
|
|||
|
||||
// ../rfc/5321:2324
|
||||
func (p *parser) xquotedString(islocalpart bool) string {
|
||||
p.xtake(`"`)
|
||||
var s string
|
||||
var esc bool
|
||||
for {
|
||||
|
|
|
@ -1133,3 +1133,34 @@ func TestPostmaster(t *testing.T) {
|
|||
testDeliver("postmaster@mox.example", nil) // Postmaster address without explicitly configured destination.
|
||||
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)
|
||||
}
|
||||
|
|
1
testdata/imap/domains.conf
vendored
1
testdata/imap/domains.conf
vendored
|
@ -6,6 +6,7 @@ Accounts:
|
|||
Domain: mox.example
|
||||
Destinations:
|
||||
mjl@mox.example: nil
|
||||
""@mox.example: nil
|
||||
JunkFilter:
|
||||
Threshold: 0.95
|
||||
Params:
|
||||
|
|
1
testdata/smtp/domains.conf
vendored
1
testdata/smtp/domains.conf
vendored
|
@ -7,6 +7,7 @@ Accounts:
|
|||
Destinations:
|
||||
mjl@mox.example: nil
|
||||
mjl@mox2.example: nil
|
||||
""@mox.example: nil
|
||||
JunkFilter:
|
||||
Threshold: 0.9
|
||||
Params:
|
||||
|
|
Loading…
Reference in a new issue