Esempio n. 1
0
def newfolder(request, tplname="webmail/folder.html"):
    mbc = IMAPconnector(user=request.user.username,
                        password=request.session["password"])
    ctx = {"title": _("Create a new mailbox"),
           "formid": "mboxform",
           "action": reverse(newfolder),
           "action_label": _("Create"),
           "action_classes": "submit",
           "withunseen": False,
           "selectonly": True,
           "mboxes": mbc.getmboxes(request.user),
           "hdelimiter": mbc.hdelimiter}

    if request.method == "POST":
        form = FolderForm(request.POST)
        if form.is_valid():
            pf = request.POST.get("parent_folder", None)
            mbc.create_folder(form.cleaned_data["name"], pf)
            return ajax_simple_response(dict(
                    status="ok", respmsg=_("Mailbox created"), newmb=form.cleaned_data["name"], parent=pf
                    ))

        ctx["form"] = form
        ctx["selected"] = None
        return ajax_response(request, status="ko", template=tplname, **ctx)

    ctx["form"] = FolderForm()
    ctx["selected"] = None
    return _render(request, tplname, ctx)
Esempio n. 2
0
def newfolder(request, tplname="webmail/folder.html"):
    mbc = IMAPconnector(user=request.user.username,
                        password=request.session["password"])
    ctx = {
        "title": _("Create a new mailbox"),
        "formid": "mboxform",
        "action": reverse(newfolder),
        "action_label": _("Create"),
        "action_classes": "submit",
        "withunseen": False,
        "selectonly": True,
        "mboxes": mbc.getmboxes(request.user)
    }

    if request.method == "POST":
        form = FolderForm(request.POST)
        if form.is_valid():
            pf = request.POST.get("parent_folder", None)
            mbc.create_folder(form.cleaned_data["name"], pf)
            return ajax_simple_response(
                dict(status="ok",
                     respmsg=_("Mailbox created"),
                     newmb=form.cleaned_data["name"],
                     parent=pf))

        ctx["form"] = form
        ctx["selected"] = None
        return ajax_response(request, status="ko", template=tplname, **ctx)

    ctx["form"] = FolderForm()
    ctx["selected"] = None
    return _render(request, tplname, ctx)
Esempio n. 3
0
def editfolder(request, tplname="webmail/folder.html"):
    mbc = IMAPconnector(user=request.user.username,
                        password=request.session["password"])
    ctx = {
        "title": _("Edit mailbox"),
        "formid": "mboxform",
        "action": reverse(editfolder),
        "action_label": _("Update"),
        "action_classes": "submit",
        "withunseen": False,
        "selectonly": True
    }

    if request.method == "POST":
        form = FolderForm(request.POST)
        if form.is_valid():
            pf = request.POST.get("parent_folder", None)
            ctx["selected"] = pf
            oldname, oldparent = separate_mailbox(request.POST["oldname"])
            res = dict(status="ok", respmsg=_("Mailbox updated"))
            if form.cleaned_data["name"] != oldname \
                    or (pf != oldparent):
                newname = form.cleaned_data["name"] if pf is None \
                    else "%s.%s" % (pf, form.cleaned_data["name"])
                mbc.rename_folder(request.POST["oldname"], newname)
                res["oldmb"] = oldname
                res["newmb"] = form.cleaned_data["name"]
                res["oldparent"] = oldparent
                res["newparent"] = pf
                if "mbox" in request.session:
                    del request.session["mbox"]
            return ajax_simple_response(res)

        ctx["mboxes"] = mbc.getmboxes(request.user)
        ctx["form"] = form
        return ajax_response(request, status="ko", template=tplname, **ctx)

    name = request.GET.get("name", None)
    if name is None:
        raise WebmailError(_("Invalid request"))
    shortname, parent = separate_mailbox(name)
    ctx["mboxes"] = mbc.getmboxes(request.user, until_mailbox=parent)
    ctx["form"] = FolderForm()
    ctx["form"].fields["oldname"].initial = name
    ctx["form"].fields["name"].initial = shortname
    ctx["selected"] = parent
    return _render(request, tplname, ctx)
Esempio n. 4
0
def editfolder(request, tplname="webmail/folder.html"):
    mbc = IMAPconnector(user=request.user.username,
                        password=request.session["password"])
    ctx = {"title" : _("Edit mailbox"),
           "formid" : "mboxform",
           "action" : reverse(editfolder),
           "action_label" : _("Update"),
           "action_classes" : "submit",
           "withunseen" : False,
           "selectonly" : True,
           "hdelimiter": mbc.hdelimiter}

    if request.method == "POST":
        form = FolderForm(request.POST)
        if form.is_valid():
            pf = request.POST.get("parent_folder", None)
            ctx["selected"] = pf
            oldname, oldparent = separate_mailbox(request.POST["oldname"], sep=mbc.hdelimiter)
            res = dict(status="ok", respmsg=_("Mailbox updated"))
            if form.cleaned_data["name"] != oldname \
                    or (pf != oldparent):
                newname = form.cleaned_data["name"] if pf is None \
                    else "%s.%s" % (pf, form.cleaned_data["name"])
                mbc.rename_folder(request.POST["oldname"], newname)
                res["oldmb"] = oldname
                res["newmb"] = form.cleaned_data["name"]
                res["oldparent"] = oldparent
                res["newparent"] = pf
                if "mbox" in request.session:
                    del request.session["mbox"]
            return ajax_simple_response(res)

        ctx["mboxes"] = mbc.getmboxes(request.user)
        ctx["form"] = form
        return ajax_response(request, status="ko", template=tplname, **ctx)

    name = request.GET.get("name", None)
    if name is None:
        raise WebmailError(_("Invalid request"))
    shortname, parent = separate_mailbox(name, sep=mbc.hdelimiter)
    ctx["mboxes"] = mbc.getmboxes(request.user, until_mailbox=parent)
    ctx["form"] = FolderForm()
    ctx["form"].fields["oldname"].initial = name
    ctx["form"].fields["name"].initial = shortname
    ctx["selected"] = parent
    return _render(request, tplname, ctx)