refactoring: replace "X-SimpleLogin-Client-IP" by constant

This commit is contained in:
Son NK 2020-05-09 17:31:37 +02:00
parent bd68a52158
commit 7654992fc2
1 changed files with 5 additions and 9 deletions

View File

@ -474,10 +474,8 @@ def handle_reply(envelope, smtp: SMTP, msg: Message, rcpt_to: str) -> (bool, str
mailb: Mailbox = Mailbox.get_by(email=mailbox_email)
if ENFORCE_SPF and mailb.force_spf:
if msg["X-SimpleLogin-Client-IP"]:
r = spf.check2(
i=msg["X-SimpleLogin-Client-IP"], s=envelope.mail_from.lower(), h=None
)
if msg[_IP_HEADER]:
r = spf.check2(i=msg[_IP_HEADER], s=envelope.mail_from.lower(), h=None)
# TODO: Handle temperr case (e.g. dns timeout)
# only an absolute pass, or no SPF policy at all is 'valid'
if r[0] not in ["pass", "none"]:
@ -485,17 +483,15 @@ def handle_reply(envelope, smtp: SMTP, msg: Message, rcpt_to: str) -> (bool, str
"SPF fail for mailbox %s, reason %s, failed IP %s",
mailbox_email,
r[0],
msg["X-SimpleLogin-Client-IP"],
msg[_IP_HEADER],
)
return False, "451 SL E11"
else:
LOG.d(
"Could not find X-SimpleLogin-Client-IP header %s -> %s",
mailbox_email,
address,
"Could not find %s header %s -> %s", _IP_HEADER, mailbox_email, address,
)
delete_header(msg, "X-SimpleLogin-Client-IP")
delete_header(msg, _IP_HEADER)
# only mailbox can send email to the reply-email
if envelope.mail_from.lower() != mailbox_email.lower():