Consistently use surrogate escape by default.
This commit is contained in:
+3
-3
@@ -328,7 +328,7 @@ class Base(object):
|
|||||||
# or trap utf-8 conversion exception, etc.
|
# or trap utf-8 conversion exception, etc.
|
||||||
def envfrom_bytes(self,*b):
|
def envfrom_bytes(self,*b):
|
||||||
try:
|
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
|
except UnicodeDecodeError: s = b
|
||||||
return self.envfrom(fld,*s)
|
return self.envfrom(fld,*s)
|
||||||
## Called when the SMTP client says MAIL FROM. Called by the
|
## 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.
|
# or trap utf-8 conversion exception, etc.
|
||||||
def envrcpt_bytes(self,*b):
|
def envrcpt_bytes(self,*b):
|
||||||
try:
|
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
|
except UnicodeDecodeError: s = b
|
||||||
return self.envrcpt(fld,*s)
|
return self.envrcpt(fld,*s)
|
||||||
## Called when the SMTP client says RCPT TO. Called by the
|
## 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.
|
# to pass bytes to @link #header the header callback @endlink instead.
|
||||||
def header_bytes(self,fld,val):
|
def header_bytes(self,fld,val):
|
||||||
try:
|
try:
|
||||||
s = val.decode(encoding='utf-8')
|
s = val.decode(encoding='utf-8',errors='surrogateescape')
|
||||||
except UnicodeDecodeError: s = val
|
except UnicodeDecodeError: s = val
|
||||||
return self.header(fld,s)
|
return self.header(fld,s)
|
||||||
## Called for each header field in the message body.
|
## Called for each header field in the message body.
|
||||||
|
|||||||
@@ -548,7 +548,7 @@ if __name__ == '__main__':
|
|||||||
return Milter.CONTINUE
|
return Milter.CONTINUE
|
||||||
|
|
||||||
for fname in sys.argv[1:]:
|
for fname in sys.argv[1:]:
|
||||||
fp = open(fname,'rb')
|
with open(fname,'rb') as fp:
|
||||||
msg = message_from_file(fp)
|
msg = message_from_file(fp)
|
||||||
email.iterators._structure(msg)
|
email.iterators._structure(msg)
|
||||||
check_attachments(msg,_list_attach)
|
check_attachments(msg,_list_attach)
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ class sampleMilter(Milter.Milter):
|
|||||||
|
|
||||||
# even if we wanted the Taiwanese spam, we can't read Chinese
|
# even if we wanted the Taiwanese spam, we can't read Chinese
|
||||||
# (delete if you read chinese mail)
|
# (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'):
|
if val.startswith('=?big5') or val.startswith('=?ISO-2022-JP'):
|
||||||
self.log('REJECT: %s: %s' % (name,val))
|
self.log('REJECT: %s: %s' % (name,val))
|
||||||
#self.setreply('550','','Go away spammer')
|
#self.setreply('550','','Go away spammer')
|
||||||
|
|||||||
Reference in New Issue
Block a user