Go Bindings for Sendmail's libmilter
Tested on Linux and FreeBSD
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.
- 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
- AddHeader
- ChgHeader
- InsHeader
- ChgFrom
- AddRcpt
- AddRcpt_Par
- DelRcpt
- ReplaceBody
- progress
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.
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.
There are two sample programs included, samplefilter.go and samplefilter2.go
##Other Libraries
A usefull MIME parsing library is go.enmime