Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pymilter
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
misc
pymilter
Commits
493741c8
Commit
493741c8
authored
20 years ago
by
Stuart Gathman
Browse files
Options
Downloads
Patches
Plain Diff
Return consistent tuple on error.
parent
9a969e8f
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
Milter/dsn.py
+8
-5
8 additions, 5 deletions
Milter/dsn.py
with
8 additions
and
5 deletions
Milter/dsn.py
+
8
−
5
View file @
493741c8
...
@@ -95,7 +95,10 @@ Received-SPF: %(spf_result)s
...
@@ -95,7 +95,10 @@ Received-SPF: %(spf_result)s
"""
"""
def
send_dsn
(
mailfrom
,
receiver
,
msg
=
None
):
def
send_dsn
(
mailfrom
,
receiver
,
msg
=
None
):
"
Send DSN. If msg is None, do callback verification.
"
"""
Send DSN. If msg is None, do callback verification.
Mailfrom is original sender we are sending DSN or CBV to.
Receiver is the MTA sending the DSN.
Return None for success or (code,msg) for failure.
"""
user
,
domain
=
mailfrom
.
split
(
'
@
'
)
user
,
domain
=
mailfrom
.
split
(
'
@
'
)
q
=
spf
.
query
(
None
,
None
,
None
)
q
=
spf
.
query
(
None
,
None
,
None
)
mxlist
=
q
.
dns
(
domain
,
'
MX
'
)
mxlist
=
q
.
dns
(
domain
,
'
MX
'
)
...
@@ -112,7 +115,7 @@ def send_dsn(mailfrom,receiver,msg=None):
...
@@ -112,7 +115,7 @@ def send_dsn(mailfrom,receiver,msg=None):
if
resp
.
split
()[
0
]
==
receiver
:
if
resp
.
split
()[
0
]
==
receiver
:
return
(
553
,
'
Fraudulent MX for %s
'
%
domain
)
return
(
553
,
'
Fraudulent MX for %s
'
%
domain
)
if
not
(
200
<=
code
<=
299
):
if
not
(
200
<=
code
<=
299
):
raise
SMTPHeloError
(
code
,
resp
)
raise
smtplib
.
SMTPHeloError
(
code
,
resp
)
if
msg
:
if
msg
:
try
:
try
:
smtp
.
sendmail
(
'
<>
'
,
mailfrom
,
msg
)
smtp
.
sendmail
(
'
<>
'
,
mailfrom
,
msg
)
...
@@ -122,7 +125,7 @@ def send_dsn(mailfrom,receiver,msg=None):
...
@@ -122,7 +125,7 @@ def send_dsn(mailfrom,receiver,msg=None):
else
:
# CBV
else
:
# CBV
code
,
resp
=
smtp
.
docmd
(
'
MAIL FROM: <>
'
)
code
,
resp
=
smtp
.
docmd
(
'
MAIL FROM: <>
'
)
if
code
!=
250
:
if
code
!=
250
:
raise
SMTPSenderRefused
(
code
,
resp
,
'
<>
'
)
raise
smtplib
.
SMTPSenderRefused
(
code
,
resp
,
'
<>
'
)
code
,
resp
=
smtp
.
rcpt
(
mailfrom
)
code
,
resp
=
smtp
.
rcpt
(
mailfrom
)
if
code
not
in
(
250
,
251
):
if
code
not
in
(
250
,
251
):
return
(
code
,
resp
)
# permanent error
return
(
code
,
resp
)
# permanent error
...
@@ -131,9 +134,9 @@ def send_dsn(mailfrom,receiver,msg=None):
...
@@ -131,9 +134,9 @@ def send_dsn(mailfrom,receiver,msg=None):
except
smtplib
.
SMTPRecipientsRefused
,
x
:
except
smtplib
.
SMTPRecipientsRefused
,
x
:
return
x
.
recipients
[
mailfrom
]
# permanent error
return
x
.
recipients
[
mailfrom
]
# permanent error
except
smtplib
.
SMTPSenderRefused
,
x
:
except
smtplib
.
SMTPSenderRefused
,
x
:
return
x
# does not accept DSN
return
x
.
args
[:
2
]
# does not accept DSN
except
smtplib
.
SMTPDataError
,
x
:
except
smtplib
.
SMTPDataError
,
x
:
return
x
# permanent error
return
x
.
args
# permanent error
except
smtplib
.
SMTPException
:
except
smtplib
.
SMTPException
:
pass
# any other error, try next MX
pass
# any other error, try next MX
except
socket
.
error
:
except
socket
.
error
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment