Two fixes

Don't send Content-Length header if not needed. (see #480)
Always use build_header... (see #473)
This commit is contained in:
Antoine Nguyen
2013-09-25 15:02:24 +02:00
parent 084004c0fc
commit a68524264d
+18 -5
View File
@@ -1,6 +1,6 @@
# coding: utf-8
import os
from rfc6266 import build_header
from rfc6266 import build_header, parse_headers
from django.conf import settings
from django.http import HttpResponse
from django.template import Template, Context
@@ -29,6 +29,14 @@ from templatetags import webextras
def getattachment(request):
"""Fetch a message attachment
The tricky part here consists in properly format the
*Content-Disposition* header. We use the rfc6266 package to encode
headers according to RFC5987 and RFC6266.
Even if the header received from Dovecot is already encoded, we
decode and re-encode it to make sure it uses UTF-8. IE doesn't
support the ISO-8859-1 encoding even if it is allowed by RFCs.
FIXME: par manque de caching, le bodystructure du message est
redemandé pour accéder aux headers de cette pièce jointe.
@@ -52,15 +60,20 @@ def getattachment(request):
if type(disp[1][0]) != dict:
atype, fieldname, filename = disp[0], disp[1][0], disp[1][1]
else:
atype, fieldname, filename = disp[0], disp[1][0]['struct'][0], disp[1][0]['struct'][1]
atype, fieldname, filename = \
disp[0], disp[1][0]['struct'][0], disp[1][0]['struct'][1]
if fieldname.endswith('*'):
cd = '%s; %s=%s' % (atype, fieldname, filename)
else:
cd = '%s; %s="%s"' % (atype, fieldname, filename)
fname = parse_headers(cd).filename_unsafe
else:
cd = build_header(request.GET["fname"])
resp["Content-Disposition"] = cd
resp["Content-Length"] = partdef["size"]
fname = request.GET.get("fname", None)
if fname is None:
raise WebmailError(_("Invalid request"))
resp["Content-Disposition"] = build_header(fname)
if int(partdef["size"]) < 200:
resp["Content-Length"] = partdef["size"]
return resp