#! /usr/bin/python
VIRUS_DIR = '/var/lib/amavis/virusmails'

import os, email.Parser
def virus_report(directory):
    parser = email.Parser.Parser()
    body = []
    for name in os.listdir(directory):
        path = os.path.join(directory, name)
        if os.access(path, os.R_OK):
            message = parser.parse(file(path), 1)
            try:
                to = message['x-envelope-to']
                alert = message['x-amavis-alert']
                body.append('%s\n    message to: %s\n    alert "%s"' % (name, to, alert))
            except KeyError:
                continue
    return '\n'.join(['Number of virus mails in quarentine: %d' % len(body), ''] + body)


if __name__ == '__main__':
    print virus_report(VIRUS_DIR)
