Fix: do not use spam check on disabled alias

This commit is contained in:
Son NK 2020-04-27 18:18:40 +02:00
parent ed16e9b478
commit ba081a597a
1 changed files with 64 additions and 67 deletions

View File

@ -328,6 +328,14 @@ def handle_forward(envelope, smtp: SMTP, msg: Message, rcpt_to: str) -> (bool, s
return False, _SELF_FORWARDING_STATUS
contact = get_or_create_contact(msg["From"], alias)
email_log = EmailLog.create(contact_id=contact.id, user_id=contact.user_id)
if not alias.enabled:
LOG.d("%s is disabled, do not forward", alias)
email_log.blocked = True
db.session.commit()
return True, "250 Message accepted for delivery"
spam_check = True
@ -343,12 +351,12 @@ def handle_forward(envelope, smtp: SMTP, msg: Message, rcpt_to: str) -> (bool, s
is_spam, spam_status = get_spam_info(msg)
if is_spam:
LOG.warning("Email detected as spam. Alias: %s, from: %s", alias, contact)
handle_spam(contact, alias, msg, user, mailbox_email, spam_status)
email_log.is_spam = True
email_log.spam_status = spam_status
handle_spam(contact, alias, msg, user, mailbox_email, email_log)
return False, "550 SL E1"
forward_log = EmailLog.create(contact_id=contact.id, user_id=contact.user_id)
if alias.enabled:
# add custom header
add_or_replace_header(msg, "X-SimpleLogin-Type", "Forward")
@ -408,9 +416,6 @@ def handle_forward(envelope, smtp: SMTP, msg: Message, rcpt_to: str) -> (bool, s
envelope.mail_options,
envelope.rcpt_options,
)
else:
LOG.d("%s is disabled, do not forward", alias)
forward_log.blocked = True
db.session.commit()
return True, "250 Message accepted for delivery"
@ -679,16 +684,8 @@ def handle_spam(
msg: Message,
user: User,
mailbox_email: str,
spam_status: str,
email_log: EmailLog,
):
email_log: EmailLog = EmailLog.create(
contact_id=contact.id,
user_id=contact.user_id,
is_spam=True,
spam_status=spam_status,
)
db.session.commit()
# Store the report & original email
orig_msg = get_orig_message_from_spamassassin_report(msg)
# generate a name for the email