summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/jwebmail/__init__.py7
-rw-r--r--src/jwebmail/read_mails.py21
-rw-r--r--src/jwebmail/webmail.py7
3 files changed, 24 insertions, 11 deletions
diff --git a/src/jwebmail/__init__.py b/src/jwebmail/__init__.py
index 25681d1..6ccca40 100644
--- a/src/jwebmail/__init__.py
+++ b/src/jwebmail/__init__.py
@@ -1,5 +1,4 @@
import os.path as os_path
-import pwd
import sys
from datetime import datetime
from os import environ
@@ -36,7 +35,7 @@ else:
toml_read_file = dict(load=toml_load, text=True)
-__version__ = "2.4.0.dev3"
+__version__ = "2.5.0.dev2"
csrf = CSRFProtect()
@@ -46,12 +45,8 @@ def validate_config(app):
assert "@" in conf["JWEBMAIL"]["ADMIN_MAIL"]
- assert os_path.isdir(conf["JWEBMAIL"]["READ_MAILS"]["MAILBOX"])
assert os_path.abspath(conf["JWEBMAIL"]["READ_MAILS"]["BACKEND"])
- assert pwd.getpwnam(
- conf["JWEBMAIL"]["READ_MAILS"].setdefault("MAILBOX_USER", environ["USER"])
- )
assert os_path.abspath(
conf["JWEBMAIL"]["READ_MAILS"].setdefault("AUTHENTICATOR", "qmail-authuser")
)
diff --git a/src/jwebmail/read_mails.py b/src/jwebmail/read_mails.py
index b7e5984..b173b35 100644
--- a/src/jwebmail/read_mails.py
+++ b/src/jwebmail/read_mails.py
@@ -1,4 +1,6 @@
+import pwd
from contextlib import closing
+from os.path import join as path_join
from flask import current_app, g
from flask_login import UserMixin, current_user
@@ -137,8 +139,23 @@ def select_timeout_session():
def build_qma(username, password):
authenticator = current_app.config["JWEBMAIL"]["READ_MAILS"]["AUTHENTICATOR"]
backend = current_app.config["JWEBMAIL"]["READ_MAILS"]["BACKEND"]
- mailbox = current_app.config["JWEBMAIL"]["READ_MAILS"]["MAILBOX"]
- mailbox_user = current_app.config["JWEBMAIL"]["READ_MAILS"]["MAILBOX_USER"]
+
+ 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(":")
+ if dom == domain:
+ mailbox_user = unix_user
+ mailbox = path_join(pwd.getpwnam(unix_user).pw_dir, "users/")
+ break
+ else:
+ raise ValueError(f"unknown virtual domain {domain!r}")
+ else:
+ 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
diff --git a/src/jwebmail/webmail.py b/src/jwebmail/webmail.py
index 8c839d3..cb4d5db 100644
--- a/src/jwebmail/webmail.py
+++ b/src/jwebmail/webmail.py
@@ -247,10 +247,11 @@ def sendmail():
flash(gettext("succ_send"))
return redirect(url_for("displayheaders"), 303)
+ _, send_server = current_user.id.split("@")
+ send_server = "mail." + send_server
+
try:
- with SMTP_SSL(
- current_app.config["JWEBMAIL"]["WRITE_MAILS"]["SMTPS_SERVER"]
- ) as smtp:
+ with SMTP_SSL(send_server) as smtp:
smtp.login(current_user.id, current_user.password)
smtp.send_message(mail)
except (