f01b113fa1
Treat empty type as 'text'.
96 lines
3.1 KiB
Text
96 lines
3.1 KiB
Text
--- 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
|
|
|
|
|