-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdmarc-reject.py
49 lines (43 loc) · 1.59 KB
/
dmarc-reject.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
import os
import email
from tkmail.delivery_reports import email_delivery_reports
counter = {'Apple<[email protected]>': 0,
'"Instagram" <[email protected]>': 0,
'Google <[email protected]>': 0,
'Nykredit <[email protected]>': 0,
'Nykredit <[email protected]>': 0,
'<*@facebookmail.com>': 0,
'Apple<[email protected]>': 0,
'<*@linkedin.com>': 0}
real_emails = 0
first = True
for base, report in email_delivery_reports():
if first:
print("First report is %s\n" % base)
first = False
if 'DMARC' in report.notification:
undelivered_message = report.message
from_ = undelivered_message['From']
if from_.endswith('@facebookmail.com>'):
counter['<*@facebookmail.com>'] += 1
continue
elif from_.endswith('@linkedin.com>'):
counter['<*@linkedin.com>'] += 1
continue
else:
try:
counter[from_] += 1
except KeyError:
pass
else:
continue
real_emails += 1
print(real_emails, base)
for k, v in undelivered_message.items():
if k.lower() in ('return-path', 'received') or k.startswith('List-'):
continue
if k.lower() in ('from', 'date', 'subject') or 'TAAGEKAMMERET' in str(v).upper():
h = email.header.make_header(email.header.decode_header(v))
print('%s: %s' % (k, h))
print('', flush=True)
print(counter)