From cdae26af47b2fd26b45066e186ae2ad200f83bea Mon Sep 17 00:00:00 2001 From: "Stuart D. Gathman" Date: Fri, 12 Jun 2020 16:51:38 -0400 Subject: [PATCH] More py3 fixes, switch to setuptools. --- MANIFEST.in | 2 +- Milter/dsn.py | 7 ++++-- README => README.md | 60 ++++++++++++++------------------------------- TODO | 2 ++ setup.py | 12 ++++----- 5 files changed, 31 insertions(+), 52 deletions(-) rename README => README.md (80%) diff --git a/MANIFEST.in b/MANIFEST.in index dca383e..0f57d33 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -2,7 +2,7 @@ include COPYING include TODO include NEWS include CREDITS -include README +include README.md include ChangeLog include MANIFEST.in include testsample.py diff --git a/Milter/dsn.py b/Milter/dsn.py index b27f749..aca56aa 100644 --- a/Milter/dsn.py +++ b/Milter/dsn.py @@ -72,10 +72,13 @@ from __future__ import print_function import smtplib import socket -from email.Message import Message +try: + from email.message import Message +except: + from email.Message import Message import Milter +import Milter.dns as dns import time -import dns ## Send DSN. # Try the published MX names in order, rejecting obviously bogus entries diff --git a/README b/README.md similarity index 80% rename from README rename to README.md index fa72cfd..2e6ecfc 100644 --- a/README +++ b/README.md @@ -1,5 +1,4 @@ -Abstract --------- +# Abstract This is a python extension module to enable python scripts to attach to Sendmail's libmilter API, enabling filtering of messages as they arrive. @@ -7,54 +6,34 @@ Since it's a script, you can do anything you want to the message - screen out viruses, collect statistics, add or modify headers, etc. You can, at any point, tell Sendmail to reject, discard, or accept the message. +Additional python modules provide for navigating and modifying MIME parts, and +sending DSNs or doing CBVs. -Requirements ------------- +# Requirements -Python milter extension: http://https://pypi.python.org/pypi/pymilter/ +Python milter extension: https://pypi.python.org/pypi/pymilter/ Python: http://www.python.org Sendmail: http://www.sendmail.org -NB: From Sendmail's libmilter/README: +# Quick Installation -libmilter requires pthread support in the operating system. Moreover, it -requires that the library functions it uses are thread safe; which is true -for the operating systems libmilter has been developed and tested on. On -some operating systems this requires special compile time options (e.g., -not just -pthread). libmilter is currently known to work on (modulo problems -in the pthread support of some specific versions): + 1. Build and install Sendmail, enabling libmilter (see libmilter/README). + 2. Build and install Python, enabling threading. + 3. Install this module: python setup.py --help + 4. Add these two lines to sendmail.cf[a]: -FreeBSD 3.x, 4.x -SunOS 5.x (x >= 5) -AIX 4.3.x -HP UX 11.x -Linux (recent versions/distributions) + O InputMailFilters=pythonfilter + Xpythonfilter, S=local:/home/username/pythonsock -libmilter is currently not supported on: - -IRIX 6.x -Ultrix - -Quick Installation ------------------- - -1. Build and install Sendmail, enabling libmilter (see libmilter/README). -2. Build and install Python, enabling threading. -3. Install this module: python setup.py --help -4. Add these two lines to sendmail.cf[*]: - -O InputMailFilters=pythonfilter -Xpythonfilter, S=local:/home/username/pythonsock - -5. Run the sample.py example milter with: python sample.py -Note that milters should almost certainly not run as root. + 5. Run the sample.py example milter with: python sample.py + Note that milters should almost certainly not run as root. That's it. Incoming mail will cause the milter to print some things, and some email will be rejected (see the "header" method). Edit and play. See spfmilter.py for a functional SPF milter, or see bms.py for an complex milter used in production. -[*] This is for a quick test. Your sendmail.cf in most distros will get +[a] This is for a quick test. Your sendmail.cf in most distros will get overwritten whenever sendmail.mc is updated. To make a milter permanent, add something like: @@ -62,8 +41,7 @@ INPUT_MAIL_FILTER(`pythonfilter', `S=local:/home/username/pythonsock, F=T, T=C:5 to sendmail.mc instead. -Not-so-quick Installation -------------------------- +# Not-so-quick Installation First install Sendmail. Make sure you read libmilter/README in the Sendmail source directory, and make sure you enable libmilter before you build. The @@ -109,8 +87,7 @@ _FFR_MILTER for the cf macros. For example, m4 -D_FFR_MILTER ../m4/cf.m4 myconfig.mc > myconfig.cf -IPv6 Notes ----------- +# IPv6 Notes The IPv6 protocol is supported if your operation system supports it and if sendmail was compiled with IPv6 support. To determine if your @@ -165,8 +142,7 @@ be determined the hostname will appear similar to the string RFC 2553 for information on interpreting and using the flowinfo and scopeid socket attributes, both of which are integers. -Authors -------- +# Authors Jim Niemira (urmane@urmane.org) wrote the original C module and some quick and dirty python to use it. Stuart D. Gathman (stuart@gathman.org) took that diff --git a/TODO b/TODO index 2b6c97f..11920d8 100644 --- a/TODO +++ b/TODO @@ -1,2 +1,4 @@ +Test case for Milter/dsn.py + Lookup exact RFC syntax of real name / email and make Milter.utils.parse_addr() pass all unit tests. diff --git a/setup.py b/setup.py index 90868f8..8a2a611 100644 --- a/setup.py +++ b/setup.py @@ -1,10 +1,13 @@ import os import sys -from distutils.core import setup, Extension +from setuptools import setup, Extension if sys.version < '2.6.5': sys.exit('ERROR: Sorry, python 2.6.5 is required for this module.') +with open("README.md", "r") as fh: + long_description = fh.read() + # FIXME: on some versions of sendmail, smutil is renamed to sm. # On slackware and debian, leave it out entirely. It depends # on how libmilter was built by the sendmail package. @@ -16,12 +19,7 @@ modules = ["mime"] # NOTE: importing Milter to obtain version fails when milter.so not built setup(name = "pymilter", version = '1.0.5', description="Python interface to sendmail milter API", - long_description="""\ -This is a python extension module to enable python scripts to -attach to sendmail's libmilter functionality. Additional python -modules provide for navigating and modifying MIME parts, and -sending DSNs or doing CBVs. -""", + long_description=long_description, author="Jim Niemira", author_email="urmane@urmane.org", maintainer="Stuart D. Gathman",