aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRunxi Yu <me@runxiyu.org>2024-05-01 13:52:38 +0800
committerRunxi Yu <me@runxiyu.org>2024-05-01 13:52:58 +0800
commitba95db4c379f6803412a069be5f866b9437de348 (patch)
tree29c51b8a3d3c8ac8666695be4e4f675960963b0e
parentType check and cleanup (diff)
downloadqbox-master.tar.gz
qbox-master.zip
Use MAIL_PREFIXHEADmaster
-rwxr-xr-xapp.py31
-rw-r--r--config.def.py1
2 files changed, 25 insertions, 7 deletions
diff --git a/app.py b/app.py
index 4266858..289ff16 100755
--- a/app.py
+++ b/app.py
@@ -146,7 +146,7 @@ def qboard(user: str) -> Union[Response, werkzeugResponse, str, tuple[str, int]]
# EMAIL STUFF IS TO BE ADDED HERE
# Why not in a separate email_stuff() function?
# Because lazy
- mbox = mailbox.Maildir("/home/qbox/Mail/Inbox")
+ mbox = mailbox.Maildir(config.MAILDIR_LOCATION)
for msg_id, msg in mbox.items():
if msg.get_subdir() != "new":
continue
@@ -178,7 +178,11 @@ def qboard(user: str) -> Union[Response, werkzeugResponse, str, tuple[str, int]]
newmsg["In-Reply-To"] = msg["Message-ID"]
elif "Message-Id" in msg.keys():
newmsg["In-Reply-To"] = msg["Message-Id"]
- newmsg["Message-Id"] = "<qbox-system-%s@%s>" % (ts, config.MAIL_HOST)
+ newmsg["Message-Id"] = "<%s-system-%s@%s>" % (
+ config.MAIL_PREFIX,
+ ts,
+ config.MAIL_HOST,
+ )
p = Popen(["/usr/sbin/sendmail", "-t", "-oi"], stdin=PIPE)
p.communicate(newmsg.as_bytes())
continue
@@ -191,7 +195,7 @@ def qboard(user: str) -> Union[Response, werkzeugResponse, str, tuple[str, int]]
reply_identifier = parsed_address[1] # Should be ts
for question in reversed(db):
assert type(question["ts"]) is str
- if reply_identifier == "qbox-" + question["ts"]:
+ if reply_identifier == config.MAIL_PREFIX + "-" + question["ts"]:
break
else:
ts = str(time.time())
@@ -208,7 +212,11 @@ def qboard(user: str) -> Union[Response, werkzeugResponse, str, tuple[str, int]]
newmsg["In-Reply-To"] = msg["Message-ID"]
elif "Message-Id" in msg.keys():
newmsg["In-Reply-To"] = msg["Message-Id"]
- newmsg["Message-Id"] = "<qbox-system-%s@%s>" % (ts, config.MAIL_HOST)
+ newmsg["Message-Id"] = "<%s-system-%s@%s>" % (
+ config.MAIL_PREFIX,
+ ts,
+ config.MAIL_HOST,
+ )
p = Popen(["/usr/sbin/sendmail", "-t", "-oi"], stdin=PIPE)
p.communicate(newmsg.as_bytes())
continue
@@ -235,7 +243,8 @@ def qboard(user: str) -> Union[Response, werkzeugResponse, str, tuple[str, int]]
newmsg["In-Reply-To"] = msg["Message-ID"]
elif "Message-Id" in msg.keys():
newmsg["In-Reply-To"] = msg["Message-Id"]
- newmsg["Message-Id"] = "<qbox-system-%s@%s>" % (
+ newmsg["Message-Id"] = "<%s-system-%s@%s>" % (
+ config.MAIL_PREFIX,
ts,
config.MAIL_HOST,
)
@@ -270,7 +279,11 @@ def qboard(user: str) -> Union[Response, werkzeugResponse, str, tuple[str, int]]
newmsg["In-Reply-To"] = msg["Message-ID"]
elif "Message-Id" in msg.keys():
newmsg["In-Reply-To"] = msg["Message-Id"]
- newmsg["Message-Id"] = "<qbox-system-%s@%s>" % (ts, config.MAIL_HOST)
+ newmsg["Message-Id"] = "<%s-system-%s@%s>" % (
+ config.MAIL_PREFIX,
+ ts,
+ config.MAIL_HOST,
+ )
p = Popen(["/usr/sbin/sendmail", "-t", "-oi"], stdin=PIPE)
p.communicate(newmsg.as_bytes())
return render_template(
@@ -294,7 +307,11 @@ def qboard(user: str) -> Union[Response, werkzeugResponse, str, tuple[str, int]]
newmsg["From"] = config.MAIL_PREFIX + "@" + config.MAIL_HOST
newmsg["To"] = config.MAPPING[user][0]
newmsg["Subject"] = "Question Box Message"
- newmsg["Message-Id"] = "<qbox-%s@%s>" % (ts, config.MAIL_HOST)
+ newmsg["Message-Id"] = "<%s-%s@%s>" % (
+ config.MAIL_PREFIX,
+ ts,
+ config.MAIL_HOST,
+ )
p = Popen(["/usr/sbin/sendmail", "-t", "-oi"], stdin=PIPE)
p.communicate(newmsg.as_bytes())
else:
diff --git a/config.def.py b/config.def.py
index 4d3fb2a..f38af45 100644
--- a/config.def.py
+++ b/config.def.py
@@ -12,3 +12,4 @@ MAPPING = {
PORT = 5728
MAIL_HOST = "andrewyu.org"
MAIL_PREFIX = "qbox"
+MAILDIR_LOCATION = "/srv/qbox/mail/Inbox"