maddy

Fork https://github.com/foxcpp/maddy

git clone git://git.lin.moe/go/maddy.git

 1/*
 2Maddy Mail Server - Composable all-in-one email server.
 3Copyright © 2019-2020 Max Mazurov <fox.cpp@disroot.org>, Maddy Mail Server contributors
 4
 5This program is free software: you can redistribute it and/or modify
 6it under the terms of the GNU General Public License as published by
 7the Free Software Foundation, either version 3 of the License, or
 8(at your option) any later version.
 9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with this program.  If not, see <https://www.gnu.org/licenses/>.
17*/
18
19package module
20
21import (
22	"context"
23
24	"github.com/emersion/go-message/textproto"
25	"github.com/emersion/go-smtp"
26	"github.com/foxcpp/maddy/framework/buffer"
27	"github.com/foxcpp/maddy/framework/config"
28)
29
30// Dummy is a struct that implements PlainAuth and DeliveryTarget
31// interfaces but does nothing. Useful for testing.
32//
33// It is always registered under the 'dummy' name and can be used in both tests
34// and the actual server code (but the latter is kinda pointless).
35type Dummy struct{ instName string }
36
37func (d *Dummy) AuthPlain(username, _ string) error {
38	return nil
39}
40
41func (d *Dummy) Lookup(_ context.Context, _ string) (string, bool, error) {
42	return "", false, nil
43}
44
45func (d *Dummy) LookupMulti(_ context.Context, _ string) ([]string, error) {
46	return []string{""}, nil
47}
48
49func (d *Dummy) Name() string {
50	return "dummy"
51}
52
53func (d *Dummy) InstanceName() string {
54	return d.instName
55}
56
57func (d *Dummy) Init(_ *config.Map) error {
58	return nil
59}
60
61func (d *Dummy) Start(ctx context.Context, msgMeta *MsgMetadata, mailFrom string) (Delivery, error) {
62	return dummyDelivery{}, nil
63}
64
65type dummyDelivery struct{}
66
67func (dd dummyDelivery) AddRcpt(ctx context.Context, rcptTo string, opts smtp.RcptOptions) error {
68	return nil
69}
70
71func (dd dummyDelivery) Body(ctx context.Context, header textproto.Header, body buffer.Buffer) error {
72	return nil
73}
74
75func (dd dummyDelivery) Abort(ctx context.Context) error {
76	return nil
77}
78
79func (dd dummyDelivery) Commit(ctx context.Context) error {
80	return nil
81}
82
83func init() {
84	Register("dummy", func(_, instName string, _, _ []string) (Module, error) {
85		return &Dummy{instName: instName}, nil
86	})
87}