Documentation ¶
Overview ¶
Package testtrx can be used to test mailfilter based filter functions
Index ¶
- type Modification
- type ModificationKind
- type Trx
- func (t *Trx) AddRcptTo(rcptTo string, esmtpArgs string)
- func (t *Trx) Body() io.ReadSeeker
- func (t *Trx) ChangeMailFrom(from string, esmtpArgs string)
- func (t *Trx) Connect() *mailfilter.Connect
- func (t *Trx) DelRcptTo(rcptTo string)
- func (t *Trx) HasRcptTo(rcptTo string) bool
- func (t *Trx) Headers() header2.Header
- func (t *Trx) HeadersEnforceOrder()
- func (t *Trx) Helo() *mailfilter.Helo
- func (t *Trx) MTA() *mailfilter.MTA
- func (t *Trx) MailFrom() *addr.MailFrom
- func (t *Trx) Modifications() []Modification
- func (t *Trx) QueueId() string
- func (t *Trx) RcptTos() []*addr.RcptTo
- func (t *Trx) ReplaceBody(r io.Reader)
- func (t *Trx) SetBody(body io.ReadSeeker) *Trx
- func (t *Trx) SetBodyBytes(b []byte) *Trx
- func (t *Trx) SetConnect(connect mailfilter.Connect) *Trx
- func (t *Trx) SetHeaders(headers header2.Header) *Trx
- func (t *Trx) SetHeadersRaw(raw []byte) *Trx
- func (t *Trx) SetHelo(helo mailfilter.Helo) *Trx
- func (t *Trx) SetMTA(mta mailfilter.MTA) *Trx
- func (t *Trx) SetMailFrom(mailFrom addr.MailFrom) *Trx
- func (t *Trx) SetQueueId(value string) *Trx
- func (t *Trx) SetRcptTos(rcptTos []*addr.RcptTo) *Trx
- func (t *Trx) SetRcptTosList(tos ...string) *Trx
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Modification ¶
type Modification struct { Kind ModificationKind Addr string Args string Index int Name string Value string Body []byte }
Modification is a modification that a mailfilter.DecisionModificationFunc made to the Trx.
type ModificationKind ¶
type ModificationKind int
const ( ChangeFrom ModificationKind = iota // a change mail from modification would have been sent to the MTA AddRcptTo // an add-recipient modification would have been sent to the MTA DelRcptTo // a delete-recipient modification would have been sent to the MTA InsertHeader // an insert-header modification would have been sent to the MTA ChangeHeader // a change-header modification would have been sent to the MTA ReplaceBody // a replace-body modification would have been sent to the MTA )
type Trx ¶
type Trx struct {
// contains filtered or unexported fields
}
Trx implements mailfilter.Trx for unit tests. Use this struct when you want to test your decision functions. You can use the fluent Set* methods of this struct to build up the transaction you want to test. After you passed the Trx to your decision function, you can call Trx.Modifications to check that your decision function did what was expected of it.
Example ¶
package main import ( "context" "fmt" "github.com/d--j/go-milter/mailfilter" "github.com/d--j/go-milter/mailfilter/addr" "github.com/d--j/go-milter/mailfilter/testtrx" ) func Filter(_ context.Context, trx mailfilter.Trx) (mailfilter.Decision, error) { trx.ChangeMailFrom("", "A=B") return mailfilter.Accept, nil } func main() { trx := (&testtrx.Trx{}).SetMTA(mailfilter.MTA{ Version: "Postfix 2.0.0", FQDN: "mx.example.net", Daemon: "smtpd", }).SetConnect(mailfilter.Connect{ Host: "localhost", Family: "tcp", Port: 25, Addr: "127.0.0.1", IfName: "lo", IfAddr: "127.0.0.1", }).SetHelo(mailfilter.Helo{ Name: "localhost", TlsVersion: "", Cipher: "", CipherBits: "", CertSubject: "", CertIssuer: "", }). SetQueueId("ABCD"). SetMailFrom(addr.NewMailFrom("root@localhost", "", "local", "", "")). SetRcptTosList("root@localhost", "postmaster@example.com"). SetHeadersRaw([]byte("Subject: test\n\n")). SetBodyBytes([]byte("test body")) decision, _ := Filter(context.Background(), trx) if decision != mailfilter.Accept { fmt.Println("decision wrong") } for _, m := range trx.Modifications() { fmt.Println(m) } }
Output: {0 A=B 0 []}
func (*Trx) Body ¶
func (t *Trx) Body() io.ReadSeeker
func (*Trx) ChangeMailFrom ¶
func (*Trx) Connect ¶
func (t *Trx) Connect() *mailfilter.Connect
func (*Trx) HeadersEnforceOrder ¶ added in v0.8.2
func (t *Trx) HeadersEnforceOrder()
func (*Trx) Helo ¶
func (t *Trx) Helo() *mailfilter.Helo
func (*Trx) MTA ¶
func (t *Trx) MTA() *mailfilter.MTA
func (*Trx) Modifications ¶
func (t *Trx) Modifications() []Modification
func (*Trx) ReplaceBody ¶
func (*Trx) SetBodyBytes ¶
func (*Trx) SetConnect ¶
func (t *Trx) SetConnect(connect mailfilter.Connect) *Trx
func (*Trx) SetHeadersRaw ¶
func (*Trx) SetQueueId ¶
func (*Trx) SetRcptTosList ¶
Click to show internal directories.
Click to hide internal directories.