diff --git a/Milter/__init__.py b/Milter/__init__.py index 7e09328..0ec4b38 100755 --- a/Milter/__init__.py +++ b/Milter/__init__.py @@ -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. diff --git a/mime.py b/mime.py index ed6f683..f0e781c 100644 --- a/mime.py +++ b/mime.py @@ -548,7 +548,7 @@ if __name__ == '__main__': return Milter.CONTINUE for fname in sys.argv[1:]: - fp = open(fname,'rb') - msg = message_from_file(fp) + with open(fname,'rb') as fp: + msg = message_from_file(fp) email.iterators._structure(msg) check_attachments(msg,_list_attach) diff --git a/sample.py b/sample.py index 031c22d..92d649e 100644 --- a/sample.py +++ b/sample.py @@ -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')