delete the email log in reply phase if NonReverseAliasInReplyPhase
This commit is contained in:
parent
b23f9fa971
commit
ed4acebdb1
|
@ -315,6 +315,8 @@ ALERT_SPAM_EMAIL = "spam"
|
||||||
# When an email is sent from a mailbox to an alias - a cycle
|
# When an email is sent from a mailbox to an alias - a cycle
|
||||||
ALERT_SEND_EMAIL_CYCLE = "cycle"
|
ALERT_SEND_EMAIL_CYCLE = "cycle"
|
||||||
|
|
||||||
|
ALERT_NON_REVERSE_ALIAS_REPLY_PHASE = "non_reverse_alias_reply_phase"
|
||||||
|
|
||||||
ALERT_SPF = "spf"
|
ALERT_SPF = "spf"
|
||||||
|
|
||||||
# when a mailbox is also an alias
|
# when a mailbox is also an alias
|
||||||
|
|
|
@ -133,9 +133,12 @@ class ModelMixin(object):
|
||||||
Session.add(self)
|
Session.add(self)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def delete(cls, obj_id):
|
def delete(cls, obj_id, commit=False):
|
||||||
Session.query(cls).filter(cls.id == obj_id).delete()
|
Session.query(cls).filter(cls.id == obj_id).delete()
|
||||||
|
|
||||||
|
if commit:
|
||||||
|
Session.commit()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def first(cls):
|
def first(cls):
|
||||||
return Session.query(cls).first()
|
return Session.query(cls).first()
|
||||||
|
|
|
@ -85,6 +85,7 @@ from app.config import (
|
||||||
ALERT_HOTMAIL_COMPLAINT_TRANSACTIONAL,
|
ALERT_HOTMAIL_COMPLAINT_TRANSACTIONAL,
|
||||||
ALERT_HOTMAIL_COMPLAINT_REPLY_PHASE,
|
ALERT_HOTMAIL_COMPLAINT_REPLY_PHASE,
|
||||||
OLD_UNSUBSCRIBER,
|
OLD_UNSUBSCRIBER,
|
||||||
|
ALERT_NON_REVERSE_ALIAS_REPLY_PHASE,
|
||||||
)
|
)
|
||||||
from app.db import Session
|
from app.db import Session
|
||||||
from app.email import status, headers
|
from app.email import status, headers
|
||||||
|
@ -1060,8 +1061,7 @@ def handle_reply(envelope, msg: Message, rcpt_to: str) -> (bool, str):
|
||||||
"Cannot encrypt message %s -> %s. %s %s", alias, contact, mailbox, user
|
"Cannot encrypt message %s -> %s. %s %s", alias, contact, mailbox, user
|
||||||
)
|
)
|
||||||
# programming error, user shouldn't see a new email log
|
# programming error, user shouldn't see a new email log
|
||||||
EmailLog.delete(email_log.id)
|
EmailLog.delete(email_log.id, commit=True)
|
||||||
Session.commit()
|
|
||||||
# return 421 so the client can retry later
|
# return 421 so the client can retry later
|
||||||
return False, status.E402
|
return False, status.E402
|
||||||
|
|
||||||
|
@ -1090,7 +1090,13 @@ def handle_reply(envelope, msg: Message, rcpt_to: str) -> (bool, str):
|
||||||
replace_header_when_reply(msg, alias, headers.CC)
|
replace_header_when_reply(msg, alias, headers.CC)
|
||||||
except NonReverseAliasInReplyPhase as e:
|
except NonReverseAliasInReplyPhase as e:
|
||||||
LOG.w("non reverse-alias in reply %s %s %s", e, contact, alias)
|
LOG.w("non reverse-alias in reply %s %s %s", e, contact, alias)
|
||||||
send_email(
|
|
||||||
|
# the email is ignored, delete the email log
|
||||||
|
EmailLog.delete(email_log.id, commit=True)
|
||||||
|
|
||||||
|
send_email_at_most_times(
|
||||||
|
user,
|
||||||
|
ALERT_NON_REVERSE_ALIAS_REPLY_PHASE,
|
||||||
mailbox.email,
|
mailbox.email,
|
||||||
f"Email sent to {contact.email} contains non reverse-alias addresses",
|
f"Email sent to {contact.email} contains non reverse-alias addresses",
|
||||||
render(
|
render(
|
||||||
|
|
Loading…
Reference in a new issue