Benjamin Renard
Add top_sender script
Benjamin Renard commited ffc6f7e at 2016-01-20 17:55:12
#!/usr/bin/python
from optparse import OptionParser
parser = OptionParser()
parser.add_option('-d',
'--debug',
action="store_true",
dest="debug")
parser.add_option('-v',
'--verbose',
action="store_true",
dest="verbose")
(options, args) = parser.parse_args()
import logging
if options.debug:
loglevel=logging.DEBUG
elif options.verbose:
loglevel=logging.INFO
else:
loglevel=logging.WARNING
logging.basicConfig(level=loglevel,format='%(asctime)s - %(levelname)s - %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p')
import subprocess
import re
mailq_p=subprocess.Popen(['mailq'], stdout=subprocess.PIPE)
mailq=mailq_p.communicate()[0]
senders={}
current_sender=None
for line in mailq.split('\n'):
m=re.match('^([A-Z0-9]+)\*?[ \t].* ([^ ]+)$',line)
if m:
sender=m.group(2)
logging.debug("New mailid of %s" % sender)
if sender not in senders:
senders[sender]={'count': 0, 'mailid': []}
senders[sender]['mailid'].append(m.group(1))
current_sender=sender
continue
m=re.match('^ *([^ ]+@.+)$',line)
if m:
if current_sender is None:
print "??? : %s" % line
continue
 
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX