5 Commits
2.0.4 ... 2.0.5

5 changed files with 73 additions and 72 deletions

View File

@@ -37,7 +37,7 @@ RDEPEND="
lxml? ( dev-python/lxml[${PYTHON_USEDEP}] ) lxml? ( dev-python/lxml[${PYTHON_USEDEP}] )
dev-python/netaddr[${PYTHON_USEDEP}] dev-python/netaddr[${PYTHON_USEDEP}]
dev-python/peewee[${PYTHON_USEDEP}] dev-python/peewee[${PYTHON_USEDEP}]
dev-python/pymilter[${PYTHON_USEDEP}]" >=dev-python/pymilter-1.5[${PYTHON_USEDEP}]"
python_install_all() { python_install_all() {
distutils-r1_python_install_all distutils-r1_python_install_all

View File

@@ -27,7 +27,7 @@ __all__ = [
"whitelist", "whitelist",
"QuarantineMilter"] "QuarantineMilter"]
__version__ = "2.0.4" __version__ = "2.0.5"
from pyquarantine import _runtime_patches from pyquarantine import _runtime_patches
@@ -100,7 +100,7 @@ class QuarantineMilter(Milter.Base):
self.logger.warning(f"unable to serialize message as bytes: {e}") self.logger.warning(f"unable to serialize message as bytes: {e}")
try: try:
self.logger.warning("try to serialize as str and encode") self.logger.warning("try to serialize as str and encode")
data = self.msg.as_string().encode("ascii", errors="replace") data = self.msg.as_string().encode(errors="replace")
except Exception as e: except Exception as e:
self.logger.error( self.logger.error(
f"unable to serialize message, giving up: {e}") f"unable to serialize message, giving up: {e}")
@@ -208,6 +208,7 @@ class QuarantineMilter(Milter.Base):
return Milter.CONTINUE return Milter.CONTINUE
@Milter.decode("replace")
def envfrom(self, mailfrom, *str): def envfrom(self, mailfrom, *str):
try: try:
self.mailfrom = "@".join(parse_addr(mailfrom)).lower() self.mailfrom = "@".join(parse_addr(mailfrom)).lower()
@@ -219,6 +220,7 @@ class QuarantineMilter(Milter.Base):
return Milter.CONTINUE return Milter.CONTINUE
@Milter.decode("replace")
def envrcpt(self, to, *str): def envrcpt(self, to, *str):
try: try:
self.rcpts.add("@".join(parse_addr(to)).lower()) self.rcpts.add("@".join(parse_addr(to)).lower())
@@ -243,6 +245,7 @@ class QuarantineMilter(Milter.Base):
return Milter.CONTINUE return Milter.CONTINUE
@Milter.decode("replace")
def header(self, field, value): def header(self, field, value):
try: try:
# remove CR and LF from address fields, otherwise pythons # remove CR and LF from address fields, otherwise pythons
@@ -258,11 +261,7 @@ class QuarantineMilter(Milter.Base):
v = v.replace("\r", "").replace("\n", "") v = v.replace("\r", "").replace("\n", "")
value = Header(s=v).encode() value = Header(s=v).encode()
# remove surrogates self.fp.write(field.encode() + b": " + value.encode() + b"\r\n")
field = field.encode("ascii", errors="replace")
value = value.encode("ascii", errors="replace")
self.fp.write(field + b": " + value + b"\r\n")
except Exception as e: except Exception as e:
self.logger.exception( self.logger.exception(
f"an exception occured in header method: {e}") f"an exception occured in header method: {e}")

View File

@@ -12,6 +12,7 @@
# along with pyquarantine. If not, see <http://www.gnu.org/licenses/>. # along with pyquarantine. If not, see <http://www.gnu.org/licenses/>.
# #
from sys import version_info
import encodings import encodings
@@ -150,6 +151,24 @@ def get_obs_local_part(value):
setattr(email._header_value_parser, "get_obs_local_part", get_obs_local_part) setattr(email._header_value_parser, "get_obs_local_part", get_obs_local_part)
#######################################
# add charset alias for windows-874 #
#######################################
#
# https://bugs.python.org/issue17254
#
# fix: https://github.com/python/cpython/pull/10237
aliases = encodings.aliases.aliases
for alias in ["windows-874", "windows_874"]:
if alias not in aliases:
aliases[alias] = "cp874"
setattr(encodings.aliases, "aliases", aliases)
if version_info.major == 3 and version_info.minor < 10:
# https://bugs.python.org/issue30681 # https://bugs.python.org/issue30681
# #
# fix: https://github.com/python/cpython/pull/22090 # fix: https://github.com/python/cpython/pull/22090
@@ -210,20 +229,3 @@ def parse(cls, value, kwds):
setattr(email.headerregistry.DateHeader, "parse", parse) setattr(email.headerregistry.DateHeader, "parse", parse)
#######################################
# add charset alias for windows-874 #
#######################################
#
# https://bugs.python.org/issue17254
#
# fix: https://github.com/python/cpython/pull/10237
aliases = encodings.aliases.aliases
for alias in ["windows-874", "windows_874"]:
if alias not in aliases:
aliases[alias] = "cp874"
setattr(encodings.aliases, "aliases", aliases)

View File

@@ -135,7 +135,7 @@ def main():
sysloghandler = logging.handlers.SysLogHandler( sysloghandler = logging.handlers.SysLogHandler(
address="/dev/log", facility=logging.handlers.SysLogHandler.LOG_MAIL) address="/dev/log", facility=logging.handlers.SysLogHandler.LOG_MAIL)
sysloghandler.setFormatter( sysloghandler.setFormatter(
logging.Formatter("pyquarantine: %(message)s")) logging.Formatter(f"{name}[%(process)d]: %(message)s"))
root_logger.addHandler(sysloghandler) root_logger.addHandler(sysloghandler)
logger.info("milter starting") logger.info("milter starting")

View File

@@ -48,6 +48,6 @@ setup(name = "pyquarantine",
] ]
) )
], ],
install_requires = ["pymilter", "jsonschema", "netaddr", "beautifulsoup4[lxml]", "peewee"], install_requires = ["pymilter >= 1.5", "jsonschema", "netaddr", "beautifulsoup4[lxml]", "peewee"],
python_requires = ">=3.9" python_requires = ">=3.9"
) )