-
Notifications
You must be signed in to change notification settings - Fork 2
/
ses.py
26 lines (19 loc) · 762 Bytes
/
ses.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
import json
def parse(notification):
topic = notification['TopicArn'].split(':')[5]
message = json.loads(notification['Message'])
source = message['mail']['source']
source_ip = message['mail']['sourceIp']
destination = message['mail']['destination']
delivery = message.get('delivery', {})
remote_mta_ip = delivery.get('remoteMtaIp', '')
timestamp = message['mail']['timestamp']
subject = message['mail']['commonHeaders']['subject']
filename = timestamp + '_' + destination[0]
text = (
'*{}* @ {}\n\n'
'*Source:* {} ({})\n'
'*Destination:* {} ({})\n'
'*Subject:* {}'
).format(topic, timestamp, source, source_ip, destination, remote_mta_ip, subject)
return text, filename