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
4749f0ff
Commit
4749f0ff
authored
5 years ago
by
Stuart D. Gathman
Browse files
Options
Downloads
Patches
Plain Diff
Change header callback to bytes, but default Milter to convert
to str with surrogateescape.
parent
18186a3c
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
Milter/__init__.py
+7
-0
7 additions, 0 deletions
Milter/__init__.py
Milter/testctx.py
+15
-2
15 additions, 2 deletions
Milter/testctx.py
miltermodule.c
+1
-1
1 addition, 1 deletion
miltermodule.c
with
23 additions
and
3 deletions
Milter/__init__.py
+
7
−
0
View file @
4749f0ff
...
@@ -701,6 +701,13 @@ def connect_callback(ctx,hostname,family,hostaddr,nr_mask=P_NR_CONN):
...
@@ -701,6 +701,13 @@ def connect_callback(ctx,hostname,family,hostaddr,nr_mask=P_NR_CONN):
m
.
_setctx
(
ctx
)
m
.
_setctx
(
ctx
)
return
m
.
connect
(
hostname
,
family
,
hostaddr
)
return
m
.
connect
(
hostname
,
family
,
hostaddr
)
## @private
# @brief check str/bytes decorator and invoke header method.
def
header_callback
(
ctx
,
fld
,
val
):
m
=
ctx
.
getpriv
()
s
=
val
.
decode
(
encoding
=
'
ascii
'
,
errors
=
'
surrogateescape
'
)
return
m
.
header
(
fld
,
s
)
## @private
## @private
# @brief Disconnect milterContext and call close method.
# @brief Disconnect milterContext and call close method.
def
close_callback
(
ctx
):
def
close_callback
(
ctx
):
...
...
This diff is collapsed.
Click to expand it.
Milter/testctx.py
+
15
−
2
View file @
4749f0ff
...
@@ -15,6 +15,7 @@ except:
...
@@ -15,6 +15,7 @@ except:
import
Milter
import
Milter
from
Milter
import
utils
from
Milter
import
utils
import
mime
import
mime
import
email
## Milter context for unit testing %milter applications.
## Milter context for unit testing %milter applications.
# A substitute for milter.milterContext that can be passed to
# A substitute for milter.milterContext that can be passed to
...
@@ -219,7 +220,20 @@ class TestCtx(object):
...
@@ -219,7 +220,20 @@ class TestCtx(object):
return
rc
return
rc
def
_header
(
self
,
fld
,
val
):
def
_header
(
self
,
fld
,
val
):
return
self
.
_priv
.
header
(
fld
,
val
)
# email.message_from_binary_file uses surrogateescape to
# preserve original bytes in unicode string for decoding errors.
# convert str or Header back to original bytes
if
hasattr
(
val
,
'
_chunks
'
):
# val is a Header object for invalid header values
v
=
b
''
for
s
,
charset
in
val
.
_chunks
:
# recover the original bytes
b
=
s
.
encode
(
encoding
=
'
ascii
'
,
errors
=
'
surrogateescape
'
)
v
+=
b
else
:
v
=
val
.
encode
(
encoding
=
'
ascii
'
,
errors
=
'
surrogateescape
'
)
# invoke the Milter header_callback
return
Milter
.
header_callback
(
self
,
fld
,
v
)
def
_eoh
(
self
):
def
_eoh
(
self
):
if
self
.
_protocol
&
Milter
.
P_NOEOH
:
if
self
.
_protocol
&
Milter
.
P_NOEOH
:
...
@@ -270,7 +284,6 @@ class TestCtx(object):
...
@@ -270,7 +284,6 @@ class TestCtx(object):
if
rc
!=
Milter
.
CONTINUE
:
return
rc
if
rc
!=
Milter
.
CONTINUE
:
return
rc
# header
# header
for
h
,
val
in
msg
.
items
():
for
h
,
val
in
msg
.
items
():
# val is a Header object for invalid header values
rc
=
self
.
_header
(
h
,
val
)
rc
=
self
.
_header
(
h
,
val
)
if
rc
!=
Milter
.
CONTINUE
:
return
rc
if
rc
!=
Milter
.
CONTINUE
:
return
rc
# eoh
# eoh
...
...
This diff is collapsed.
Click to expand it.
miltermodule.c
+
1
−
1
View file @
4749f0ff
...
@@ -674,7 +674,7 @@ milter_wrap_header(SMFICTX *ctx, char *headerf, char *headerv) {
...
@@ -674,7 +674,7 @@ milter_wrap_header(SMFICTX *ctx, char *headerf, char *headerv) {
if
(
header_callback
==
NULL
)
return
SMFIS_CONTINUE
;
if
(
header_callback
==
NULL
)
return
SMFIS_CONTINUE
;
c
=
_get_context
(
ctx
);
c
=
_get_context
(
ctx
);
if
(
!
c
)
return
SMFIS_TEMPFAIL
;
if
(
!
c
)
return
SMFIS_TEMPFAIL
;
arglist
=
Py_BuildValue
(
"(O
ss
)"
,
c
,
headerf
,
headerv
);
arglist
=
Py_BuildValue
(
"(O
yy
)"
,
c
,
headerf
,
headerv
);
return
_generic_wrapper
(
c
,
header_callback
,
arglist
);
return
_generic_wrapper
(
c
,
header_callback
,
arglist
);
}
}
...
...
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