Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Milter callbacks are added by implementing methods for the struct with matching
* Helo
* EnvFrom
* EnvRcpt
* Data
* Header
* Eoh
* Body
Expand Down
4 changes: 4 additions & 0 deletions filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ void setHeader(struct smfiDesc *smfilter) {
smfilter->xxfi_header = &Go_xxfi_header;
}

void setData(struct smfiDesc *smfilter) {
smfilter->xxfi_data = &Go_xxfi_data;
}

void setEoh(struct smfiDesc *smfilter) {
smfilter->xxfi_eoh = &Go_xxfi_eoh;
}
Expand Down
11 changes: 6 additions & 5 deletions filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ This projected is licensed under the terms of the MIT License.

// Set Callback functions in smfiDesc struct
extern void makesmfilter(struct smfiDesc *smfilter);
extern void setAbort(struct smfiDesc *smfilter);
extern void setBody(struct smfiDesc *smfilter);
extern void setClose(struct smfiDesc *smfilter);
extern void setConnect(struct smfiDesc *smfilter);
extern void setHelo(struct smfiDesc *smfilter);
extern void setData(struct smfiDesc *smfilter);
extern void setEnvFrom(struct smfiDesc *smfilter);
extern void setEnvRcpt(struct smfiDesc *smfilter);
extern void setHeader(struct smfiDesc *smfilter);
extern void setEoh(struct smfiDesc *smfilter);
extern void setBody(struct smfiDesc *smfilter);
extern void setEom(struct smfiDesc *smfilter);
extern void setAbort(struct smfiDesc *smfilter);
extern void setClose(struct smfiDesc *smfilter);
extern void setHeader(struct smfiDesc *smfilter);
extern void setHelo(struct smfiDesc *smfilter);

// Utility functions for things that we can't do in Go

Expand Down
40 changes: 40 additions & 0 deletions gomilter.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,21 @@ const (
SETSYMLIST = 0x00000100 // 100000000
)

// What the MTA can send/filter wants in protocol
const (
SMFIP_NOCONNECT = 0x00000001 // MTA should not send connect info
SMFIP_NOHELO = 0x00000002 // MTA should not send HELO info
SMFIP_NOMAIL = 0x00000004 // MTA should not send MAIL info
SMFIP_NORCPT = 0x00000008 // MTA should not send RCPT info
SMFIP_NOBODY = 0x00000010 // MTA should not send body
SMFIP_NOHDRS = 0x00000020 // MTA should not send headers
SMFIP_NOEOH = 0x00000040 // MTA should not send EOH
SMFIP_NR_HDR = 0x00000080 // No reply for headers
SMFIP_NOHREPL = SMFIP_NR_HDR // No reply for headers
SMFIP_NOUNKNOWN = 0x00000100 // MTA should not send unknown commands
SMFIP_NODATA = 0x00000200 // MTA should not send DATA
)

// Interface that must be implemented in order to use gomilter
type Milter interface {
GetFilterName() string
Expand Down Expand Up @@ -129,6 +144,10 @@ type checkForHeader interface {
Header(ctx uintptr, headerf, headerv string) (sfsistat int8)
}

type checkForData interface {
Data(ctx uintptr) (sfsistat int8)
}

type checkForEoh interface {
Eoh(ctx uintptr) (sfsistat int8)
}
Expand Down Expand Up @@ -275,6 +294,16 @@ func Go_xxfi_envrcpt(ctx *C.SMFICTX, argv **C.char) C.sfsistat {
return C.sfsistat(code)
}

//export Go_xxfi_data
func Go_xxfi_data(ctx *C.SMFICTX) C.sfsistat {
m := milter.(checkForData)
code := m.Data(ctx2int(ctx))
if milter.GetDebug() {
logger.Printf("Data callback returned: %d\n", code)
}
return C.sfsistat(code)
}

//export Go_xxfi_header
func Go_xxfi_header(ctx *C.SMFICTX, headerf, headerv *C.char) C.sfsistat {
m := milter.(checkForHeader)
Expand Down Expand Up @@ -669,6 +698,17 @@ func Run(amilter Milter) int {
logger.Println("Helo callback not implemented")
}
}
// Check if Data method was implemented
if _, ok := milter.(checkForData); ok {
if milter.GetDebug() {
logger.Println("Data callback implemented")
}
C.setData(&smfilter)
} else {
if milter.GetDebug() {
logger.Println("Data callback not implemented")
}
}
// Check if EnvFrom method was implemented
if _, ok := milter.(checkForEnvFrom); ok {
if milter.GetDebug() {
Expand Down