Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pymilter-suspicious-from
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-suspicious-from
Commits
e343be18
Commit
e343be18
authored
5 years ago
by
Jan Philipp Timme
Browse files
Options
Downloads
Patches
Plain Diff
Handle issues with parse errors
parent
50f0b798
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
main.py
+7
-2
7 additions, 2 deletions
main.py
with
7 additions
and
2 deletions
main.py
+
7
−
2
View file @
e343be18
...
@@ -29,6 +29,8 @@ def normalizeRawFromHeader(value):
...
@@ -29,6 +29,8 @@ def normalizeRawFromHeader(value):
def
parseFromHeader
(
value
):
def
parseFromHeader
(
value
):
"""
Split
'
From:
'
-header into label and address values.
"""
"""
Split
'
From:
'
-header into label and address values.
"""
match
=
split_from_regex
.
match
(
value
)
match
=
split_from_regex
.
match
(
value
)
if
match
is
None
:
return
None
result
=
{
result
=
{
'
label
'
:
match
.
group
(
'
from_label
'
).
strip
(),
'
label
'
:
match
.
group
(
'
from_label
'
).
strip
(),
'
address
'
:
match
.
group
(
'
from_address
'
).
strip
()
'
address
'
:
match
.
group
(
'
from_address
'
).
strip
()
...
@@ -53,7 +55,7 @@ class SuspiciousFrom(Milter.Base):
...
@@ -53,7 +55,7 @@ class SuspiciousFrom(Milter.Base):
def
__init__
(
self
):
def
__init__
(
self
):
self
.
id
=
Milter
.
uniqueID
()
self
.
id
=
Milter
.
uniqueID
()
self
.
reset
()
self
.
reset
()
logger
.
info
(
f
"
(
{
self
.
id
}
) Instanciated.
"
)
logger
.
debug
(
f
"
(
{
self
.
id
}
) Instanciated.
"
)
def
reset
(
self
):
def
reset
(
self
):
self
.
final_result
=
Milter
.
ACCEPT
self
.
final_result
=
Milter
.
ACCEPT
...
@@ -68,6 +70,9 @@ class SuspiciousFrom(Milter.Base):
...
@@ -68,6 +70,9 @@ class SuspiciousFrom(Milter.Base):
logger
.
info
(
f
"
Got empty from header value! WTF! Skipping.
"
)
logger
.
info
(
f
"
Got empty from header value! WTF! Skipping.
"
)
return
Milter
.
CONTINUE
return
Milter
.
CONTINUE
data
=
parseFromHeader
(
value
)
data
=
parseFromHeader
(
value
)
if
data
is
None
:
logger
.
info
(
f
"
Failed to parse given from header value! Skipping.
"
)
return
Milter
.
CONTINUE
logger
.
info
(
f
"
(
{
self
.
id
}
) Label:
'
{
data
[
'
label
'
]
}
'
, Address:
'
{
data
[
'
address
'
]
}
'"
)
logger
.
info
(
f
"
(
{
self
.
id
}
) Label:
'
{
data
[
'
label
'
]
}
'
, Address:
'
{
data
[
'
address
'
]
}
'"
)
if
data
[
'
label_domain
'
]
is
not
None
:
if
data
[
'
label_domain
'
]
is
not
None
:
logger
.
debug
(
f
"
(
{
self
.
id
}
) Label
'
{
data
[
'
label
'
]
}
'
contains an address with domain
'
{
data
[
'
label_domain
'
]
}
'
.
"
)
logger
.
debug
(
f
"
(
{
self
.
id
}
) Label
'
{
data
[
'
label
'
]
}
'
contains an address with domain
'
{
data
[
'
label_domain
'
]
}
'
.
"
)
...
@@ -92,7 +97,7 @@ class SuspiciousFrom(Milter.Base):
...
@@ -92,7 +97,7 @@ class SuspiciousFrom(Milter.Base):
logger
.
info
(
f
"
(
{
self
.
id
}
) EOM: Final verdict is
{
self
.
final_result
}
. New headers:
{
self
.
new_headers
}
"
)
logger
.
info
(
f
"
(
{
self
.
id
}
) EOM: Final verdict is
{
self
.
final_result
}
. New headers:
{
self
.
new_headers
}
"
)
for
new_header
in
self
.
new_headers
:
for
new_header
in
self
.
new_headers
:
self
.
addheader
(
new_header
[
'
name
'
],
new_header
[
'
value
'
])
self
.
addheader
(
new_header
[
'
name
'
],
new_header
[
'
value
'
])
logger
.
info
(
f
"
(
{
self
.
id
}
) EOM: Reseting self.
"
)
logger
.
debug
(
f
"
(
{
self
.
id
}
) EOM: Reseting self.
"
)
self
.
reset
()
self
.
reset
()
return
self
.
final_result
return
self
.
final_result
...
...
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