-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocess-hold.py
executable file
·66 lines (54 loc) · 1.83 KB
/
process-hold.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env python
import os
import sys
import time
import datetime
expanduser = os.path.expanduser
expandvars = os.path.expandvars
def expand( name ): # handle $HOME/pathname or ~user/pathname
return expandvars( expanduser( name ))
if os.name in ( 'posix', 'dos' ):
DO_NOT_INCLUDE = ( '.', '..' ) # don't include these for dos & posix
else:
print "Unknown OS,", os.name, "exiting"
sys.exit(1);
def find( *paths ):
list = []
for pathname in paths:
os.path.walk( expand(pathname), append, list )
return list
def append( list, dirname, filelist ):
for filename in filelist:
if filename not in DO_NOT_INCLUDE:
filename = os.path.join( dirname, filename )
if not os.path.islink( filename ):
list.append( filename )
if __name__ == "__main__":
threshold = 100
release = 20
sleep = 1
while True:
hold_files = []
os.path.walk(expand("/var/spool/postfix/hold"), append, hold_files)
num_hold = len(hold_files)
active_files = []
os.path.walk(expand("/var/spool/postfix/active"), append, active_files)
num_active = len(active_files)
deferred_files = []
os.path.walk(expand("/var/spool/postfix/deferred"), append, deferred_files)
num_deferred = len(deferred_files)
print datetime.datetime.now(), "hold", num_hold, "active", num_active, "deferred", num_deferred
if num_hold > 0:
if num_active + num_deferred < threshold:
process_files = hold_files[0:min(release, num_hold)]
#print "Process more mail", process_files
for file in process_files:
cmd = "postsuper -H " + os.path.basename(file)
os.system(cmd)
print cmd
os.system("postqueue -f")
print "Waiting for awhile to process -- sleeping", sleep, "minutes"
time.sleep(60 * sleep)
else:
print "No more hold files"
sys.exit(0);