Beispiel #1
0
def forward(request, tplname='admin/forward.html'):
    try:
        mb = request.user.mailbox_set.all()[0]
    except IndexError:
        raise ModoboaException(
            _("You need a mailbox in order to define a forward"))
    try:
        al = Alias.objects.get(address=mb.address, domain__name=mb.domain.name)
    except Alias.DoesNotExist:
        al = None
    if request.method == "POST":
        form = ForwardForm(request.POST)
        error = None
        if form.is_valid():
            try:
                if al is None:
                    al = Alias()
                    al.address = mb.address
                    al.domain = mb.domain
                    al.enabled = mb.user.is_active
                intdests = []
                if form.cleaned_data["keepcopies"]:
                    intdests += [mb]
                form.parse_dest()
                al.save(int_rcpts=intdests, ext_rcpts=form.dests)
                if request.user.group != "SimpleUsers":
                    al.post_create(request.user)
                return ajax_response(request, respmsg=_("Forward updated"))
            except BadDestination, e:
                error = str(e)

        return ajax_simple_response(
            dict(status="ko", errors=form.errors, respmsg=error))
Beispiel #2
0
def forward(request, tplname='admin/forward.html'):
    mb = request.user.mailbox_set.all()[0]
    try:
        al = Alias.objects.get(address=mb.address,
                               domain__name=mb.domain.name)
    except Alias.DoesNotExist:
        al = None
    if request.method == "POST":
        form = ForwardForm(request.POST)
        error = None
        if form.is_valid():
            if al is None:
                al = Alias()
                al.address = mb.address
                al.domain = mb.domain
                al.enabled = mb.user.is_active
            intdests = []
            if form.cleaned_data["keepcopies"]:
                intdests += [mb]
            form.parse_dest()
            al.save(
                int_rcpts=intdests, ext_rcpts=form.dests, creator=request.user
            )
            return render_to_json_response(_("Forward updated"))

        return render_to_json_response(
            {'form_errors': form.errors}, status=400
        )

    form = ForwardForm()
    if al is not None:
        form.fields["dest"].initial = al.extmboxes
        try:
            al.mboxes.get(pk=mb.id)
        except Mailbox.DoesNotExist:
            pass
        else:
            form.fields["keepcopies"].initial = True
    return render_to_json_response({
        "content": _render_to_string(request, tplname, {
            "form": form
        })
    })
Beispiel #3
0
def forward(request, tplname='admin/forward.html'):
    mb = request.user.mailbox_set.all()[0]
    try:
        al = Alias.objects.get(address=mb.address, domain__name=mb.domain.name)
    except Alias.DoesNotExist:
        al = None
    if request.method == "POST":
        form = ForwardForm(request.POST)
        error = None
        if form.is_valid():
            if al is None:
                al = Alias()
                al.address = mb.address
                al.domain = mb.domain
                al.enabled = mb.user.is_active
            intdests = []
            if form.cleaned_data["keepcopies"]:
                intdests += [mb]
            form.parse_dest()
            al.save(int_rcpts=intdests,
                    ext_rcpts=form.dests,
                    creator=request.user)
            return render_to_json_response(_("Forward updated"))

        return render_to_json_response({'form_errors': form.errors},
                                       status=400)

    form = ForwardForm()
    if al is not None:
        form.fields["dest"].initial = al.extmboxes
        try:
            al.mboxes.get(pk=mb.id)
        except Mailbox.DoesNotExist:
            pass
        else:
            form.fields["keepcopies"].initial = True
    return render_to_json_response(
        {"content": _render_to_string(request, tplname, {"form": form})})
Beispiel #4
0
def forward(request, tplname='admin/forward.html'):
    try:
        mb = request.user.mailbox_set.all()[0]
    except IndexError:
        raise ModoboaException(
            _("You need a mailbox in order to define a forward")
        )
    try:
        al = Alias.objects.get(address=mb.address,
                               domain__name=mb.domain.name)
    except Alias.DoesNotExist:
        al = None
    if request.method == "POST":
        form = ForwardForm(request.POST)
        error = None
        if form.is_valid():
            try:
                if al is None:
                    al = Alias()
                    al.address = mb.address
                    al.domain = mb.domain
                    al.enabled = mb.user.is_active
                intdests = []
                if form.cleaned_data["keepcopies"]:
                    intdests += [mb]
                form.parse_dest()
                al.save(int_rcpts=intdests, ext_rcpts=form.dests)
                if request.user.group != "SimpleUsers":
                    al.post_create(request.user)
                return ajax_response(request, respmsg=_("Forward updated"))
            except BadDestination, e:
                error = str(e)

        return ajax_simple_response(dict(
            status="ko",
            errors=form.errors,
            respmsg=error
        ))