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/*
  5Maddy Mail Server - Composable all-in-one email server.
  6Copyright © 2019-2020 Max Mazurov <fox.cpp@disroot.org>, Maddy Mail Server contributors
  7
  8This program is free software: you can redistribute it and/or modify
  9it under the terms of the GNU General Public License as published by
 10the Free Software Foundation, either version 3 of the License, or
 11(at your option) any later version.
 12
 13This program is distributed in the hope that it will be useful,
 14but WITHOUT ANY WARRANTY; without even the implied warranty of
 15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 16GNU General Public License for more details.
 17
 18You should have received a copy of the GNU General Public License
 19along with this program.  If not, see <https://www.gnu.org/licenses/>.
 20*/
 21
 22/*
 23This is example of a minimal stateful check module implementation.
 24See HACKING.md in the repo root for implementation recommendations.
 25*/
 26
 27package directory_name_here
 28
 29import (
 30	"context"
 31
 32	"github.com/emersion/go-message/textproto"
 33	"github.com/foxcpp/maddy/framework/buffer"
 34	"github.com/foxcpp/maddy/framework/config"
 35	"github.com/foxcpp/maddy/framework/log"
 36	"github.com/foxcpp/maddy/framework/module"
 37	"github.com/foxcpp/maddy/internal/target"
 38)
 39
 40const modName = "check_things"
 41
 42type Check struct {
 43	instName string
 44	log      log.Logger
 45}
 46
 47func New(modName, instName string, aliases, inlineArgs []string) (module.Module, error) {
 48	return &Check{
 49		instName: instName,
 50	}, nil
 51}
 52
 53func (c *Check) Name() string {
 54	return modName
 55}
 56
 57func (c *Check) InstanceName() string {
 58	return c.instName
 59}
 60
 61func (c *Check) Init(cfg *config.Map) error {
 62	return nil
 63}
 64
 65type state struct {
 66	c       *Check
 67	msgMeta *module.MsgMetadata
 68	log     log.Logger
 69}
 70
 71func (c *Check) CheckStateForMsg(ctx context.Context, msgMeta *module.MsgMetadata) (module.CheckState, error) {
 72	return &state{
 73		c:       c,
 74		msgMeta: msgMeta,
 75		log:     target.DeliveryLogger(c.log, msgMeta),
 76	}, nil
 77}
 78
 79func (s *state) CheckConnection(ctx context.Context) module.CheckResult {
 80	return module.CheckResult{}
 81}
 82
 83func (s *state) CheckSender(ctx context.Context, addr string) module.CheckResult {
 84	return module.CheckResult{}
 85}
 86
 87func (s *state) CheckRcpt(ctx context.Context, addr string) module.CheckResult {
 88	return module.CheckResult{}
 89}
 90
 91func (s *state) CheckBody(ctx context.Context, hdr textproto.Header, body buffer.Buffer) module.CheckResult {
 92	return module.CheckResult{}
 93}
 94
 95func (s *state) Close() error {
 96	return nil
 97}
 98
 99func init() {
100	module.Register(modName, New)
101}