|
@@ -31,7 +31,7 @@ It should contain the following info:
|
|
|
|
|
|
"""
|
|
|
import time
|
|
|
-from email.message import EmailMessage
|
|
|
+from email.message import Message
|
|
|
from email.parser import Parser
|
|
|
from email.policy import SMTPUTF8
|
|
|
from smtplib import SMTP
|
|
@@ -85,11 +85,11 @@ class MailHandler:
|
|
|
smtp = SMTP(POSTFIX_SERVER, 25)
|
|
|
msg = Parser(policy=SMTPUTF8).parsestr(message_data)
|
|
|
|
|
|
+ rcpt_to = envelope.rcpt_tos[0].lower()
|
|
|
+
|
|
|
# Reply case
|
|
|
# reply+ or ra+ (reverse-alias) prefix
|
|
|
- if envelope.rcpt_tos[0].startswith("reply+") or envelope.rcpt_tos[0].startswith(
|
|
|
- "ra+"
|
|
|
- ):
|
|
|
+ if rcpt_to.startswith("reply+") or rcpt_to.startswith("ra+"):
|
|
|
LOG.debug("Reply phase")
|
|
|
app = new_app()
|
|
|
|
|
@@ -102,9 +102,9 @@ class MailHandler:
|
|
|
with app.app_context():
|
|
|
return self.handle_forward(envelope, smtp, msg)
|
|
|
|
|
|
- def handle_forward(self, envelope, smtp: SMTP, msg: EmailMessage) -> str:
|
|
|
+ def handle_forward(self, envelope, smtp: SMTP, msg: Message) -> str:
|
|
|
"""return *status_code message*"""
|
|
|
- alias = envelope.rcpt_tos[0] # alias@SL
|
|
|
+ alias = envelope.rcpt_tos[0].lower() # alias@SL
|
|
|
|
|
|
gen_email = GenEmail.get_by(email=alias)
|
|
|
if not gen_email:
|
|
@@ -212,8 +212,8 @@ class MailHandler:
|
|
|
db.session.commit()
|
|
|
return "250 Message accepted for delivery"
|
|
|
|
|
|
- def handle_reply(self, envelope, smtp: SMTP, msg: EmailMessage) -> str:
|
|
|
- reply_email = envelope.rcpt_tos[0]
|
|
|
+ def handle_reply(self, envelope, smtp: SMTP, msg: Message) -> str:
|
|
|
+ reply_email = envelope.rcpt_tos[0].lower()
|
|
|
|
|
|
# reply_email must end with EMAIL_DOMAIN
|
|
|
if not reply_email.endswith(EMAIL_DOMAIN):
|
|
@@ -230,7 +230,7 @@ class MailHandler:
|
|
|
return "550 alias unknown by SimpleLogin"
|
|
|
|
|
|
user_email = forward_email.gen_email.user.email
|
|
|
- if envelope.mail_from != user_email:
|
|
|
+ if envelope.mail_from.lower() != user_email.lower():
|
|
|
LOG.error(
|
|
|
f"Reply email can only be used by user email. Actual mail_from: %s. User email %s",
|
|
|
envelope.mail_from,
|
|
@@ -293,7 +293,7 @@ class MailHandler:
|
|
|
return "250 Message accepted for delivery"
|
|
|
|
|
|
|
|
|
-def add_or_replace_header(msg: EmailMessage, header: str, value: str):
|
|
|
+def add_or_replace_header(msg: Message, header: str, value: str):
|
|
|
try:
|
|
|
msg.add_header(header, value)
|
|
|
except ValueError:
|