maddy

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

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

  1//go:build ignore
  2// +build ignore
  3
  4// Copy that file into target/ subdirectory.
  5
  6package target_name
  7
  8/*
  9Maddy Mail Server - Composable all-in-one email server.
 10Copyright © 2019-2021 Max Mazurov <fox.cpp@disroot.org>, Maddy Mail Server contributors
 11
 12This program is free software: you can redistribute it and/or modify
 13it under the terms of the GNU General Public License as published by
 14the Free Software Foundation, either version 3 of the License, or
 15(at your option) any later version.
 16
 17This program is distributed in the hope that it will be useful,
 18but WITHOUT ANY WARRANTY; without even the implied warranty of
 19MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 20GNU General Public License for more details.
 21
 22You should have received a copy of the GNU General Public License
 23along with this program.  If not, see <https://www.gnu.org/licenses/>.
 24*/
 25
 26import (
 27	"context"
 28
 29	"github.com/emersion/go-message/textproto"
 30	"github.com/foxcpp/maddy/framework/buffer"
 31	"github.com/foxcpp/maddy/framework/config"
 32	"github.com/foxcpp/maddy/framework/log"
 33	"github.com/foxcpp/maddy/framework/module"
 34)
 35
 36const modName = "target.target_name"
 37
 38type Target struct {
 39	instName string
 40	log      log.Logger
 41}
 42
 43func New(_, instName string, _, inlineArgs []string) (module.Module, error) {
 44	// If wanted, extract any values from inlineArgs (these values:
 45	// deliver_to target_name ARG1 ARG2 { ... }
 46
 47	return &Target{
 48		instName: instName,
 49		log:      log.Logger{Name: instName},
 50	}, nil
 51}
 52
 53func (t *Target) Init(cfg *config.Map) error {
 54	cfg.Bool("debug", true, false, &t.log.Debug)
 55
 56	// Read any config directives into Target variables here.
 57
 58	if _, err := cfg.Process(); err != nil {
 59		return err
 60	}
 61
 62	// Finish setup using obtained values.
 63
 64	return nil
 65}
 66
 67func (t *Target) Name() string {
 68	return modName
 69}
 70
 71func (t *Target) InstanceName() string {
 72	return t.instName
 73}
 74
 75// If it necessary to have any server shutdown cleanup - implement Close.
 76
 77func (t *Target) Close() error {
 78	return nil
 79}
 80
 81type delivery struct {
 82	t        *Target
 83	mailFrom string
 84	log      log.Logger
 85	msgMeta  *module.MsgMetadata
 86}
 87
 88/*
 89See module.DeliveryTarget and module.Delivery docs for details on each method.
 90*/
 91
 92func (t *Target) Start(ctx context.Context, msgMeta *module.MsgMetadata, mailFrom string) (module.Delivery, error) {
 93	return &delivery{
 94		t:        t,
 95		mailFrom: mailFrom,
 96		log:      DeliveryLogger(t.log, msgMeta),
 97		msgMeta:  msgMeta,
 98	}, nil
 99}
100
101func (d *delivery) AddRcpt(ctx context.Context, rcptTo string) error {
102	// Corresponds to SMTP RCPT command.
103	panic("implement me")
104}
105
106func (d *delivery) Body(ctx context.Context, header textproto.Header, body buffer.Buffer) error {
107	// Corresponds to SMTP DATA command.
108	panic("implement me")
109}
110
111/*
112If Body call can fail partially (either success or fail for each recipient passed to AddRcpt)
113- implement BodyNonAtomic and signal status for each recipient using StatusCollector callback.
114
115func (d *delivery) BodyNonAtomic(ctx context.Context, sc module.StatusCollector, header textproto.Header, body buffer.Buffer) {
116
117}
118*/
119
120func (d *delivery) Abort(ctx context.Context) error {
121	panic("implement me")
122}
123
124func (d *delivery) Commit(ctx context.Context) error {
125	panic("implement me")
126}
127
128func init() {
129	module.Register(modName, New)
130}