-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
110 lines (100 loc) · 3.12 KB
/
main.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# heimdall/main.py
import json
from evaluate import evaluate_email_expression, evaluate_gmail_expression
def main():
# Example usage
email_json = '{"sender": "[email protected]"}'
expression = 'email.receiver.endsWith("@example.com")'
result = evaluate_email_expression(email_json, expression)
if type(result) != bool:
if result.startswith("error:"):
print(f"Error: {result[6:]}")
else:
print(f"Expression result: {result}")
# Now to test for false
expression = 'email.sender.endsWith("@!example.com")'
result = evaluate_email_expression(email_json, expression)
if type(result) != bool:
if result.startswith("error:"):
print(f"Error: {result[6:]}")
else:
print(f"Expression result: {result}")
expression = 'email.receiver.endsWith("@shuffler.io")'
# now, testing for gmail
gmail_test_dict = {
"snippet": "Test",
"payload": {
"partId": "",
"mimeType": "multipart/alternative",
"filename": "",
"headers": [
{
"name": "Date",
"value": "Sun, 30 Jun 2024 11:42:06 -0700"
},
{
"name": "Subject",
"value": "Some fixes failed for Page indexing issues on site shuffler.io"
},
{
"name": "From",
"value": "Google Search Console Team <[email protected]>"
},
{
"name": "To",
"value": "[email protected]"
},
{
"name": "Content-Type",
"value": "multipart/alternative; boundary=\"0000000000005ee218061c1fd61d\""
}
],
"body": {
"size": 0
},
"parts": [
{
"partId": "0",
"mimeType": "text/plain",
"filename": "",
"headers": [
{
"name": "Content-Type",
"value": "text/plain; charset=\"UTF-8\"; format=flowed; delsp=yes"
}
],
"body": {
"size": 5,
"data": "eHl6=="
}
},
{
"partId": "1",
"mimeType": "text/html",
"filename": "",
"headers": [
{
"name": "Content-Type",
"value": "text/html; charset=\"UTF-8\""
},
{
"name": "Content-Transfer-Encoding",
"value": "quoted-printable"
}
],
"body": {
"size": 5,
"data": "PGRpdj54eXo8L2Rpdj4="
}
}
]
},
"sizeEstimate": 5,
"historyId": "xyz",
"internalDate": "1719790003609"
}
gmail_test = json.dumps(gmail_test_dict)
result = evaluate_gmail_expression(gmail_test, expression)
print(result)
if __name__ == '__main__':
main()