import psycopg2
import re
import datetime
+import argparse
+
+parser = argparse.ArgumentParser(description='Process DMARC records.')
+parser.add_argument('-c', '--config', action='store',
+ default='', dest='config_file',
+ help='Path to config file')
+parser.add_argument('-t', '--test', action='store_true',
+ default=False,
+ help='Test, but do not add records to the database')
+args = parser.parse_args()
def fetch_msg(num):
return mailbox.uid('FETCH', num, '(RFC822)')[1][0][1]
connection.commit()
config = configparser.ConfigParser()
-config.read('dmarc.ini')
+if args.config_file:
+ config.read(args.config_file)
+else:
+ config.read(['/etc/dmarc_to_database.ini', './dmarc_to_database.ini'])
+
+if not config.sections():
+ raise RuntimeError('Could not find configuration file')
conn = psycopg2.connect(host=config['database']['server'],
database=config['database']['database'],
results = cur.fetchall()
if not results:
print('write', report.find('./report_metadata/report_id').text)
- write_report(conn, cur, report)
+ if not args.test:
+ write_report(conn, cur, report)
conn.close()