<commit_before># coding: utf-8
import os
from rfc6266 import build_header, parse_headers
from django.conf import settings
from django.http import HttpResponse
from django.template import Template, Context
from django.utils.translation import ugettext as _, ungettext
from django.core.urlresolvers import reverse
from django.contrib.auth.decorators import login_required
from django.views.decorators.csrf import csrf_exempt
from django.views.decorators.gzip import gzip_page
from modoboa.lib import parameters
from modoboa.lib.webutils import _render, _render_to_string, \
    ajax_response, ajax_simple_response
from modoboa.lib.decorators import needs_mailbox
from exceptions import WebmailError
from forms import FolderForm, AttachmentForm, ComposeMailForm
from imaputils import get_imapconnector, IMAPconnector, separate_mailbox
from lib import decode_payload, AttachmentUploadHandler, \
    save_attachment, ImapListing, EmailSignature, \
    clean_attachments, set_compose_session, send_mail, \
    ImapEmail, ReplyModifier, ForwardModifier
from templatetags import webextras


@login_required
@needs_mailbox()
@gzip_page
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.

    :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:
            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]
        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:
        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


@login_required
@needs_mailbox()
def move(request):
    for arg in ["msgset", "to"]:
        if not arg in request.GET:
            raise WebmailError(_("Invalid request"))
    mbc = get_imapconnector(request)
    mbc.move(request.GET["msgset"], request.session["mbox"], request.GET["to"])
    resp = listmailbox(request, request.session["mbox"], update_session=False)
    resp.update(status="ok")<commit_msg>The fix may be easier than expected :p<commit_after># coding: utf-8
import os
from rfc6266 import build_header
from django.conf import settings
from django.http import HttpResponse
from django.template import Template, Context
from django.utils.translation import ugettext as _, ungettext
from django.core.urlresolvers import reverse
from django.contrib.auth.decorators import login_required
from django.views.decorators.csrf import csrf_exempt
from django.views.decorators.gzip import gzip_page
from modoboa.lib import parameters
from modoboa.lib.webutils import _render, _render_to_string, \
    ajax_response, ajax_simple_response
from modoboa.lib.decorators import needs_mailbox
from exceptions import WebmailError
from forms import FolderForm, AttachmentForm, ComposeMailForm
from imaputils import get_imapconnector, IMAPconnector, separate_mailbox
from lib import decode_payload, AttachmentUploadHandler, \
    save_attachment, ImapListing, EmailSignature, \
    clean_attachments, set_compose_session, send_mail, \
    ImapEmail, ReplyModifier, ForwardModifier
from templatetags import webextras


@login_required
@needs_mailbox()
@gzip_page
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


@login_required
@needs_mailbox()
def move(request):
    for arg in ["msgset", "to"]:
        if not arg in request.GET:
            raise WebmailError(_("Invalid request"))
    mbc = get_imapconnector(request)
    mbc.move(request.GET["msgset"], request.session["mbox"], request.GET["to"])
    resp = listmailbox(request, request.session["mbox"], update_session=False)
    resp.update(status="ok")
{'fraction_non_alphanumeric': 0.10230263157894737, 'fraction_numerical': 0.007894736842105263, 'mean_word_length': 4.170918367346939, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5090228', 'n_tokens_mistral': 1848, 'n_tokens_neox': 1802, 'n_words': 523}