programming:python:python-libmilter
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
programming:python:python-libmilter [2012/02/18 20:36] – jay | programming:python:python-libmilter [2012/02/22 23:22] – [Donations] jay | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== | + | ====== |
+ | |||
+ | ===== About ===== | ||
python-libmilter started as a project to maximize the portability of libmilter. | python-libmilter started as a project to maximize the portability of libmilter. | ||
Line 6: | Line 8: | ||
Note that this documentation assumes a good working knowledge of the SMTP protocol as defined in RFC 2822. | Note that this documentation assumes a good working knowledge of the SMTP protocol as defined in RFC 2822. | ||
- | ====== Bug Reports, Issues and Contributions | + | ===== Getting It ===== |
+ | You have a couple of options for getting this package. | ||
+ | |||
+ | You can also use '' | ||
+ | <code bash> | ||
+ | pip install python-libmilter | ||
+ | </ | ||
+ | |||
+ | ===== Donations ===== | ||
+ | By no means should anyone feel they //have// to donate. | ||
+ | |||
+ | < | ||
+ | <form action=" | ||
+ | <input type=" | ||
+ | <input type=" | ||
+ | <input type=" | ||
+ | <img alt="" | ||
+ | </ | ||
+ | </ | ||
+ | ===== Bug Reports, Issues and Contributions ===== | ||
Please submit any and all bug reports/ | Please submit any and all bug reports/ | ||
Line 13: | Line 34: | ||
If you have any other questions, you can always email me directly at admin@splitstreams.com. | If you have any other questions, you can always email me directly at admin@splitstreams.com. | ||
- | ====== The Library | + | ===== The Library ===== |
You will find that the library file is split up into sections defining the constants for client server options and flags. | You will find that the library file is split up into sections defining the constants for client server options and flags. | ||
- | ===== Constants | + | ==== Constants ==== |
- | ==== SMFIF_* | + | === SMFIF_* === |
These are flags that are set defining mutations that we wish to make in our app. This first set is compatible with version 2 of the milter protocol. | These are flags that are set defining mutations that we wish to make in our app. This first set is compatible with version 2 of the milter protocol. | ||
Line 40: | Line 61: | ||
^ SMFIF_ALLOPTS | This sets all flags | | ^ SMFIF_ALLOPTS | This sets all flags | | ||
- | ==== SMFIP_* | + | === SMFIP_* === |
These are protocol options, and can be set in a couple of different ways. The first way is to simply set them when setting up your factory (TODO: link to the factory section). | These are protocol options, and can be set in a couple of different ways. The first way is to simply set them when setting up your factory (TODO: link to the factory section). | ||
Line 75: | Line 96: | ||
^ SMFIP_ALLPROTOS | Sets all protocol options | | ^ SMFIP_ALLPROTOS | Sets all protocol options | | ||
- | ==== Response Constants | + | === Response Constants === |
These are what you use to reply to the MTA with what you want it to do currently. | These are what you use to reply to the MTA with what you want it to do currently. | ||
Line 98: | Line 119: | ||
| SHUTDOWN | 421: shutdown (internal to MTA) | | | SHUTDOWN | 421: shutdown (internal to MTA) | | ||
- | ==== All the Rest ==== | + | === All the Rest === |
All the rest of the standard constants are defined as well. I've only documented the ones above as these are the only ones directly used. | All the rest of the standard constants are defined as well. I've only documented the ones above as these are the only ones directly used. | ||
- | ===== Overridable Callbacks | + | ==== Overridable Callbacks ==== |
Here is the list of the overridable callbacks. | Here is the list of the overridable callbacks. | ||
Line 108: | Line 129: | ||
As an aside, all this information is also available with a '' | As an aside, all this information is also available with a '' | ||
- | ==== connect(self , hostname , family , ip , port , cmdDict) | + | === connect(self , hostname , family , ip , port , cmdDict) === |
This gets the connection info: | This gets the connection info: | ||
Line 118: | Line 139: | ||
| dict | cmdDict | The raw dictionary of items sent by the MTA | | | dict | cmdDict | The raw dictionary of items sent by the MTA | | ||
- | ==== helo(self , heloname) | + | === helo(self , heloname) === |
This gets the HELO string sent by the client | This gets the HELO string sent by the client | ||
Line 124: | Line 145: | ||
| str | heloname | What the client HELOed as | | | str | heloname | What the client HELOed as | | ||
- | ==== mailFrom(self , frAddr , cmdDict) | + | === mailFrom(self , frAddr , cmdDict) === |
This gets the MAIL FROM envelope address | This gets the MAIL FROM envelope address | ||
Line 131: | Line 152: | ||
| dict | cmdDict | The raw dictionary of items sent by the MTA | | | dict | cmdDict | The raw dictionary of items sent by the MTA | | ||
- | ==== rcpt(self , recip , cmdDict) | + | === rcpt(self , recip , cmdDict) === |
This gets the RCPT TO envelope address | This gets the RCPT TO envelope address | ||
Line 138: | Line 159: | ||
| dict | cmdDict | The raw dictionary of items sent by the MTA | | | dict | cmdDict | The raw dictionary of items sent by the MTA | | ||
- | ==== header(self , key , val , cmdDict) | + | === header(self , key , val , cmdDict) === |
This gets one header from the email at a time. The " | This gets one header from the email at a time. The " | ||
Line 148: | Line 169: | ||
| dict | cmdDict | The raw dictionary of items sent by the MTA | | | dict | cmdDict | The raw dictionary of items sent by the MTA | | ||
- | ==== eoh(self , cmdDict) | + | === eoh(self , cmdDict) === |
This tells you when all the headers have been received | This tells you when all the headers have been received | ||
Line 154: | Line 175: | ||
| dict | cmdDict | The raw dictionary of items sent by the MTA | | | dict | cmdDict | The raw dictionary of items sent by the MTA | | ||
- | ==== data(self , cmdDict) | + | === data(self , cmdDict) === |
This is called when the client sends DATA | This is called when the client sends DATA | ||
Line 160: | Line 181: | ||
| dict | cmdDict | The raw dictionary of items sent by the MTA | | | dict | cmdDict | The raw dictionary of items sent by the MTA | | ||
- | ==== body(self , chunk , cmdDict) | + | === body(self , chunk , cmdDict) === |
This gets a chunk of the body of the email from the MTA. This will be called many times for a large email. | This gets a chunk of the body of the email from the MTA. This will be called many times for a large email. | ||
Line 167: | Line 188: | ||
| dict | cmdDict | The raw dictionary of items sent by the MTA | | | dict | cmdDict | The raw dictionary of items sent by the MTA | | ||
- | ==== eob(self , cmdDict) | + | === eob(self , cmdDict) === |
This signals that the MTA has sent the entire body of the email. This is the callback where you can use [[# | This signals that the MTA has sent the entire body of the email. This is the callback where you can use [[# | ||
Line 173: | Line 194: | ||
| dict | cmdDict | The raw dictionary of items sent by the MTA | | | dict | cmdDict | The raw dictionary of items sent by the MTA | | ||
- | ==== close(self) | + | === close(self) === |
Here, you can close any open resources. | Here, you can close any open resources. | ||
**NOTE:** this method is **always** called when everything is complete. | **NOTE:** this method is **always** called when everything is complete. | ||
- | ==== abort(self) | + | === abort(self) === |
This is called when an ABORT is received from the MTA. | This is called when an ABORT is received from the MTA. | ||
**NOTE:** Postfix will send an ABORT at the end of every message. | **NOTE:** Postfix will send an ABORT at the end of every message. | ||
- | ===== Modification Methods | + | ==== Modification Methods ==== |
These are all the methods that can **only be used in the eob()** callback in your milter to modify the message/ | These are all the methods that can **only be used in the eob()** callback in your milter to modify the message/ | ||
- | ==== addRcpt(self , rcpt , esmtpAdd='' | + | === addRcpt(self , rcpt , esmtpAdd='' |
This will tell the MTA to add a recipient to the email. | This will tell the MTA to add a recipient to the email. | ||
Line 198: | Line 219: | ||
**IMPORTANT: | **IMPORTANT: | ||
- | ==== delRcpt(self , rcpt) ==== | + | === delRcpt(self , rcpt) === |
This will tell the MTA to delete a recipient from the email | This will tell the MTA to delete a recipient from the email | ||
Line 205: | Line 226: | ||
You must have the '' | You must have the '' | ||
- | ==== replBody(self , body) ==== | + | === replBody(self , body) === |
This will replace the body of the email with a new body. This is how you would make changes to the body of an email. | This will replace the body of the email with a new body. This is how you would make changes to the body of an email. | ||
You must have the '' | You must have the '' | ||
- | ==== addHeader(self , key , val) ==== | + | === addHeader(self , key , val) === |
This will add a header to the email in the form: "key: val" | This will add a header to the email in the form: "key: val" | ||
You must have the '' | You must have the '' | ||
- | ==== chgHeader(self , key , val='' | + | === chgHeader(self , key , val='' |
This will change a header in the email. | This will change a header in the email. | ||
You must have the '' | You must have the '' | ||
- | ==== quarantine(self , msg='' | + | === quarantine(self , msg='' |
This tells the MTA to quarantine the message (put it in the HOLD queue in Postfix). | This tells the MTA to quarantine the message (put it in the HOLD queue in Postfix). | ||
You must have the '' | You must have the '' | ||
- | ==== setReply(self , rcode , xcode , msg) ==== | + | === setReply(self , rcode , xcode , msg) === |
Sets the reply that the MTA will use for this message.\\ | Sets the reply that the MTA will use for this message.\\ | ||
The '' | The '' | ||
Line 236: | Line 257: | ||
</ | </ | ||
- | ==== chgFrom(self , frAddr , esmtpAdd='' | + | === chgFrom(self , frAddr , esmtpAdd='' |
This tells the MTA to change the envelope From address, with optional ESMTP extensions in '' | This tells the MTA to change the envelope From address, with optional ESMTP extensions in '' | ||
You must have the '' | You must have the '' | ||
- | ==== skip(self) | + | === skip(self) === |
This tells the MTA that we don't want any more of this type of callback. | This tells the MTA that we don't want any more of this type of callback. | ||
Line 248: | Line 269: | ||
You must have the '' | You must have the '' | ||
- | ===== Factories | + | ==== Factories ==== |
When you are building your own milter, you will have to choose a factory to use to run your milter. | When you are building your own milter, you will have to choose a factory to use to run your milter. | ||
Line 269: | Line 290: | ||
| sockChmod | int | What to '' | | sockChmod | int | What to '' | ||
- | ==== AsyncFactory | + | === AsyncFactory === |
This factory is somewhat modeled after a Twisted implementation, | This factory is somewhat modeled after a Twisted implementation, | ||
Line 290: | Line 311: | ||
**NOTE:** No " | **NOTE:** No " | ||
- | ==== ThreadFactory | + | === ThreadFactory === |
This is a factory, wherein each connection from the MTA ends up in it's own thread. | This is a factory, wherein each connection from the MTA ends up in it's own thread. | ||
Line 304: | Line 325: | ||
</ | </ | ||
- | ==== ForkFactory | + | === ForkFactory === |
This is a factory that will fork a child process for each incoming connection from the MTA. This will add some more overhead on your machine, but is recommended for the best concurrency. | This is a factory that will fork a child process for each incoming connection from the MTA. This will add some more overhead on your machine, but is recommended for the best concurrency. | ||
Line 316: | Line 337: | ||
</ | </ | ||
- | ====== Example | + | ===== Example ===== |
See the examples directory in the distribution for a complete test milter example using the [[# | See the examples directory in the distribution for a complete test milter example using the [[# |
programming/python/python-libmilter.txt · Last modified: 2023/11/10 20:06 by jay