示例#1
0
def getattachment(request):
    """Fetch a message attachment

    FIXME: par manque de caching, le bodystructure du message est
    redemandé pour accéder aux headers de cette pièce jointe.

    :param request: a ``Request`` object
    """
    mbox = request.GET.get("mbox", None)
    mailid = request.GET.get("mailid", None)
    pnum = request.GET.get("partnumber", None)
    if not mbox or not mailid or not pnum:
        raise WebmailError(_("Invalid request"))

    headers = {"Content-Type": "text/plain", "Content-Transfer-Encoding": None}
    imapc = get_imapconnector(request)
    partdef, payload = imapc.fetchpart(mailid, mbox, pnum)
    resp = HttpResponse(decode_payload(partdef["encoding"], payload))
    resp["Content-Type"] = partdef["Content-Type"]
    resp["Content-Transfer-Encoding"] = partdef["encoding"]
    if partdef["disposition"] != 'NIL':
        disp = partdef["disposition"]
        # FIXME : ugly hack, see fetch_parser.py for more explanation
        # :p
        if type(disp[1][0]) != dict:
            cd = '%s; %s="%s"' % (disp[0], disp[1][0], disp[1][1])
        else:
            cd = '%s; %s="%s"' % (disp[0], disp[1][0]['struct'][0],
                                  disp[1][0]['struct'][1])
    else:
        cd = 'attachment; filename="%s"' % request.GET["fname"]
    resp["Content-Disposition"] = cd
    resp["Content-Length"] = partdef["size"]
    return resp
示例#2
0
def getattachment(request):
    """Fetch a message attachment

    FIXME: par manque de caching, le bodystructure du message est
    redemandé pour accéder aux headers de cette pièce jointe.

    :param request: a ``Request`` object
    """
    mbox = request.GET.get("mbox", None)
    mailid = request.GET.get("mailid", None)
    pnum = request.GET.get("partnumber", None)
    if not mbox or not mailid or not pnum:
        raise WebmailError(_("Invalid request"))

    imapc = get_imapconnector(request)
    partdef, payload = imapc.fetchpart(mailid, mbox, pnum)
    resp = HttpResponse(decode_payload(partdef["encoding"], payload))
    resp["Content-Type"] = partdef["Content-Type"]
    resp["Content-Transfer-Encoding"] = partdef["encoding"]
    if partdef["disposition"] != 'NIL':
        disp = partdef["disposition"]
        # FIXME : ugly hack, see fetch_parser.py for more explanation
        # :p
        if type(disp[1][0]) != dict:
            cd = '%s; %s=%s' % (disp[0], disp[1][0], disp[1][1])
        else:
            cd = '%s; %s=%s' % (disp[0], disp[1][0]['struct'][0], disp[1][0]['struct'][1])
    else:
        cd = build_header(request.GET["fname"])
    resp["Content-Disposition"] = cd
    resp["Content-Length"] = partdef["size"]
    return resp
示例#3
0
文件: views.py 项目: Tdey/modoboa
def getattachment(request):
    """Fetch a message attachment

    FIXME: par manque de caching, le bodystructure du message est
    redemandé pour accéder aux headers de cette pièce jointe.

    :param request: a ``Request`` object
    """
    mbox = request.GET.get("mbox", None)
    mailid = request.GET.get("mailid", None)
    pnum = request.GET.get("partnumber", None)
    fname = request.GET.get("fname", None)
    if not mbox or not mailid or not pnum or not fname:
        raise WebmailError(_("Invalid request"))

    imapc = get_imapconnector(request)
    partdef, payload = imapc.fetchpart(mailid, mbox, pnum)
    resp = HttpResponse(decode_payload(partdef["encoding"], payload))
    resp["Content-Type"] = partdef["Content-Type"]
    resp["Content-Transfer-Encoding"] = partdef["encoding"]
    resp["Content-Disposition"] = build_header(fname)
    if int(partdef["size"]) < 200:
        resp["Content-Length"] = partdef["size"]
    return resp