New example

This commit is contained in:
Stuart Gathman
2011-11-05 15:51:03 +00:00
parent feb6526cb8
commit 83a1762515
4 changed files with 18 additions and 20 deletions
+8 -2
View File
@@ -310,7 +310,7 @@ class Base(object):
## Called when the connection is closed. ## Called when the connection is closed.
def close(self): return CONTINUE def close(self): return CONTINUE
## Return mask of SMFIP_N.. protocol option bits to clear for this class ## Return mask of SMFIP_N* protocol option bits to clear for this class
# The @@nocallback and @@noreply decorators set the # The @@nocallback and @@noreply decorators set the
# <code>milter_protocol</code> function attribute to the protocol mask bit to # <code>milter_protocol</code> function attribute to the protocol mask bit to
# pass to libmilter, causing that callback or its reply to be skipped. # pass to libmilter, causing that callback or its reply to be skipped.
@@ -336,7 +336,10 @@ class Base(object):
## Negotiate milter protocol options. Called by the ## Negotiate milter protocol options. Called by the
# <a href="https://www.milter.org/developers/api/xxfi_negotiate"> # <a href="https://www.milter.org/developers/api/xxfi_negotiate">
# xffi_negotiate</a> callback. # xffi_negotiate</a> callback. This is an advanced callback,
# do not override unless you know what you are doing. Most
# negotiation can be done simply by using the supplied
# class and function decorators.
# Options are passed as # Options are passed as
# a list of 4 32-bit ints which can be modified and are passed # a list of 4 32-bit ints which can be modified and are passed
# back to libmilter on return. # back to libmilter on return.
@@ -363,6 +366,8 @@ class Base(object):
## Return the value of an MTA macro. Sendmail macro names ## Return the value of an MTA macro. Sendmail macro names
# are either single chars (e.g. "j") or multiple chars enclosed # are either single chars (e.g. "j") or multiple chars enclosed
# in braces (e.g. "{auth_type}"). Macro names are MTA dependent. # in braces (e.g. "{auth_type}"). Macro names are MTA dependent.
# See <a href="https://www.milter.org/developers/api/smfi_getsymval">
# smfi_getsymval</a> for default sendmail macros.
# @param sym the macro name # @param sym the macro name
def getsymval(self,sym): def getsymval(self,sym):
return self._ctx.getsymval(sym) return self._ctx.getsymval(sym)
@@ -714,4 +719,5 @@ for priv in ('os','milter','thread','factory','_seq','_seq_lock','__version__'):
__all__ = __all__.keys() __all__ = __all__.keys()
## @example milter-template.py ## @example milter-template.py
## @example milter-nomix.py
# #
+5 -14
View File
@@ -1,12 +1,7 @@
## To roll your own milter, create a class that extends Milter. ## A very simple milter to prevent mixing of internal and external mail.
# See the pymilter project at http://bmsi.com/python/milter.html # Internal is defined as using one of a list of internal top level domains.
# based on Sendmail's milter API http://www.milter.org/milter_api/api.html
# This code is open-source on the same terms as Python. # This code is open-source on the same terms as Python.
## Milter calls methods of your class at milter events.
## Return REJECT,TEMPFAIL,ACCEPT to short circuit processing for a message.
## You can also add/del recipients, replacebody, add/del headers, etc.
import Milter import Milter
import time import time
import sys import sys
@@ -14,15 +9,11 @@ from Milter.utils import parse_addr
internal_tlds = ["corp", "personal"] internal_tlds = ["corp", "personal"]
# Determine if a hostname is internal or not. True if internal, ## Determine if a hostname is internal or not.
# False otherwise # True if internal, False otherwise
def is_internal(hostname): def is_internal(hostname):
components = hostname.split(".") components = hostname.split(".")
return components.pop() in internal_tlds:
if components.pop() in internal_tlds:
return True
else:
return False
# Determine if internal and external hosts are mixed based on a list # Determine if internal and external hosts are mixed based on a list
# of hostnames # of hostnames
+1 -2
View File
@@ -79,7 +79,7 @@ class myMilter(Milter.Base):
## def envrcpt(self, to, *str): ## def envrcpt(self, to, *str):
@Milter.noreply @Milter.noreply
def envrcpt(self, recipient, *str): def envrcpt(self, to, *str):
rcptinfo = to,Milter.dictfromlist(str) rcptinfo = to,Milter.dictfromlist(str)
self.R.append(rcptinfo) self.R.append(rcptinfo)
@@ -110,7 +110,6 @@ class myMilter(Milter.Base):
self.addrcpt('<%s>' % 'spy@example.com') self.addrcpt('<%s>' % 'spy@example.com')
return Milter.ACCEPT return Milter.ACCEPT
def close(self): def close(self):
# always called, even when abort is called. Clean up # always called, even when abort is called. Clean up
# any external resources here. # any external resources here.
+4 -2
View File
@@ -1,4 +1,7 @@
# $Log$ # $Log$
# Revision 1.7 2009/06/13 21:15:12 customdesigned
# Doxygen updates.
#
# Revision 1.6 2009/06/09 03:13:13 customdesigned # Revision 1.6 2009/06/09 03:13:13 customdesigned
# More doxygen docs. # More doxygen docs.
# #
@@ -165,15 +168,14 @@ class MimeMessage(Message):
""" """
def __init__(self,fp=None,seekable=1): def __init__(self,fp=None,seekable=1):
Message.__init__(self) Message.__init__(self)
self.headerchange = None
self.submsg = None self.submsg = None
self.modified = False self.modified = False
## @var headerchange ## @var headerchange
# Provide a headerchange event for integration with Milter. # Provide a headerchange event for integration with Milter.
# The headerchange attribute can be assigned a function to be called when # The headerchange attribute can be assigned a function to be called when
# changing headers. The signature is: # changing headers. The signature is:
# headerchange(msg,name,value) -> None # headerchange(msg,name,value) -> None
self.headerchange = None
def get_param(self, param, failobj=None, header='content-type', unquote=True): def get_param(self, param, failobj=None, header='content-type', unquote=True):
val = Message.get_param(self,param,failobj,header,unquote) val = Message.get_param(self,param,failobj,header,unquote)