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
46ed3ddb
Commit
46ed3ddb
authored
17 years ago
by
Stuart Gathman
Browse files
Options
Downloads
Patches
Plain Diff
Allow arbitrary object, not just spf.query like, to provide data for create_msg
parent
6048fe6e
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
+40
-19
40 additions, 19 deletions
Milter/dsn.py
with
40 additions
and
19 deletions
Milter/dsn.py
+
40
−
19
View file @
46ed3ddb
...
@@ -5,6 +5,9 @@
...
@@ -5,6 +5,9 @@
# Send DSNs, do call back verification,
# Send DSNs, do call back verification,
# and generate DSN messages from a template
# and generate DSN messages from a template
# $Log$
# $Log$
# Revision 1.15 2007/09/24 20:13:26 customdesigned
# Remove explicit spf dependency.
#
# Revision 1.14 2007/03/03 18:19:40 customdesigned
# Revision 1.14 2007/03/03 18:19:40 customdesigned
# Handle DNS error sending DSN.
# Handle DNS error sending DSN.
#
#
...
@@ -89,23 +92,41 @@ def send_dsn(mailfrom,receiver,msg=None,timeout=600,session=None):
...
@@ -89,23 +92,41 @@ def send_dsn(mailfrom,receiver,msg=None,timeout=600,session=None):
return
(
450
,
'
No MX response within %f minutes
'
%
(
timeout
/
60.0
))
return
(
450
,
'
No MX response within %f minutes
'
%
(
timeout
/
60.0
))
return
(
450
,
'
No MX servers available
'
)
# temp error
return
(
450
,
'
No MX servers available
'
)
# temp error
def
create_msg
(
q
,
rcptlist
,
origmsg
=
None
,
template
=
None
):
class
Vars
:
pass
"
Create a DSN message from a template. Template must be
'
\n
'
separated.
"
# NOTE: Caller can pass an object to create_msg that in a typical milter
# collects things like heloname or sender anyway.
def
create_msg
(
v
,
rcptlist
=
None
,
origmsg
=
None
,
template
=
None
):
"""
Create a DSN message from a template. Template must be
'
\n
'
separated.
v - an object whose attributes are used for substitutions. Must
have sender and receiver attributes at a minimum.
rcptlist - used to set v.rcpt if given
origmsg - used to set v.subject and v.spf_result if given
template - a
'
\n
'
separated string with python
'
%(name)s
'
substitutions.
"""
if
not
template
:
if
not
template
:
return
None
return
None
heloname
=
q
.
h
if
hasattr
(
v
,
'
perm_error
'
):
sender
=
q
.
s
# likely to be an spf.query, try translating for backward compatibility
connectip
=
q
.
i
q
=
v
receiver
=
q
.
r
v
=
Vars
()
sender_domain
=
q
.
o
try
:
result
=
q
.
result
v
.
heloname
=
q
.
h
perm_error
=
q
.
perm_error
v
.
sender
=
q
.
s
rcpt
=
'
\n\t
'
.
join
(
rcptlist
)
v
.
connectip
=
q
.
i
try
:
subject
=
origmsg
[
'
Subject
'
]
v
.
receiver
=
q
.
r
except
:
subject
=
'
(none)
'
v
.
sender_domain
=
q
.
o
v
.
result
=
q
.
result
v
.
perm_error
=
q
.
perm_error
except
:
v
=
q
if
rcptlist
:
v
.
rcpt
=
'
\n\t
'
.
join
(
rcptlist
)
if
origmsg
:
try
:
v
.
subject
=
origmsg
[
'
Subject
'
]
except
:
v
.
subject
=
'
(none)
'
try
:
try
:
spf_result
=
origmsg
[
'
Received-SPF
'
]
v
.
spf_result
=
origmsg
[
'
Received-SPF
'
]
except
:
spf_result
=
None
except
:
v
.
spf_result
=
None
msg
=
Message
()
msg
=
Message
()
...
@@ -115,13 +136,13 @@ def create_msg(q,rcptlist,origmsg=None,template=None):
...
@@ -115,13 +136,13 @@ def create_msg(q,rcptlist,origmsg=None,template=None):
hdrs
,
body
=
template
.
split
(
'
\n\n
'
,
1
)
hdrs
,
body
=
template
.
split
(
'
\n\n
'
,
1
)
for
ln
in
hdrs
.
splitlines
():
for
ln
in
hdrs
.
splitlines
():
name
,
val
=
ln
.
split
(
'
:
'
,
1
)
name
,
val
=
ln
.
split
(
'
:
'
,
1
)
msg
.
add_header
(
name
,(
val
%
locals
()
).
strip
())
msg
.
add_header
(
name
,(
val
%
v
.
__dict__
).
strip
())
msg
.
set_payload
(
body
%
locals
()
)
msg
.
set_payload
(
body
%
v
.
__dict__
)
# add headers if missing from old template
# add headers if missing from old template
if
'
to
'
not
in
msg
:
if
'
to
'
not
in
msg
:
msg
.
add_header
(
'
To
'
,
sender
)
msg
.
add_header
(
'
To
'
,
v
.
sender
)
if
'
from
'
not
in
msg
:
if
'
from
'
not
in
msg
:
msg
.
add_header
(
'
From
'
,
'
postmaster@%s
'
%
receiver
)
msg
.
add_header
(
'
From
'
,
'
postmaster@%s
'
%
v
.
receiver
)
if
'
auto-submitted
'
not
in
msg
:
if
'
auto-submitted
'
not
in
msg
:
msg
.
add_header
(
'
Auto-Submitted
'
,
'
auto-generated
'
)
msg
.
add_header
(
'
Auto-Submitted
'
,
'
auto-generated
'
)
return
msg
return
msg
...
...
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