Skip to content
A golang library for milter support
Go
Branch: master
Clone or download
Pull request Compare This branch is 3 commits ahead, 2 commits behind phalaaxx:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore
LICENSE
README.md
cstrings.go
errors.go
go.mod
interface.go
message.go
milter-protocol.txt
milter.go
modifier.go
response.go
session.go

README.md

GoDoc

milter

A Go library for milter support heavily inspired from https://github.com/andybalholm/milter For example how to use the library see https://github.com/phalaaxx/pf-milters - postfix milter for email classification with bogofilter and blacklisting messages which contain files with executable extensions.

CHANGES

I changed the original package for better usage.

  • Better Integrating Interface
  • Callback Interfaces with Context
import "github.com/x-mod/milter"

import (
	"context"
	"net"

	"github.com/spf13/cobra"
	"github.com/spf13/viper"
	"github.com/x-mod/milter"
	"github.com/x-mod/routine"
	"github.com/x-mod/tcpserver"
)

func Main(cmd *cobra.Command, args []string) error {
	srv := tcpserver.NewServer(
		tcpserver.Network(viper.GetString("inet")),
		tcpserver.Address(viper.GetString("address")),
		tcpserver.Handler(Handler),
	)
	return routine.Main(
		routine.ExecutorFunc(srv.Serve),
		routine.Interrupts(routine.DefaultCancelInterruptors...),
		routine.Cleanup(
			routine.ExecutorFunc(func(ctx context.Context) error {
				srv.Close()
				return nil
			})),
	)
}

func Handler(ctx context.Context, conn net.Conn) error {
    ssn := milter.NewMilterSession(conn, 
            milter.WithMilter(&MyMilter{}), 
            milter.WithContext(ctx))
	return ssn.Serve()
}

//MyMilter implement the Milter interface
type MyMilter struct{}

///Callback with Context

// Connect(ctx context.Context, host string, family string, port uint16, addr net.IP, m *Modifier) (Response, error)

// Helo(ctx context.Context, name string, m *Modifier) (Response, error)
You can’t perform that action at this time.