2 // Copyright 2020 Blue Static <https://www.bluestatic.org>
3 // This program is free software licensed under the GNU General Public License,
4 // version 3.0. The full text of the license can be found in LICENSE.txt.
5 // SPDX-License-Identifier: GPL-3.0-only
19 "src.bluestatic.org/mailpopbox/smtp"
22 func TestVerifyAddress(t *testing.T) {
23 dir, err := ioutil.TempDir("", "maildrop")
25 t.Errorf("Failed to create temp dir: %v", err)
28 defer os.RemoveAll(dir)
32 Hostname: "mx.example.com",
35 Domain: "example.com",
43 if s.VerifyAddress(mail.Address{Address: "example@example.com"}) != smtp.ReplyOK {
44 t.Errorf("Valid mailbox is not reported to be valid")
46 if s.VerifyAddress(mail.Address{Address: "mailbox@example.com"}) != smtp.ReplyOK {
47 t.Errorf("Valid mailbox is not reported to be valid")
49 if s.VerifyAddress(mail.Address{Address: "hello@other.net"}) == smtp.ReplyOK {
50 t.Errorf("Invalid mailbox reports to be valid")
52 if s.VerifyAddress(mail.Address{Address: "hello@mx.example.com"}) == smtp.ReplyOK {
53 t.Errorf("Invalid mailbox reports to be valid")
55 if s.VerifyAddress(mail.Address{Address: "unknown"}) == smtp.ReplyOK {
56 t.Errorf("Invalid mailbox reports to be valid")
60 func TestMessageDelivery(t *testing.T) {
61 dir, err := ioutil.TempDir("", "maildrop")
63 t.Errorf("Failed to create temp dir: %v", err)
66 defer os.RemoveAll(dir)
70 Hostname: "mx.example.com",
73 Domain: "example.com",
82 MailFrom: mail.Address{Address: "sender@mail.net"},
83 RcptTo: []mail.Address{{Address: "receive@example.com"}},
84 Data: []byte("Hello, world"),
88 if rl := s.OnMessageDelivered(env); rl != nil {
89 t.Errorf("Failed to deliver message: %v", rl)
92 f, err := os.Open(filepath.Join(dir, "msgid.msg"))
94 t.Errorf("Failed to open delivered message: %v", err)
98 data, err := ioutil.ReadAll(f)
100 t.Errorf("Failed to read message: %v", err)
103 if !bytes.Contains(data, env.Data) {
104 t.Errorf("Could not find expected data in message")