Skip to content

Commit 26075de

Browse files
JonathanMelerAnar Azadaliyev
authored andcommitted
Fixes issue with EWS Search and Delete (#1696)
* Fixes issue with EWS Search and Delete * CR fixes * Fix typo and releaseNotes * Add Test playbook * Remove forward/ replay prefixes only from beginning of Subject
1 parent fe468ce commit 26075de

File tree

4 files changed

+162
-1
lines changed

4 files changed

+162
-1
lines changed

Playbooks/playbook-Search_And_Delete_Emails_-_EWS.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ id: search_and_delete_emails_-_ews
22
version: -1
33
name: Search And Delete Emails - EWS
44
fromversion: 3.6.0
5+
releaseNotes: "Added targe-mail-box to delete task"
56
description: This playbook searches EWS to identify and delete emails with similar
67
attributes of a malicious email.
78
starttaskid: "0"
@@ -263,7 +264,10 @@ tasks:
263264
complex:
264265
root: EWS
265266
accessor: Items.itemId
266-
target-mailbox: {}
267+
target-mailbox:
268+
complex:
269+
root: EWS
270+
accessor: Items.mailbox
267271
separatecontext: false
268272
view: |-
269273
{

Scripts/script-BuildEWSQuery.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@ commonfields:
22
id: BuildEWSQuery
33
version: -1
44
name: BuildEWSQuery
5+
releaseNotes: "Add parameter for stripping the subject from prefixes"
56
script: |-
7+
import re
8+
9+
# Regex for removing forward/replay prefixes
10+
p = re.compile('([\[\(] *)?(RE|FWD?) *([-:;)\]][ :;\])-]*|$)|\]+ *$', re.IGNORECASE)
11+
612
args = {}
713
814
if demisto.args().get("from"):
@@ -14,6 +20,20 @@ script: |-
1420
if demisto.args().get("body"):
1521
args["Body"] = demisto.args().get("body")
1622
23+
stripSubject = True if demisto.args().get("stripSubject").lower() == "true" else False
24+
if stripSubject and args["Subject"]:
25+
# Recursively remove the regex matches only from the beginning of the string
26+
match_string = args["Subject"]
27+
location_match = p.match(match_string)
28+
location = location_match.start() if location_match else -1
29+
30+
while(location==0 and match_string):
31+
match_string = p.sub("",match_string,1)
32+
location_match = p.match(match_string)
33+
location = location_match.start() if location_match else -1
34+
35+
args["Subject"] = match_string
36+
1737
query = " AND ".join('{0}:"{1}"'.format(key,value) for (key,value) in args.items())
1838
1939
search_last_week = True if demisto.args().get("searchThisWeek").lower() == "true" else False
@@ -49,6 +69,13 @@ args:
4969
- "false"
5070
description: Limit the search to the current week (true/false).
5171
defaultValue: "true"
72+
- name: stripSubject
73+
auto: PREDEFINED
74+
predefined:
75+
- "true"
76+
- "false"
77+
description: Removes the prefix from the subject of reply and forward messages (e.g., FW:).
78+
defaultValue: "true"
5279
outputs:
5380
- contextPath: EWS.Query
5481
description: The result query
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
id: buildewsquery_test
2+
version: 6
3+
name: BuildEWSQuery Test
4+
starttaskid: "0"
5+
tasks:
6+
"0":
7+
id: "0"
8+
taskid: 9c8a5ad7-0bf6-4355-8578-26a3d7d23b14
9+
type: start
10+
task:
11+
id: 9c8a5ad7-0bf6-4355-8578-26a3d7d23b14
12+
version: -1
13+
name: ""
14+
iscommand: false
15+
brand: ""
16+
nexttasks:
17+
'#none#':
18+
- "1"
19+
reputationcalc: 0
20+
separatecontext: false
21+
view: |-
22+
{
23+
"position": {
24+
"x": 50,
25+
"y": 50
26+
}
27+
}
28+
"1":
29+
id: "1"
30+
taskid: ad4f0f93-2d75-4125-8044-195cbaf6466f
31+
type: regular
32+
task:
33+
id: ad4f0f93-2d75-4125-8044-195cbaf6466f
34+
version: -1
35+
name: Build EWS Query
36+
scriptName: BuildEWSQuery
37+
type: regular
38+
iscommand: false
39+
brand: ""
40+
nexttasks:
41+
'#none#':
42+
- "2"
43+
scriptarguments:
44+
attachmentName: {}
45+
body: {}
46+
from:
47+
48+
searchThisWeek:
49+
simple: "true"
50+
stripSubject:
51+
simple: "true"
52+
subject:
53+
simple: 'RE: RE: FWD: hello RE: world'
54+
reputationcalc: 0
55+
separatecontext: false
56+
view: |-
57+
{
58+
"position": {
59+
"x": 50,
60+
"y": 195
61+
}
62+
}
63+
"2":
64+
id: "2"
65+
taskid: 77878e94-c11b-415c-8cf7-d0dbaef65626
66+
type: regular
67+
task:
68+
id: 77878e94-c11b-415c-8cf7-d0dbaef65626
69+
version: -1
70+
name: Verify query
71+
scriptName: VerifyContext
72+
type: regular
73+
iscommand: false
74+
brand: ""
75+
nexttasks:
76+
'#none#':
77+
- "3"
78+
scriptarguments:
79+
expectedValue:
80+
simple: 'From:"[email protected]" AND Subject:"hello RE: world" AND Received:"this
81+
week"'
82+
fields: {}
83+
path:
84+
simple: EWS.Query
85+
reputationcalc: 0
86+
separatecontext: false
87+
view: |-
88+
{
89+
"position": {
90+
"x": 50,
91+
"y": 370
92+
}
93+
}
94+
"3":
95+
id: "3"
96+
taskid: d6e4eb15-eac3-4dab-8ef5-9b00d0a83e38
97+
type: title
98+
task:
99+
id: d6e4eb15-eac3-4dab-8ef5-9b00d0a83e38
100+
version: -1
101+
name: Done
102+
type: title
103+
iscommand: false
104+
brand: ""
105+
reputationcalc: 0
106+
separatecontext: false
107+
view: |-
108+
{
109+
"position": {
110+
"x": 50,
111+
"y": 545
112+
}
113+
}
114+
view: |-
115+
{
116+
"linkLabelsPosition": {},
117+
"paper": {
118+
"dimensions": {
119+
"height": 560,
120+
"width": 380,
121+
"x": 50,
122+
"y": 50
123+
}
124+
}
125+
}
126+
inputs: []
127+
outputs: []

Tests/conf.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
"testTimeout": 160,
33
"testInterval": 20,
44
"tests": [
5+
{
6+
"playbookID": "buildewsquery_test"
7+
},
58
{
69
"integrations": "Palo Alto Minemeld",
710
"playbookID": "minemeld_test"

0 commit comments

Comments
 (0)