The first three reasons have been handled.

see #308
This commit is contained in:
Antoine Nguyen
2012-09-19 17:23:50 +02:00
parent 7ae0910df8
commit 118c0b9aaa
4 changed files with 24 additions and 14 deletions
+1
View File
@@ -102,6 +102,7 @@ class BodyStructure(object):
extensions = ["envelopestruct", "bodystruct", "textlines"] + extensions
for idx, value in enumerate(definition[7:]):
params[extensions[idx]] = value
self.attachments += [params]
def load_from_definition(self, definition, multisubtype=None):
+19 -11
View File
@@ -180,19 +180,27 @@ class ImapEmail(Email):
mformat = self.dformat if self.bs.contents.has_key(self.dformat) else fallback_fmt
pnum = self.bs.contents[mformat]['pnum']
data = self.imapc._cmd("FETCH", mailid, "(BODY.PEEK[%s])" % pnum)
content = decode_payload(self.bs.contents[mformat]['encoding'],
data[int(mailid)]['BODY[%s]' % pnum])
charset = self._find_content_charset(mformat)
if charset is not None:
content = content.decode(charset)
if len(self.bs.contents):
pnum = self.bs.contents[mformat]['pnum']
data = self.imapc._cmd("FETCH", mailid, "(BODY.PEEK[%s])" % pnum)
content = decode_payload(self.bs.contents[mformat]['encoding'],
data[int(mailid)]['BODY[%s]' % pnum])
charset = self._find_content_charset(mformat)
if charset is not None:
try:
content = content.decode(charset)
except (UnicodeDecodeError, LookupError):
import chardet
result = chardet.detect(content)
content = content.decode(result['encoding'])
self._fetch_inlines()
self.body = \
getattr(self, "viewmail_%s" % mformat)(content, links=links)
else:
self.body = None
self._find_attachments()
self._fetch_inlines()
self.body = \
getattr(self, "viewmail_%s" % mformat)(content, links=links)
msg = email.message_from_string(headers)
for hdr in self.headernames:
+3 -3
View File
@@ -40,9 +40,9 @@ def getattachment(request):
resp["Content-Transfer-Encoding"] = partdef["encoding"]
if partdef["disposition"] != 'NIL':
disp = partdef["disposition"]
cd = "%s; %s=%s" % (disp[0], disp[1][0], disp[1][1])
cd = '%s; %s="%s"' % (disp[0], disp[1][0], disp[1][1])
else:
cd = "attachment; filename=%s" % request.GET["fname"]
cd = 'attachment; filename="%s"' % request.GET["fname"]
resp["Content-Disposition"] = cd
resp["Content-Length"] = partdef["size"]
return resp
@@ -408,7 +408,7 @@ def getmailcontent(request):
email = ImapEmail(mbox, mailid, request, links=int(request.GET["links"]))
return _render(request, "common/viewmail.html", {
"headers" : email.render_headers(folder=mbox, mail_id=mailid),
"folder" : mbox, "imapid" : mailid, "mailbody" : email.body
"folder" : mbox, "imapid" : mailid, "mailbody" : email.body if email.body else ""
})
def viewmail(request):
+1
View File
@@ -3,3 +3,4 @@ south
lxml
pycrypto
sievelib
chardet