From f01b113fa1f2e24ed80111a1748bdc53790661f9 Mon Sep 17 00:00:00 2001
From: Martin Blapp <mbr@FreeBSD.org>
Date: Sat, 15 Apr 2006 09:07:49 +0000
Subject: Handle unknown encodings. Even binary parts are handled now. Treat
 empty type as 'text'.

---
 mail/pyzor/files/patch-handle_unknown_encodings | 96 +++++++++++++++++++++++++
 mail/pyzor/files/patch-unknowntype              | 12 ++++
 2 files changed, 108 insertions(+)
 create mode 100644 mail/pyzor/files/patch-handle_unknown_encodings
 create mode 100644 mail/pyzor/files/patch-unknowntype

(limited to 'mail/pyzor')

diff --git a/mail/pyzor/files/patch-handle_unknown_encodings b/mail/pyzor/files/patch-handle_unknown_encodings
new file mode 100644
index 000000000000..fa0b5c9fcca2
--- /dev/null
+++ b/mail/pyzor/files/patch-handle_unknown_encodings
@@ -0,0 +1,96 @@
+--- lib/pyzor/client.py	Sun Sep  8 22:37:15 2002
++++ lib/pyzor/client.py	Wed Aug  3 10:58:03 2005
+@@ -466,7 +470,7 @@
+ 
+         (fp, offsets) = self.get_line_offsets(fp)
+         
+-        # did we get an empty file?
++	# did we get an empty (parsed output)file?
+         if len(offsets) == 0:
+             return
+ 
+@@ -662,39 +666,66 @@
+         self.multifile = None
+         self.curfile   = None
+ 
++	# Check if we got a mail or not. Set type to binary if there is no 'From:' header and
++	# type text/plain with encoding 7bit. 7bit is passed trough anyway so nobody cares.
++	if (not msg.has_key("From") and self.type == 'text' and msg.subtype == 'plain' and msg.getencoding() == '7bit'):
++		self.type = 'binary';
++
+         if self.type == 'text':
+             encoding = msg.getencoding()
+-            if encoding == '7bit':
+-                self.curfile = msg.fp
+-            else:
+-                self.curfile = tempfile.TemporaryFile()
+-                mimetools.decode(msg.fp, self.curfile, encoding)
+-                self.curfile.seek(0)
+-                
++            self.curfile = msg.fp
++            if encoding != '7bit':
++                # fix bad encoding name
++                if encoding == '8bits':
++                    encoding = '8bit'
++                try:
++                    newcurfile = tempfile.TemporaryFile()
++                    mimetools.decode(msg.fp, newcurfile, encoding)
++                    newcurfile.seek(0)
++                    self.curfile = newcurfile
++                except:
++                    # ignore encoding on errors, pass msg as is
++                    pass
++
+         elif self.type == 'multipart':
+             import multifile
+             self.multifile = multifile.MultiFile(msg.fp, seekable=False)
+             self.multifile.push(msg.getparam('boundary'))
+-            self.multifile.next()
+-            self.curfile = self.__class__(self.multifile)
+-
++	    try:
++		self.multifile.next()
++		self.curfile = self.__class__(self.multifile)
++	    except:
++	    	#
++	    	# Catch multipart decoding errors
++	    	#
++		fp.seek(0)
++		self.curfile = fp
++		self.type = 'binary'
+ 
+         if self.type == 'text' or self.type == 'multipart':
+             assert self.curfile is not None
++        elif self.type == 'binary':
++	    try:
++	 	fp.seek(0)
++	    except:
++	    	pass
++	    self.curfile = fp
+         else:
+             assert self.curfile is None
+ 
+         
+     def readline(self):
+         l = ''
+-        if self.type in ('text', 'multipart'):
+-            l = self.curfile.readline()
+-
+-        if self.type == 'multipart' and not l and self.multifile.next():
+-            self.curfile = self.__class__(self.multifile)
+-            # recursion.  Could get messy if
+-            # we get a bunch of empty multifile parts
+-            l = self.readline()
++	try:
++		if self.type in ('text', 'multipart', 'binary'):
++		    l = self.curfile.readline()
++		if self.type == 'multipart' and not l and self.multifile.next():
++		    self.curfile = self.__class__(self.multifile)
++		    # recursion.  Could get messy if
++		    # we get a bunch of empty multifile parts
++		    l = self.readline()
++	except (TypeError, multifile.Error):
++		pass
+         return l
+ 
+ 
diff --git a/mail/pyzor/files/patch-unknowntype b/mail/pyzor/files/patch-unknowntype
new file mode 100644
index 000000000000..8591be0d7066
--- /dev/null
+++ b/mail/pyzor/files/patch-unknowntype
@@ -0,0 +1,12 @@
+--- lib/pyzor/client.py	Tue Aug 23 14:53:09 2005
++++ lib/pyzor/client.py	Tue Aug 23 14:51:36 2005
+@@ -693,6 +692,9 @@
+ 	# type text/plain with encoding 7bit. 7bit is passed trough anyway so nobody cares.
+ 	if (not msg.has_key("From") and self.type == 'text' and msg.subtype == 'plain' and msg.getencoding() == '7bit'):
+ 		self.type = 'binary';
++	
++	if self.type is '':
++	    self.type = 'text';
+ 
+         if self.type == 'text':
+             encoding = msg.getencoding()
-- 
cgit v1.2.3