mirror of
https://github.com/mjl-/mox.git
synced 2025-07-12 13:44:37 +03:00
do not require the SMTPUTF8 extension when not needed (#145)
Squashed commit of the following: commit11c25d727f
Author: Laurent Meunier <laurent@deltalima.net> Date: Sun Mar 31 12:37:09 2024 +0200 Fix style issue commitc075a8cd8b
Author: Laurent Meunier <laurent@deltalima.net> Date: Sun Mar 31 12:35:04 2024 +0200 Also check smtputf8 for submitted messages or when in pedantic mode commitc02328f881
Author: Laurent Meunier <laurent@deltalima.net> Date: Sun Mar 31 12:33:20 2024 +0200 Calls to `newParser` should use `c.smtputf8` commita0bbd13afc
Author: Laurent Meunier <laurent@deltalima.net> Date: Sun Mar 31 12:32:12 2024 +0200 Improve SMTPUTF8 tests commit08735690f3
Author: Laurent Meunier <laurent@deltalima.net> Date: Sat Mar 30 17:22:33 2024 +0100 do earlier smtputf8-check commit3484651691
Author: Laurent Meunier <laurent@deltalima.net> Date: Thu Mar 28 17:47:11 2024 +0100 do not require the SMTPUTF8 extension when not needed fix #145
This commit is contained in:

committed by
Mechiel Lukkien

parent
d34dd8aae6
commit
9c5d234162
@ -1767,3 +1767,64 @@ func TestFutureRelease(t *testing.T) {
|
||||
test(" HOLDFOR=1 HOLDFOR=1", "501") // Duplicate.
|
||||
test(" HOLDFOR=1 HOLDUNTIL="+time.Now().Add(time.Hour).UTC().Format(time.RFC3339), "501") // Duplicate.
|
||||
}
|
||||
|
||||
// Test SMTPUTF8
|
||||
func TestSMTPUTF8(t *testing.T) {
|
||||
ts := newTestServer(t, filepath.FromSlash("../testdata/smtp/mox.conf"), dns.MockResolver{})
|
||||
defer ts.close()
|
||||
|
||||
ts.user = "mjl@mox.example"
|
||||
ts.pass = password0
|
||||
ts.submission = true
|
||||
|
||||
test := func(mailFrom string, rcptTo string, headerValue string, filename string, clientSmtputf8 bool, expectedSmtputf8 bool, expErr *smtpclient.Error) {
|
||||
t.Helper()
|
||||
|
||||
ts.run(func(_ error, client *smtpclient.Client) {
|
||||
t.Helper()
|
||||
msg := strings.ReplaceAll(fmt.Sprintf(`From: <%s>
|
||||
To: <%s>
|
||||
Subject: test
|
||||
X-Custom-Test-Header: %s
|
||||
MIME-Version: 1.0
|
||||
Content-type: multipart/mixed; boundary="simple boundary"
|
||||
|
||||
--simple boundary
|
||||
Content-Type: text/plain; charset=UTF-8;
|
||||
Content-Disposition: attachment; filename="%s"
|
||||
Content-Transfer-Encoding: base64
|
||||
|
||||
QW4gYXR0YWNoZWQgdGV4dCBmaWxlLg==
|
||||
|
||||
--simple boundary--
|
||||
`, mailFrom, rcptTo, headerValue, filename), "\n", "\r\n")
|
||||
|
||||
err := client.Deliver(ctxbg, mailFrom, rcptTo, int64(len(msg)), strings.NewReader(msg), true, clientSmtputf8, 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)
|
||||
}
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
msgs, _ := queue.List(ctxbg, queue.Filter{})
|
||||
queuedMsg := msgs[len(msgs)-1]
|
||||
if queuedMsg.SMTPUTF8 != expectedSmtputf8 {
|
||||
t.Fatalf("[%s / %s / %s / %s] got SMTPUTF8 %t, expected %t", mailFrom, rcptTo, headerValue, filename, queuedMsg.SMTPUTF8, expectedSmtputf8)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
test(`mjl@mox.example`, `remote@example.org`, "header-ascii", "ascii.txt", false, false, nil)
|
||||
test(`mjl@mox.example`, `remote@example.org`, "header-ascii", "ascii.txt", true, false, nil)
|
||||
test(`mjl@mox.example`, `🙂@example.org`, "header-ascii", "ascii.txt", true, true, nil)
|
||||
test(`mjl@mox.example`, `🙂@example.org`, "header-ascii", "ascii.txt", false, true, &smtpclient.Error{Permanent: true, Code: smtp.C553BadMailbox, Secode: smtp.SeMsg6NonASCIIAddrNotPermitted7})
|
||||
test(`Ω@mox.example`, `remote@example.org`, "header-ascii", "ascii.txt", true, true, nil)
|
||||
test(`Ω@mox.example`, `remote@example.org`, "header-ascii", "ascii.txt", false, true, &smtpclient.Error{Permanent: true, Code: smtp.C550MailboxUnavail, Secode: smtp.SeMsg6NonASCIIAddrNotPermitted7})
|
||||
test(`mjl@mox.example`, `remote@example.org`, "header-utf8-😍", "ascii.txt", true, true, nil)
|
||||
test(`mjl@mox.example`, `remote@example.org`, "header-utf8-😍", "ascii.txt", false, true, nil)
|
||||
test(`mjl@mox.example`, `remote@example.org`, "header-ascii", "utf8-🫠️.txt", true, true, nil)
|
||||
test(`Ω@mox.example`, `🙂@example.org`, "header-utf8-😍", "utf8-🫠️.txt", true, true, nil)
|
||||
test(`mjl@mox.example`, `remote@xn--vg8h.example.org`, "header-ascii", "ascii.txt", true, false, nil)
|
||||
}
|
||||
|
Reference in New Issue
Block a user