fix is_automatic_out_of_office: only use "Auto-Submitted" header
This commit is contained in:
parent
0abfb82fd1
commit
ffc621596a
|
@ -43,6 +43,7 @@ MIME_HEADERS = [
|
||||||
# convert to lowercase to facilitate header look up
|
# convert to lowercase to facilitate header look up
|
||||||
MIME_HEADERS = [h.lower() for h in MIME_HEADERS]
|
MIME_HEADERS = [h.lower() for h in MIME_HEADERS]
|
||||||
|
|
||||||
# if any of these headers are present, that means automatic out of office email
|
|
||||||
AUTO_REPLY1 = "X-Autoreply"
|
# according to https://datatracker.ietf.org/doc/html/rfc3834#section-3.1.7, this header should be set to "auto-replied"
|
||||||
AUTO_REPLY2 = "Auto-Submitted"
|
# however on hotmail, this is set to "auto-generated"
|
||||||
|
AUTO_SUBMITTED = "Auto-Submitted"
|
||||||
|
|
|
@ -5,7 +5,7 @@ E202 = "250 Unsubscribe request accepted"
|
||||||
E203 = "250 SL E203 email can't be sent from a reverse-alias"
|
E203 = "250 SL E203 email can't be sent from a reverse-alias"
|
||||||
E204 = "250 SL E204 ignore"
|
E204 = "250 SL E204 ignore"
|
||||||
E205 = "250 SL E205 bounce handled"
|
E205 = "250 SL E205 bounce handled"
|
||||||
# out of office status
|
# out-of-office status
|
||||||
E206 = "250 SL E206 Out of office"
|
E206 = "250 SL E206 Out of office"
|
||||||
|
|
||||||
# if mail_from is a IgnoreBounceSender, no need to send back a bounce report
|
# if mail_from is a IgnoreBounceSender, no need to send back a bounce report
|
||||||
|
|
|
@ -1666,6 +1666,7 @@ class EmailLog(Base, ModelMixin):
|
||||||
forward = orm.relationship(Contact)
|
forward = orm.relationship(Contact)
|
||||||
|
|
||||||
contact = orm.relationship(Contact, backref="email_logs")
|
contact = orm.relationship(Contact, backref="email_logs")
|
||||||
|
alias = orm.relationship(Alias)
|
||||||
mailbox = orm.relationship("Mailbox", lazy="joined", foreign_keys=[mailbox_id])
|
mailbox = orm.relationship("Mailbox", lazy="joined", foreign_keys=[mailbox_id])
|
||||||
user = orm.relationship(User)
|
user = orm.relationship(User)
|
||||||
|
|
||||||
|
|
|
@ -1752,15 +1752,19 @@ def handle_spam(
|
||||||
|
|
||||||
|
|
||||||
def is_automatic_out_of_office(msg: Message) -> bool:
|
def is_automatic_out_of_office(msg: Message) -> bool:
|
||||||
if msg[headers.AUTO_REPLY1] is not None:
|
"""
|
||||||
LOG.d(
|
Return whether an email is out-of-office
|
||||||
"out-of-office email %s:%s", headers.AUTO_REPLY1, msg[headers.AUTO_REPLY1]
|
For info, out-of-office is sent to the envelope mail_from and not the From: header
|
||||||
)
|
More info on https://datatracker.ietf.org/doc/html/rfc3834#section-4 and https://support.google.com/mail/thread/21246740/my-auto-reply-filter-isn-t-replying-to-original-sender-address?hl=en&msgid=21261237
|
||||||
return True
|
"""
|
||||||
|
if msg[headers.AUTO_SUBMITTED] is None:
|
||||||
|
return False
|
||||||
|
|
||||||
if msg[headers.AUTO_REPLY2] is not None:
|
if msg[headers.AUTO_SUBMITTED].lower() in ("auto-replied", "auto-generated"):
|
||||||
LOG.d(
|
LOG.d(
|
||||||
"out-of-office email %s:%s", headers.AUTO_REPLY2, msg[headers.AUTO_REPLY2]
|
"out-of-office email %s:%s",
|
||||||
|
headers.AUTO_SUBMITTED,
|
||||||
|
msg[headers.AUTO_SUBMITTED],
|
||||||
)
|
)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
|
@ -53,11 +53,11 @@ def test_is_automatic_out_of_office():
|
||||||
msg = EmailMessage()
|
msg = EmailMessage()
|
||||||
assert not is_automatic_out_of_office(msg)
|
assert not is_automatic_out_of_office(msg)
|
||||||
|
|
||||||
msg[headers.AUTO_REPLY1] = "yes"
|
msg[headers.AUTO_SUBMITTED] = "auto-replied"
|
||||||
assert is_automatic_out_of_office(msg)
|
assert is_automatic_out_of_office(msg)
|
||||||
|
|
||||||
del msg[headers.AUTO_REPLY1]
|
del msg[headers.AUTO_SUBMITTED]
|
||||||
assert not is_automatic_out_of_office(msg)
|
assert not is_automatic_out_of_office(msg)
|
||||||
|
|
||||||
msg[headers.AUTO_REPLY2] = "auto-replied"
|
msg[headers.AUTO_SUBMITTED] = "auto-generated"
|
||||||
assert is_automatic_out_of_office(msg)
|
assert is_automatic_out_of_office(msg)
|
||||||
|
|
Loading…
Reference in a new issue