summaryrefslogtreecommitdiff
path: root/src/jwebmail/read_mails.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/jwebmail/read_mails.py')
-rw-r--r--src/jwebmail/read_mails.py22
1 files changed, 8 insertions, 14 deletions
diff --git a/src/jwebmail/read_mails.py b/src/jwebmail/read_mails.py
index 5aed8d2..8e1a23d 100644
--- a/src/jwebmail/read_mails.py
+++ b/src/jwebmail/read_mails.py
@@ -2,7 +2,7 @@ import pwd
from contextlib import closing
from os.path import join as path_join
-from flask import current_app, g
+from flask import current_app
from flask_login import UserMixin, current_user, login_user
from .model.read_mails import QMailAuthuser, QMAuthError
@@ -150,14 +150,12 @@ def _select_timeout_session():
raise ValueError(f"unknown session_type {session_type!r}")
-def _build_qma(username, password):
+def _build_qma(domain):
authenticator = current_app.config["JWEBMAIL"]["READ_MAILS"]["AUTHENTICATOR"]
backend = current_app.config["JWEBMAIL"]["READ_MAILS"]["BACKEND"]
virt_users = current_app.config["JWEBMAIL"]["READ_MAILS"].get("VIRTUAL_USERS")
if virt_users:
- _, domain = username.split("@")
-
with open(virt_users, encoding="ASCII") as file:
for virt_dom in file:
dom, unix_user = virt_dom.rstrip().split(":")
@@ -171,14 +169,13 @@ def _build_qma(username, password):
mailbox_user = current_app.config["JWEBMAIL"]["READ_MAILS"]["MAILBOX_USER"]
mailbox = current_app.config["JWEBMAIL"]["READ_MAILS"]["MAILBOX"]
- return QMailAuthuser(
- username, password, backend, mailbox, mailbox_user, authenticator
- )
+ return QMailAuthuser(backend, mailbox, mailbox_user, authenticator)
def login(username, password):
try:
- _build_qma(username, password).open()
+ _, domain = username.split("@")
+ _build_qma(domain).open(username, password)
except QMAuthError as err:
if err.rc == 1:
return False
@@ -203,9 +200,6 @@ def load_user(username: str) -> JWebmailUser:
def get_read_mails_logged_in():
- if "read_mails" in g:
- return g.read_mails
-
- qma = _build_qma(current_user.get_id(), current_user.password).open()
- g.read_mails = qma
- return qma
+ username = current_user.get_id()
+ _, domain = username.split("@")
+ return _build_qma(domain).open(username, current_user.password)