Logging fixups: Don't traceback for non-UTF-8 data in mail headers and don't put byte string markers in logs (some remain, but are from dkimpy and should be fixed there), related to LP: #1980821

This commit is contained in:
Scott Kitterman
2022-12-05 19:21:26 -05:00
parent a90c88c53a
commit 4a04b5ea6d
2 changed files with 18 additions and 8 deletions
+5
View File
@@ -1,3 +1,8 @@
1.2.3
- Logging fixups: Don't traceback for non-UTF-8 data in mail headers and
don't put byte string markers in logs (some remain, but are from dkimpy
and should be fixed there), related to LP: #1980821.
1.2.2 2020-08-09
- Improve README.md formating for markdown display on pypi
- Improve documentation in dkimpy-milter.conf (5) and README.md for signing
+12 -7
View File
@@ -107,9 +107,10 @@ class dkimMilter(Milter.Base):
# envfrom (MAIL FROM in the SMTP protocol) seems to mark the start
# of each message.
@Milter.noreply
def envfrom(self, f, *str):
def envfrom(self, f, *stri):
if self.conf.get('Syslog') and self.conf.get('debugLevel') >= 2:
syslog.syslog("mail from: {0} {1}".format(f, str))
f = str(bytes(f, encoding='utf-8', errors='replace'))[2:-1]
syslog.syslog("mail from: {0} {1}".format(f, stri))
self.fp = io.BytesIO()
self.mailfrom = f
t = parse_addr(f)
@@ -133,7 +134,8 @@ class dkimMilter(Milter.Base):
if lname == 'dkim-signature':
if (self.conf.get('Syslog') and
self.conf.get('debugLevel') >= 1):
syslog.syslog("{0}: {1}".format(name, val))
val2 = str(bytes(val, encoding='utf-8', errors='replace'))[2:-1]
syslog.syslog("{0}: {1}".format(name, val2))
self.has_dkim += 1
if lname == 'from':
fname, self.author = parseaddr(val)
@@ -143,7 +145,8 @@ class dkimMilter(Milter.Base):
pass # self.author was not a proper email address
if (self.conf.get('Syslog') and
self.conf.get('debugLevel') >= 1):
syslog.syslog("{0}: {1}".format(name, val))
val2 = str(bytes(val, encoding='utf-8', errors='replace'))[2:-1]
syslog.syslog("{0}: {1}".format(name, val2))
elif lname == 'authentication-results':
self.arheaders.append(val)
if self.fp:
@@ -181,7 +184,8 @@ class dkimMilter(Milter.Base):
self.chgheader('authentication-results', i, '')
if (self.conf.get('Syslog') and
self.conf.get('debugLevel') >= 1):
syslog.syslog('REMOVE: {0}'.format(val))
val2 = str(bytes(val, encoding='utf-8', errors='replace'))[2:-1]
syslog.syslog('REMOVE: {0}'.format(val2))
except:
# Don't error out on unparseable AR header fiels
pass
@@ -428,7 +432,8 @@ class dkimMilter(Milter.Base):
if self.conf.get('Syslog'):
if d.domain:
syslog.syslog('DKIM: Fail ({0})'
.format(d.domain.lower()))
.format(str(d.domain.lower(), 'UTF-8',
errors='replace')))
else:
syslog.syslog('DKIM: Fail, unextractable domain')
if res:
@@ -438,7 +443,7 @@ class dkimMilter(Milter.Base):
res = False
if self.header_d:
self.arresults.append(
authres.DKIMAuthenticationResult(result=result,
authres.DKIMAuthenticationResult(result=result[2:-1],
header_i=self.header_i,
header_d=self.header_d,
header_a=self.header_a,