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
c0aa632e
Commit
c0aa632e
authored
18 years ago
by
Stuart Gathman
Browse files
Options
Downloads
Patches
Plain Diff
Negative feedback for bad headers. Purge cache logs on startup.
parent
a875ac78
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
Milter/cache.py
+12
-3
12 additions, 3 deletions
Milter/cache.py
Milter/plock.py
+62
-0
62 additions, 0 deletions
Milter/plock.py
bms.py
+7
-1
7 additions, 1 deletion
bms.py
with
81 additions
and
4 deletions
Milter/cache.py
+
12
−
3
View file @
c0aa632e
...
...
@@ -10,6 +10,9 @@
# CBV results.
#
# $Log$
# Revision 1.3 2007/01/08 23:20:54 customdesigned
# Get user feedback.
#
# Revision 1.2 2007/01/05 23:33:55 customdesigned
# Make blacklist an AddrCache
#
...
...
@@ -22,6 +25,7 @@
# This code is under the GNU General Public License. See COPYING for details.
import
time
from
plock
import
PLock
class
AddrCache
(
object
):
time_format
=
'
%Y%b%d %H:%M:%S %Z
'
...
...
@@ -39,6 +43,8 @@ class AddrCache(object):
cache
=
{}
self
.
cache
=
cache
now
=
time
.
time
()
lock
=
PLock
(
self
.
fname
)
wfp
=
lock
.
lock
()
try
:
too_old
=
now
-
age
*
24
*
60
*
60
# max age in days
for
ln
in
open
(
self
.
fname
):
...
...
@@ -46,11 +52,14 @@ class AddrCache(object):
rcpt
,
ts
=
ln
.
strip
().
split
(
None
,
1
)
l
=
time
.
strptime
(
ts
,
AddrCache
.
time_format
)
t
=
time
.
mktime
(
l
)
if
t
>
too_old
:
if
t
<
too_old
:
continue
cache
[
rcpt
.
lower
()]
=
(
t
,
None
)
except
:
cache
[
ln
.
strip
().
lower
()]
=
(
now
,
None
)
except
IOError
:
pass
wfp
.
write
(
ln
)
lock
.
commit
(
self
.
fname
+
'
.old
'
)
except
IOError
:
lock
.
unlock
()
def
has_key
(
self
,
sender
):
"
True if sender is cached and has not expired.
"
...
...
This diff is collapsed.
Click to expand it.
Milter/plock.py
0 → 100644
+
62
−
0
View file @
c0aa632e
# Author: Stuart D. Gathman <stuart@bmsi.com>
# Copyright 2001 Business Management Systems, Inc.
# This code is under the GNU General Public License. See COPYING for details.
import
os
from
time
import
sleep
class
PLock
(
object
):
"
A simple /etc/passwd style lock,update,rename protocol for updating files.
"
def
__init__
(
self
,
basename
):
self
.
basename
=
basename
self
.
fp
=
None
def
lock
(
self
,
lockname
=
None
):
"
Start an update transaction. Return FILE to write new version.
"
self
.
unlock
()
if
not
lockname
:
lockname
=
self
.
basename
+
'
.lock
'
self
.
lockname
=
lockname
st
=
os
.
stat
(
self
.
basename
)
u
=
os
.
umask
(
0002
)
try
:
fd
=
os
.
open
(
lockname
,
os
.
O_WRONLY
+
os
.
O_CREAT
+
os
.
O_EXCL
,
st
.
st_mode
|
0660
)
finally
:
os
.
umask
(
u
)
self
.
fp
=
os
.
fdopen
(
fd
,
'
w
'
)
try
:
os
.
chown
(
self
.
lockname
,
-
1
,
st
.
st_gid
)
except
:
self
.
unlock
()
raise
return
self
.
fp
def
wlock
(
self
,
lockname
=
None
):
"
Wait until lock is free, then start an update transaction.
"
while
True
:
try
:
return
self
.
lock
(
lockname
)
except
OSError
:
sleep
(
2
)
def
commit
(
self
,
backname
=
None
):
"
Commit update transaction with optional backup file.
"
if
not
self
.
fp
:
raise
IOError
,
"
File not locked
"
self
.
fp
.
close
()
self
.
fp
=
None
if
backname
:
try
:
os
.
remove
(
backname
)
except
OSError
:
pass
os
.
link
(
self
.
basename
,
backname
)
os
.
rename
(
self
.
lockname
,
self
.
basename
)
def
unlock
(
self
):
"
Cancel update transaction.
"
if
self
.
fp
:
try
:
self
.
fp
.
close
()
except
:
pass
self
.
fp
=
None
os
.
remove
(
self
.
lockname
)
This diff is collapsed.
Click to expand it.
bms.py
+
7
−
1
View file @
c0aa632e
#!/usr/bin/env python
# A simple milter that has grown quite a bit.
# $Log$
# Revision 1.84 2007/01/10 04:44:25 customdesigned
# Documentation updates.
#
# Revision 1.83 2007/01/08 23:20:54 customdesigned
# Get user feedback.
#
...
...
@@ -1017,7 +1020,10 @@ class bmsMilter(Milter.Milter):
val
=
parse_header
(
hval
)
if
not
self
.
internal_connection
and
not
(
self
.
blacklist
or
self
.
whitelist
):
rc
=
self
.
check_header
(
name
,
val
)
if
rc
!=
Milter
.
CONTINUE
:
return
rc
if
rc
!=
Milter
.
CONTINUE
:
if
gossip
and
self
.
umis
:
gossip_node
.
feedback
(
self
.
umis
,
1
)
return
rc
elif
self
.
whitelist_sender
and
lname
==
'
subject
'
:
# check for AutoReplys
vl
=
val
.
lower
()
...
...
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