diff --git a/extensions/webmail/views.py b/extensions/webmail/views.py index 62a973924..d537b9bfe 100644 --- a/extensions/webmail/views.py +++ b/extensions/webmail/views.py @@ -132,8 +132,16 @@ def getattachment(request, folder, mail_id): fname = unicode(decoded[0][0], decoded[0][1]) if fname == request.GET["fname"]: resp = HttpResponse(part.get_payload(decode=1)) - for hdr in ["Content-Disposition", "Content-Type"]: + for hdr in ["Content-Type", "Content-Transfer-Encoding"]: + if not part.has_key(hdr): + continue resp[hdr] = re.sub("\s", "", part[hdr]) + if part.has_key("Content-Disposition"): + resp["Content-Disposition"] = \ + re.sub("\s", "", part["Content-Disposition"]) + else: + resp["Content-Disposition"] = \ + "attachment; filename=%s" % fname resp["Content-Length"] = len(resp.content) return resp raise Http404 diff --git a/lib/email_listing.py b/lib/email_listing.py index 92b9b3201..8c40d84d5 100644 --- a/lib/email_listing.py +++ b/lib/email_listing.py @@ -148,10 +148,14 @@ class Email(object): if part.has_key("Content-Disposition"): if re.match("^attachment", part["Content-Disposition"]): self.attachments += [part] + continue if part.get_content_type() in ("text/html", "text/plain"): contents[part.get_content_subtype()] += part.get_payload(decode=True) if mode != "html" or links == "0": continue + if part.get_content_maintype() == "application": + self.attachments += [part] + continue if part.get_content_maintype() == "image": if part.has_key("Content-Location"): @@ -159,7 +163,7 @@ class Email(object): if re.match("^http:", fname): path = fname else: - path = os.path.abspath("static/tmp" + fname) + path = os.path.abspath("static/tmp/" + fname) fp = open(path, "wb") fp.write(part.get_payload(decode=True)) fp.close()