Milter.testctx.TestCtx Class Reference

Milter context for unit testing milter applications. More...

Inheritance diagram for Milter.testctx.TestCtx:

## Public Member Functions

| __init__ (self, logfile='test/milter.log')
| getpriv (self)
| setpriv (self, priv)
| getsymval (self, name)
| setreply (self, rcode, xcode, *msg)
| setsymlist (self, stage, macros)
| addheader (self, field, value, idx)
| chgheader (self, field, idx, value)
| addrcpt (self, rcpt, params)
| delrcpt (self, rcpt)
| replacebody (self, chunk)
| chgfrom (self, sender, params=None)
| quarantine (self, reason)
| progress (self)
| Reset activity timer.

## Static Public Attributes

list | default_opts = [Milter.CURR_ACTS,0x1fffff,0,0]

## Protected Member Functions

| _setsymval (self, name, val)
| _abort (self)
| _close (self)
| _negotiate (self)
| _connect (self, host='localhost', helo='spamrelay', ip='1.2.3.4')
| _helo (self, helo)
| _envfrom (self, *s)
| _envrcpt (self, s)
| _data (self)
| _header (self, fld, val)
| _eoh (self)
| _feed_body (self, bfp)
| _eom (self)
| _feedFile (self, fp, sender="spam@adv.com", rcpt="victim@lamb.com", *rcpts)
| Feed a file like object to the ctx.
| _feedMsg (self, fname, sender="spam@adv.com", *rcpts)
| Feed an email contained in a file to the milter.

## Protected Attributes

| _priv = None
| Usually the Milter application derived from Milter.Base.
list | _delrcpt = []
| List of recipients deleted.
list | _addrcpt = []
| List of recipients added.
dict | _macros = { }
| Macros defined.
tuple | _reply = None
| Reply codes and messages set by the milter.
list | _symlist = [ None, None, None, None, None, None, None ]
| The macros returned by protocol stage.
| _body = None
| The message body.
bool | _bodyreplaced = False
| True if the milter replaced the message body.
bool | _headerschanged = False
| True if the milter changed any headers.
| _msg = None
| The rfc822 message object for the current email being fed to the milter.
| _sender = None
| The MAIL FROM for the current email being fed to the milter.
bool | _envfromchanged = False
| True if the milter changed the envelope from.
list | _opts = TestCtx.default_opts
| List of recipients added.
| _activity = time.time()
| Last activity.
int | _stage = -1
list | _protocol = self._opts[1]

## Detailed Description

Milter context for unit testing milter applications.

A substitute for milter.milterContext that can be passed to Milter.Base._setctx().

Since
  1.0.3

## Member Function Documentation

## _feedFile()

Milter.testctx.TestCtx._feedFile | ( |  | self,
|  |  | fp,
|  |  | sender = "spam@adv.com",
|  |  | rcpt = "victim@lamb.com",
|  | * | rcpts )

protected

Feed a file like object to the ctx.

Calls the callbacks in the same sequence as libmilter.

Parameters

  fp | the file with rfc2822 message stream
  sender | the MAIL FROM
  rcpt | RCPT TO - additional recipients may follow

References Milter.test.TestBase._body, _body, Milter.test.TestBase._bodyreplaced, _bodyreplaced, _data(), _envfrom(), _envrcpt(), _eoh(), _eom(), _feed_body(), _header(), Milter.test.TestBase._headerschanged, _headerschanged, Milter.test.TestBase._msg, _msg, Milter.test.TestBase._reply, and _reply.

Referenced by _feedMsg().

## _feedMsg()

Milter.testctx.TestCtx._feedMsg | ( |  | self,
|  |  | fname,
|  |  | sender = "spam@adv.com",
|  | * | rcpts )

protected

Feed an email contained in a file to the milter.

This is a convenience method that invokes feedFile .

Parameters

  sender | MAIL FROM
  rcpts | RCPT TO, multiple recipients may be supplied

References _feedFile().

## Member Data Documentation

## _opts

list Milter.testctx.TestCtx._opts = TestCtx.default_opts

protected

List of recipients added.

Negotiated options

Referenced by progress().

The documentation for this class was generated from the following file:

- Milter/testctx.py