I got some time to hack this weekend, and added a new module to
pythonfilter. The new module is called "xfilter", and allows you to
modify messages from courier filters.
The module is implemented by loading the incoming messages as python
email.message objects which a filter can modify and submit. When a
modified message is submitted, the new copy is sent to the submit
program, and the recipients of the original message are marked as completed.
http://phantom.dragonsdawn.net/~gordon/courier-patches/courier-pythonfilter/
I need to fix the use of as_string() in the submit method, but the code
should be suitable for testing now. If anyone's interested, please have
a look at the code. Let me know if the interface is ugly, or if there
are bugs which need fixing.
As an example, this filter adds a new, useless header:
#!/usr/bin/python
# testxfilter -- Courier filter which adds a useless header
import sys
import courier.xfilter
# Record in the system log that this filter was initialized.
sys.stderr.write('Initialized the "testxfilter" python filter\n')
def doFilter(bodyFile, controlFileList):
"""Add a new header to incoming mail."""
try:
mfilter = courier.xfilter.XFilter('testxfilter', bodyFile,
controlFileList)
except courier.xfilter.LoopError, e:
# LoopError indicates that we've already filtered this message.
return ''
mmsg = mfilter.getMessage()
mmsg['X-Test-Header'] = 'A new header!'
mfilter.submit()
# Return 250, no more filters should be run on this copy.
return '250 OK'
-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
courier-users mailing list
[email protected]
Unsubscribe: https://lists.sourceforge.net/lists/listinfo/courier-users