def _listing(request): if not request.user.is_superuser and request.user.group != 'SimpleUsers': if not Domain.objects.get_for_admin(request.user).count(): return empty_quarantine(request) navparams = QuarantineNavigationParameters(request) navparams.store() lst = SQLlisting( request.user, navparams=navparams, elems_per_page=int( parameters.get_user(request.user, "MESSAGES_PER_PAGE") ) ) page = lst.paginator.getpage(navparams.get('page')) if not page: return empty_quarantine(request) content = lst.fetch(request, page.id_start, page.id_stop) ctx = getctx( "ok", listing=content, paginbar=pagination_bar(page), page=page.number ) if request.session.get('location', 'listing') != 'listing': ctx['menu'] = quar_menu() request.session['location'] = 'listing' return render_to_json_response(ctx)
def _listing(request): flt = None rcptfilter = None msgs = None if not request.user.is_superuser and request.user.group != 'SimpleUsers': if not Domain.objects.get_for_admin(request.user).count(): return empty_quarantine(request) order = request.GET.get("order", "-date") if not "navparams" in request.session: request.session["navparams"] = {} request.session["navparams"]["order"] = order parse_search_parameters(request) if "pattern" in request.session: criteria = request.session["criteria"] if criteria == "both": criteria = "from_addr,subject,to" for c in criteria.split(","): if c == "from_addr": nfilter = Q(mail__from_addr__contains=request.session["pattern"]) elif c == "subject": nfilter = Q(mail__subject__contains=request.session["pattern"]) elif c == "to": rcptfilter = request.session["pattern"] continue else: raise Exception("unsupported search criteria %s" % c) flt = nfilter if flt is None else flt | nfilter msgs = get_wrapper().get_mails(request, rcptfilter) if "page" in request.GET: request.session["page"] = request.GET["page"] pageid = int(request.session["page"]) else: if "page" in request.session: del request.session["page"] pageid = 1 lst = SQLlisting( request.user, msgs, flt, navparams=request.session["navparams"], elems_per_page=int(parameters.get_user(request.user, "MESSAGES_PER_PAGE")) ) page = lst.paginator.getpage(pageid) if not page: return empty_quarantine(request) content = lst.fetch(request, page.id_start, page.id_stop) navbar = lst.render_navbar(page, "listing/?") ctx = getctx("ok", listing=content, navbar=navbar, menu=quar_menu(request.user)) return HttpResponse(simplejson.dumps(ctx), mimetype="application/json")
def _listing(request): flt = None rcptfilter = None msgs = None if not request.user.is_superuser and request.user.group != 'SimpleUsers': if not Domain.objects.get_for_admin(request.user).count(): return empty_quarantine(request) navparams = QuarantineNavigationParameters(request) navparams.store() pattern = navparams.get('pattern', '') if pattern: criteria = navparams.get('criteria') if criteria == "both": criteria = "from_addr,subject,to" for c in criteria.split(","): if c == "from_addr": nfilter = Q(mail__from_addr__contains=pattern) elif c == "subject": nfilter = Q(mail__subject__contains=pattern) elif c == "to": rcptfilter = pattern continue else: raise BadRequest("unsupported search criteria %s" % c) flt = nfilter if flt is None else flt | nfilter msgtype = navparams.get('msgtype', None) if msgtype is not None: nfilter = Q(mail__msgrcpt__content=msgtype) flt = flt | nfilter if flt is not None else nfilter msgs = get_wrapper().get_mails(request, rcptfilter) page = navparams.get('page') lst = SQLlisting(request.user, msgs, flt, navparams=request.session["quarantine_navparams"], elems_per_page=int( parameters.get_user(request.user, "MESSAGES_PER_PAGE"))) page = lst.paginator.getpage(page) if not page: return empty_quarantine(request) content = lst.fetch(request, page.id_start, page.id_stop) ctx = getctx("ok", listing=content, paginbar=pagination_bar(page), page=page.number) if request.session.get('location', 'listing') != 'listing': ctx['menu'] = quar_menu() request.session['location'] = 'listing' return render_to_json_response(ctx)
def _listing(request): flt = None rcptfilter = None msgs = None if not request.user.is_superuser and request.user.group != 'SimpleUsers': if not Domain.objects.get_for_admin(request.user).count(): return empty_quarantine(request) navparams = QuarantineNavigationParameters(request) navparams.store() pattern = navparams.get('pattern', '') if pattern: criteria = navparams.get('criteria') if criteria == "both": criteria = "from_addr,subject,to" for c in criteria.split(","): if c == "from_addr": nfilter = Q(mail__from_addr__contains=pattern) elif c == "subject": nfilter = Q(mail__subject__contains=pattern) elif c == "to": rcptfilter = pattern continue else: raise BadRequest("unsupported search criteria %s" % c) flt = nfilter if flt is None else flt | nfilter msgtype = navparams.get('msgtype', None) if msgtype is not None: nfilter = Q(mail__msgrcpt__content=msgtype) flt = flt | nfilter if flt is not None else nfilter msgs = get_wrapper().get_mails(request, rcptfilter) page = navparams.get('page') lst = SQLlisting( request.user, msgs, flt, navparams=request.session["quarantine_navparams"], elems_per_page=int(parameters.get_user(request.user, "MESSAGES_PER_PAGE")) ) page = lst.paginator.getpage(page) if not page: return empty_quarantine(request) content = lst.fetch(request, page.id_start, page.id_stop) ctx = getctx( "ok", listing=content, paginbar=pagination_bar(page), page=page.number ) if request.session.get('location', 'listing') != 'listing': ctx['menu'] = quar_menu() request.session['location'] = 'listing' return render_to_json_response(ctx)
def viewmail(request, mail_id): rcpt = request.GET["rcpt"] if request.user.mailbox_set.count(): mb = Mailbox.objects.get(user=request.user) if rcpt in mb.alias_addresses: get_wrapper().set_msgrcpt_status(rcpt, mail_id, 'V') content = Template(""" <iframe src="{{ url }}" id="mailcontent"></iframe> """).render(Context({"url": reverse(getmailcontent, args=[mail_id])})) menu = viewm_menu(mail_id, rcpt) ctx = getctx("ok", menu=menu, listing=content) request.session['location'] = 'viewmail' return render_to_json_response(ctx)
def viewmail(request, mail_id): if request.user.group != 'SimpleUsers': rcpt = request.GET["rcpt"] else: rcpt = None if request.user.mailbox_set.count(): mb = Mailbox.objects.get(user=request.user) if not rcpt or rcpt == mb.full_address: msgrcpt = get_wrapper().get_recipient_message(mb.full_address, mail_id) msgrcpt.rs = 'V' msgrcpt.save() content = Template(""" <iframe src="{{ url }}" id="mailcontent"></iframe> """).render(Context({"url": reverse(getmailcontent, args=[mail_id])})) menu = viewm_menu(request.user, mail_id, rcpt) ctx = getctx("ok", menu=menu, listing=content) return HttpResponse(simplejson.dumps(ctx), mimetype="application/json")
def viewmail(request, mail_id): if request.user.group != 'SimpleUsers': rcpt = request.GET["rcpt"] else: rcpt = None if request.user.mailbox_set.count(): mb = Mailbox.objects.get(user=request.user) if not rcpt or rcpt == mb.full_address: msgrcpt = get_wrapper().get_recipient_message( mb.full_address, mail_id) msgrcpt.rs = 'V' msgrcpt.save() content = Template(""" <iframe src="{{ url }}" id="mailcontent"></iframe> """).render(Context({"url": reverse(getmailcontent, args=[mail_id])})) menu = viewm_menu(request.user, mail_id, rcpt) ctx = getctx("ok", menu=menu, listing=content) return HttpResponse(simplejson.dumps(ctx), mimetype="application/json")
def empty_quarantine(request): content = "<div class='alert alert-info'>%s</div>" % _("Empty quarantine") ctx = getctx("ok", level=2, listing=content, navbar="", menu=quar_menu(request.user)) return HttpResponse(simplejson.dumps(ctx), mimetype="application/json")
def empty_quarantine(request): content = "<div class='alert alert-info'>%s</div>" % _("Empty quarantine") ctx = getctx("ok", level=2, listing=content) return render_to_json_response(ctx)