|
|
@@ -348,6 +348,97 @@ what's up
|
|
|
writeAndReadUntilLine(t, email, c, scanner, "451 4.0.0 invalid address")
|
|
|
}
|
|
|
|
|
|
+func TestSmtpBackend_Base64Body(t *testing.T) {
|
|
|
+ email := `EHLO example.com
|
|
|
+MAIL FROM: test@mydomain.me
|
|
|
+RCPT TO: ntfy-mytopic@ntfy.sh
|
|
|
+DATA
|
|
|
+Content-Type: multipart/mixed; boundary="===============2138658284696597373=="
|
|
|
+MIME-Version: 1.0
|
|
|
+Subject: TrueNAS truenas.local: TrueNAS Test Message hostname: truenas.local
|
|
|
+From: =?utf-8?q?Robbie?= <test@mydomain.me>
|
|
|
+To: test@mydomain.me
|
|
|
+Date: Thu, 16 Feb 2023 01:04:00 -0000
|
|
|
+Message-ID: <truenas-20230216.010400.344514.b'8jfL'@truenas.local>
|
|
|
+
|
|
|
+This is a multi-part message in MIME format.
|
|
|
+--===============2138658284696597373==
|
|
|
+Content-Type: text/plain; charset="utf-8"
|
|
|
+MIME-Version: 1.0
|
|
|
+Content-Transfer-Encoding: base64
|
|
|
+
|
|
|
+VGhpcyBpcyBhIHRlc3QgbWVzc2FnZSBmcm9tIFRydWVOQVMgQ09SRS4=
|
|
|
+
|
|
|
+--===============2138658284696597373==
|
|
|
+Content-Type: text/html; charset="utf-8"
|
|
|
+MIME-Version: 1.0
|
|
|
+Content-Transfer-Encoding: base64
|
|
|
+
|
|
|
+PCFET0NUWVBFIEhUTUwgUFVCTElDICItLy9XM0MvL0RURCBIVE1MIDQuMCBUcmFuc2l0aW9uYWwv
|
|
|
+L0VOIj4KClRoaXMgaXMgYSB0ZXN0IG1lc3NhZ2UgZnJvbSBUcnVlTkFTIENPUkUuCg==
|
|
|
+
|
|
|
+--===============2138658284696597373==--
|
|
|
+.
|
|
|
+`
|
|
|
+ s, c, _, scanner := newTestSMTPServer(t, func(w http.ResponseWriter, r *http.Request) {
|
|
|
+ require.Equal(t, "/mytopic", r.URL.Path)
|
|
|
+ require.Equal(t, "TrueNAS truenas.local: TrueNAS Test Message hostname: truenas.local", r.Header.Get("Title"))
|
|
|
+ require.Equal(t, "This is a test message from TrueNAS CORE.", readAll(t, r.Body))
|
|
|
+ })
|
|
|
+ defer s.Close()
|
|
|
+ defer c.Close()
|
|
|
+ writeAndReadUntilLine(t, email, c, scanner, "250 2.0.0 OK: queued")
|
|
|
+}
|
|
|
+
|
|
|
+/*
|
|
|
+ func TestSmtpBackend_NestedMultipartBase64(t *testing.T) {
|
|
|
+ email := `EHLO example.com
|
|
|
+
|
|
|
+MAIL FROM: test@mydomain.me
|
|
|
+RCPT TO: ntfy-mytopic@ntfy.sh
|
|
|
+DATA
|
|
|
+Content-Type: multipart/mixed; boundary="===============2138658284696597373=="
|
|
|
+MIME-Version: 1.0
|
|
|
+Subject: TrueNAS truenas.local: TrueNAS Test Message hostname: truenas.local
|
|
|
+From: =?utf-8?q?Robbie?= <test@mydomain.me>
|
|
|
+To: test@mydomain.me
|
|
|
+Date: Thu, 16 Feb 2023 01:04:00 -0000
|
|
|
+Message-ID: <truenas-20230216.010400.344514.b'8jfL'@truenas.local>
|
|
|
+
|
|
|
+This is a multi-part message in MIME format.
|
|
|
+--===============2138658284696597373==
|
|
|
+Content-Type: multipart/alternative; boundary="===============2233989480071754745=="
|
|
|
+MIME-Version: 1.0
|
|
|
+
|
|
|
+--===============2233989480071754745==
|
|
|
+Content-Type: text/plain; charset="utf-8"
|
|
|
+MIME-Version: 1.0
|
|
|
+Content-Transfer-Encoding: base64
|
|
|
+
|
|
|
+VGhpcyBpcyBhIHRlc3QgbWVzc2FnZSBmcm9tIFRydWVOQVMgQ09SRS4=
|
|
|
+
|
|
|
+--===============2233989480071754745==
|
|
|
+Content-Type: text/html; charset="utf-8"
|
|
|
+MIME-Version: 1.0
|
|
|
+Content-Transfer-Encoding: base64
|
|
|
+
|
|
|
+PCFET0NUWVBFIEhUTUwgUFVCTElDICItLy9XM0MvL0RURCBIVE1MIDQuMCBUcmFuc2l0aW9uYWwv
|
|
|
+L0VOIj4KClRoaXMgaXMgYSB0ZXN0IG1lc3NhZ2UgZnJvbSBUcnVlTkFTIENPUkUuCg==
|
|
|
+
|
|
|
+--===============2233989480071754745==--
|
|
|
+
|
|
|
+--===============2138658284696597373==--
|
|
|
+.
|
|
|
+`
|
|
|
+
|
|
|
+ s, c, _, scanner := newTestSMTPServer(t, func(w http.ResponseWriter, r *http.Request) {
|
|
|
+ t.Fatal("This should not be called")
|
|
|
+ })
|
|
|
+ defer s.Close()
|
|
|
+ defer c.Close()
|
|
|
+ writeAndReadUntilLine(t, email, c, scanner, "451 4.0.0 invalid address")
|
|
|
+ }
|
|
|
+*/
|
|
|
type smtpHandlerFunc func(http.ResponseWriter, *http.Request)
|
|
|
|
|
|
func newTestSMTPServer(t *testing.T, handler smtpHandlerFunc) (s *smtp.Server, c net.Conn, conf *Config, scanner *bufio.Scanner) {
|