Coder Social home page Coder Social logo

gomilter's Introduction

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

gomilter's People

Contributors

freeaqingme avatar leonrbaker avatar allgeiersupport avatar pedrinimm avatar

Watchers

James Cloos avatar

Forkers

open-ch

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.