gomilter

package module
v0.0.0-...-aac1245 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 14, 2017 License: MIT Imports: 11 Imported by: 0

README

gomilter

Go Bindings for Sendmail's libmilter

Tested on Linux and FreeBSD

Installation

The Sendmail header file libmilter/mfapi.h is required. For Redhat/CentOS, install the sendmail-devel package:

yum install sendmail-devel

Install the gomilter package:

go get github.com/leonrbaker/gomilter

##Usage

The milter is implemented in a struct. Start by defining your own struct type and embeding the gomilter MilterRaw struct.

type Mymilter struct {
	gomilter.MilterRaw // Embed the basic functionality.
}

Milter callbacks are added by implementing methods for the struct with matching predefined names.

Callbacks
  • Connect
  • Helo
  • EnvFrom
  • EnvRcpt
  • Header
  • Eoh
  • Body
  • Eom
  • Abort
  • Close

Not all the callbacks need to be defined. The callbacks are explained on the milter.org site. Unfortunately the milter.org site has been shut down but it is still on web.archive.org

Message Modification Functions
  • AddHeader
  • ChgHeader
  • InsHeader
  • ChgFrom
  • AddRcpt
  • AddRcpt_Par
  • DelRcpt
  • ReplaceBody
Other Message Handling Functions
  • progress
Startup

The Socket field of the milter struct must be set. For example:

mymilter.Socket = "unix:/var/gomilter/socket"

Control is handed over to the libmilter smfi_main function by calling the Run method and passing it a pointer to your milter struct

gomilter.Run(mymilter)

The milter has a Stop method which calls the libmilter smfi_stop function.

Private Data

libmilter is able to store private data for a connection. This data can be accessed from other functions and callbacks for the same connection. You can pass a pointer to any data structure to SetPriv. The data is retrieved with GetPriv

t := T{1, 2, 3}
m.SetPriv(ctx, &t)

Retrieve the data with

var t T
m.GetPriv(ctx, &t))

GetPriv should only be called once. If the private data is needed in another function or callback then call SetPriv again.

Sample Programs

There are two sample programs included, samplefilter.go and samplefilter2.go

##Other Libraries

A usefull MIME parsing library is go.enmime

Documentation

Index

Constants

View Source
const (
	Continue = iota
	Reject
	Discard
	Accept
	Tempfail

	Noreply
	Skip
)

Return values for Callback functions

View Source
const (
	ADDHDRS     = 0x00000001 // 000000001
	CHGBODY     = 0x00000002 // 000000010
	ADDRCPT     = 0x00000004 // 000000100
	DELRCPT     = 0x00000008 // 000001000
	CHGHDRS     = 0x00000010 // 000010000
	QUARANTINE  = 0x00000020 // 000100000
	CHGFROM     = 0x00000040 // 001000000
	ADDRCPT_PAR = 0x00000080 // 010000000
	SETSYMLIST  = 0x00000100 // 100000000
)

flags

Variables

This section is empty.

Functions

func AddHeader

func AddHeader(ctx uintptr, headerf, headerv string) int

func AddRcpt

func AddRcpt(ctx uintptr, rcpt string) int

func AddRcpt_Par

func AddRcpt_Par(ctx uintptr, rcpt, args string) int

func ChgFrom

func ChgFrom(ctx uintptr, mail, args string) int

func ChgHeader

func ChgHeader(ctx uintptr, headerf string, hdridx int, headerv string) int

func DelRcpt

func DelRcpt(ctx uintptr, rcpt string) int

func GetPriv

func GetPriv(ctx uintptr, privatedata interface{}) int

func GetSymVal

func GetSymVal(ctx uintptr, symname string) string

func Go_xxfi_abort

func Go_xxfi_abort(ctx *C.SMFICTX) C.sfsistat

func Go_xxfi_body

func Go_xxfi_body(ctx *C.SMFICTX, bodyp *C.uchar, bodylen C.size_t) C.sfsistat

func Go_xxfi_close

func Go_xxfi_close(ctx *C.SMFICTX) C.sfsistat

func Go_xxfi_connect

func Go_xxfi_connect(ctx *C.SMFICTX, hostname *C.char, hostaddr *C._SOCK_ADDR) (sfsistat C.sfsistat)

func Go_xxfi_envfrom

func Go_xxfi_envfrom(ctx *C.SMFICTX, argv **C.char) C.sfsistat

func Go_xxfi_envrcpt

func Go_xxfi_envrcpt(ctx *C.SMFICTX, argv **C.char) C.sfsistat

func Go_xxfi_eoh

func Go_xxfi_eoh(ctx *C.SMFICTX) C.sfsistat

func Go_xxfi_eom

func Go_xxfi_eom(ctx *C.SMFICTX) C.sfsistat

func Go_xxfi_header

func Go_xxfi_header(ctx *C.SMFICTX, headerf, headerv *C.char) C.sfsistat

func Go_xxfi_helo

func Go_xxfi_helo(ctx *C.SMFICTX, helohost *C.char) C.sfsistat

func GobDecode

func GobDecode(buf []byte, data interface{}) error

func GobEncode

func GobEncode(data interface{}) ([]byte, error)

func InsHeader

func InsHeader(ctx uintptr, hdridx int, headerf, headerv string) int

func ReplaceBody

func ReplaceBody(ctx uintptr, body []byte) int

func Run

func Run(amilter Milter) int

func SetMLReply

func SetMLReply(ctx uintptr, rcode, xcode string, message ...string) int

func SetPriv

func SetPriv(ctx uintptr, privatedata interface{}) int

See also: http://bit.ly/1HVWA9I

func SetReply

func SetReply(ctx uintptr, rcode, xcode, message string) int

func Stop

func Stop()

Types

type CtxPtr

type CtxPtr *C.struct_smfi_str

type Milter

type Milter interface {
	GetFilterName() string
	GetDebug() bool
	GetFlags() int
	GetSocket() string
	GetLogger() *log.Logger
}

Interface that must be implemented in order to use gomilter

type MilterRaw

type MilterRaw struct {
	FilterName string
	Debug      bool
	Flags      int
	Socket     string
	Logger     *log.Logger
}

An "empty" Milter with no callback functions

func (*MilterRaw) GetDebug

func (m *MilterRaw) GetDebug() bool

func (*MilterRaw) GetFilterName

func (m *MilterRaw) GetFilterName() string

func (*MilterRaw) GetFlags

func (m *MilterRaw) GetFlags() int

func (*MilterRaw) GetLogger

func (m *MilterRaw) GetLogger() *log.Logger

func (*MilterRaw) GetSocket

func (m *MilterRaw) GetSocket() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL