本文整理汇总了Python中modoboa.lib.parameters.get_user函数的典型用法代码示例。如果您正苦于以下问题:Python get_user函数的具体用法?Python get_user怎么用?Python get_user使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_user函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, mbox, mailid, request, dformat="DISPLAYMODE", addrfull=False, links=0):
mformat = parameters.get_user(request.user, "DISPLAYMODE")
self.dformat = parameters.get_user(request.user, dformat)
self.headers = []
self.attachments = {}
self.imapc = get_imapconnector(request)
msg = self.imapc.fetchmail(mbox, mailid, readonly=False, headers=self.headers_as_list)
self.mbox = mbox
self.mailid = mailid
headers = msg["BODY[HEADER.FIELDS (%s)]" % self.headers_as_text]
fallback_fmt = "html" if self.dformat == "plain" else "plain"
self.bs = BodyStructure(msg["BODYSTRUCTURE"])
data = None
mformat = self.dformat if self.bs.contents.has_key(self.dformat) else fallback_fmt
if len(self.bs.contents):
bodyc = u""
for part in self.bs.contents[mformat]:
pnum = part["pnum"]
data = self.imapc._cmd("FETCH", mailid, "(BODY.PEEK[%s])" % pnum)
content = decode_payload(part["encoding"], data[int(mailid)]["BODY[%s]" % pnum])
charset = self._find_content_charset(part)
if charset is not None:
try:
content = content.decode(charset)
except (UnicodeDecodeError, LookupError):
result = chardet.detect(content)
content = content.decode(result["encoding"])
bodyc += content
self._fetch_inlines()
self.body = getattr(self, "viewmail_%s" % mformat)(bodyc, links=links)
else:
self.body = None
self._find_attachments()
msg = email.message_from_string(headers)
for hdr in self.headernames:
label = hdr[0]
name = hdr[0]
if not name in msg.keys():
name = name.upper()
if not name in msg.keys():
continue
try:
key = re.sub("-", "_", name).lower()
value = getattr(IMAPheader, "parse_%s" % key)(msg[name], full=addrfull)
except AttributeError:
value = msg[name]
if hdr[1]:
self.headers += [{"name": label, "value": value}]
try:
label = re.sub("-", "_", label)
setattr(self, label, value)
except:
pass
示例2: send_mail
def send_mail(request, form, posturl=None):
"""Email verification and sending.
If the form does not present any error, a new MIME message is
constructed. Then, a connection is established with the defined
SMTP server and the message is finally sent.
:param request: a Request object
:param posturl: the url to post the message form to
:return: a 2-uple (True|False, HttpResponse)
"""
if not form.is_valid():
editormode = parameters.get_user(request.user, "EDITOR")
listing = _render_to_string(
request, "webmail/compose.html",
{"form": form, "noerrors": True,
"body": form.cleaned_data.get("body", "").strip(),
"posturl": posturl}
)
return False, dict(status="ko", listing=listing, editor=editormode)
msg = form.to_msg(request)
rcpts = prepare_addresses(form.cleaned_data["to"], "envelope")
for hdr in ["cc", "cci"]:
if form.cleaned_data[hdr]:
msg[hdr.capitalize()] = prepare_addresses(form.cleaned_data[hdr])
rcpts += prepare_addresses(form.cleaned_data[hdr], "envelope")
try:
secmode = parameters.get_admin("SMTP_SECURED_MODE")
if secmode == "ssl":
s = smtplib.SMTP_SSL(parameters.get_admin("SMTP_SERVER"),
int(parameters.get_admin("SMTP_PORT")))
else:
s = smtplib.SMTP(parameters.get_admin("SMTP_SERVER"),
int(parameters.get_admin("SMTP_PORT")))
if secmode == "starttls":
s.starttls()
except Exception as text:
raise WebmailInternalError(str(text))
if parameters.get_admin("SMTP_AUTHENTICATION") == "yes":
try:
s.login(request.user.username, get_password(request))
except smtplib.SMTPException as err:
raise WebmailInternalError(str(err))
try:
s.sendmail(request.user.email, rcpts, msg.as_string())
s.quit()
except smtplib.SMTPException as err:
raise WebmailInternalError(str(err))
sentfolder = parameters.get_user(request.user, "SENT_FOLDER")
get_imapconnector(request).push_mail(sentfolder, msg)
clean_attachments(request.session["compose_mail"]["attachments"])
del request.session["compose_mail"]
return True, {}
示例3: getfs
def getfs(request, name):
sc = SieveClient(user=request.user.username,
password=request.session["password"])
editormode = parameters.get_user(request.user, "EDITOR_MODE")
error = None
try:
content = sc.getscript(name, format=editormode)
except SieveClientError as e:
error = str(e)
else:
if content is None:
error = _("Failed to retrieve filters set")
if error is not None:
return ajax_response(request, "ko", respmsg=error)
if editormode == "raw":
htmlcontent = render_to_string("modoboa_sievefilters/rawfilter.html", dict(
name=name, scriptcontent=content
))
else:
htmlcontent = render_to_string("modoboa_sievefilters/guieditor.html", dict(
fs=content
))
menu = '<ul id="fsetmenu" class="nav nav-sidebar"><li class="nav-header">%s</li>%s</ul>' % \
(_("Actions"), fset_menu(editormode, name))
resp = dict(menu=menu, content=htmlcontent)
return render_to_json_response(resp)
示例4: _listing
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)
示例5: empty
def empty(request, name):
if name != parameters.get_user(request.user, "TRASH_FOLDER"):
raise WebmailError(_("Invalid request"))
get_imapconnector(request).empty(name)
content = "<div class='alert alert-info'>%s</div>" % _("Empty mailbox")
return ajax_simple_response(dict(
status="ok", listing=content, mailbox=name
))
示例6: extra_js
def extra_js(user):
return [
"""function autoreply_cb() {
$('#id_untildate').datepicker({format: 'yyyy-mm-dd', language: '%s'});
}
"""
% parameters.get_user(user, "LANG", app="core")
]
示例7: getmboxes
def getmboxes(
self, user, topmailbox='', until_mailbox=None,
unseen_messages=True):
"""Returns a list of mailboxes for a particular user
By default, only the first level of mailboxes under
``topmailbox`` is returned. If ``until_mailbox`` is specified,
all levels needed to access this mailbox will be returned.
:param user: a ``User`` instance
:param topmailbox: the mailbox where to start in the tree
:param until_mailbox: the deepest needed mailbox
:param unseen_messages: include unseen messages counters or not
:return: a list
"""
if topmailbox:
md_mailboxes = []
else:
md_mailboxes = [
{"name": "INBOX", "class": "fa fa-inbox"},
{"name": parameters.get_user(user, "DRAFTS_FOLDER"),
"class": "fa fa-file"},
{"name": 'Junk', "class": "fa fa-fire"},
{"name": parameters.get_user(user, "SENT_FOLDER"),
"class": "fa fa-envelope"},
{"name": parameters.get_user(user, "TRASH_FOLDER"),
"class": "fa fa-trash"}
]
if until_mailbox:
name, parent = separate_mailbox(until_mailbox, self.hdelimiter)
if parent:
until_mailbox = parent
self._listmboxes(topmailbox, md_mailboxes, until_mailbox)
if unseen_messages:
for mb in md_mailboxes:
if "send_status" not in mb:
continue
del mb["send_status"]
key = "path" if "path" in mb else "name"
if not mb.get("removed", False):
count = self.unseen_messages(mb[key])
if count == 0:
continue
mb["unseen"] = count
return md_mailboxes
示例8: empty
def empty(request, name):
if name != parameters.get_user(request.user, "TRASH_FOLDER"):
raise BadRequest(_("Invalid request"))
get_imapconnector(request).empty(name)
content = "<div class='alert alert-info'>%s</div>" % _("Empty mailbox")
return render_to_json_response({
'listing': content, 'mailbox': name
})
示例9: getfs
def getfs(request, name):
sc = SieveClient(user=request.user.username, password=request.session["password"])
editormode = parameters.get_user(request.user, "EDITOR_MODE")
error = None
try:
content = sc.getscript(name, format=editormode)
except SieveClientError, e:
error = str(e)
示例10: extra_js
def extra_js(user):
return ["""function autoreply_cb() {
$('.datefield').datetimepicker({
format: 'YYYY-MM-DD hh:mm:ss',
language: '%(lang)s'
});
}
""" % {'lang': parameters.get_user(user, "LANG", app="core")}
]
示例11: delete
def delete(request):
mbox = request.GET.get("mbox", None)
mailid = request.GET.get("mailid", None)
if mbox is None or mailid is None:
raise WebmailError(_("Invalid request"))
mbc = get_imapconnector(request)
mbc.move(mailid, mbox, parameters.get_user(request.user, "TRASH_FOLDER"))
resp = dict(status="ok")
return ajax_simple_response(resp)
示例12: empty
def empty(request):
"""Empty the trash folder."""
name = request.GET.get("name", None)
if name != parameters.get_user(request.user, "TRASH_FOLDER"):
raise BadRequest(_("Invalid request"))
get_imapconnector(request).empty(name)
content = "<div class='alert alert-info'>%s</div>" % _("Empty mailbox")
return render_to_json_response({
'listing': content, 'mailbox': name, 'pages': [1]
})
示例13: _listing
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")
示例14: delete
def delete(request):
mbox = request.GET.get("mbox", None)
selection = request.GET.getlist("selection[]", None)
if mbox is None or selection is None:
raise BadRequest(_("Invalid request"))
selection = [item for item in selection if item.isdigit()]
mbc = get_imapconnector(request)
mbc.move(",".join(selection), mbox, parameters.get_user(request.user, "TRASH_FOLDER"))
count = len(selection)
message = ungettext("%(count)d message deleted", "%(count)d messages deleted", count) % {"count": count}
return render_to_json_response(message)
示例15: msg
def msg(self):
"""
"""
if self._msg is None:
self._msg = self.imapc.fetchmail(self.mbox, self.mailid, readonly=False, headers=self.headers_as_list)
self.bs = BodyStructure(self._msg["BODYSTRUCTURE"])
self._find_attachments()
if not self.dformat in ["plain", "html"]:
self.dformat = parameters.get_user(self.request.user, self.dformat)
fallback_fmt = "html" if self.dformat == "plain" else "plain"
self.mformat = self.dformat if self.dformat in self.bs.contents else fallback_fmt
return self._msg