Consistently use surrogate escape by default.

This commit is contained in:
Stuart D. Gathman
2020-06-17 12:54:58 -04:00
parent 0efddd316a
commit 132e8326b5
3 changed files with 6 additions and 6 deletions
+3 -3
View File
@@ -328,7 +328,7 @@ class Base(object):
# or trap utf-8 conversion exception, etc.
def envfrom_bytes(self,*b):
try:
s = (v.decode(encoding='utf-8') for v in b)
s = (v.decode(encoding='utf-8',errors='surrogateescape') for v in b)
except UnicodeDecodeError: s = b
return self.envfrom(fld,*s)
## Called when the SMTP client says MAIL FROM. Called by the
@@ -349,7 +349,7 @@ class Base(object):
# or trap utf-8 conversion exception, etc.
def envrcpt_bytes(self,*b):
try:
s = (v.decode(encoding='utf-8') for v in b)
s = (v.decode(encoding='utf-8',errors='surrogateescape') for v in b)
except UnicodeDecodeError: s = b
return self.envrcpt(fld,*s)
## Called when the SMTP client says RCPT TO. Called by the
@@ -377,7 +377,7 @@ class Base(object):
# to pass bytes to @link #header the header callback @endlink instead.
def header_bytes(self,fld,val):
try:
s = val.decode(encoding='utf-8')
s = val.decode(encoding='utf-8',errors='surrogateescape')
except UnicodeDecodeError: s = val
return self.header(fld,s)
## Called for each header field in the message body.
+1 -1
View File
@@ -548,7 +548,7 @@ if __name__ == '__main__':
return Milter.CONTINUE
for fname in sys.argv[1:]:
fp = open(fname,'rb')
with open(fname,'rb') as fp:
msg = message_from_file(fp)
email.iterators._structure(msg)
check_attachments(msg,_list_attach)
+1 -1
View File
@@ -73,7 +73,7 @@ class sampleMilter(Milter.Milter):
# even if we wanted the Taiwanese spam, we can't read Chinese
# (delete if you read chinese mail)
print('val=',val)
print('val=',val.encode(errors='surrogateescape'))
if val.startswith('=?big5') or val.startswith('=?ISO-2022-JP'):
self.log('REJECT: %s: %s' % (name,val))
#self.setreply('550','','Go away spammer')