Skip to content

Commit

Permalink
Merge branch 'contrib/PaloAltoNetworks_ASM-EXPANDR-11245-2' into ASM-…
Browse files Browse the repository at this point in the history
…EXPANDR-11245-2
  • Loading branch information
johnnywilkes authored Oct 1, 2024
2 parents 41d5ad1 + 2927524 commit 88b70c3
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 4 deletions.
8 changes: 6 additions & 2 deletions Packs/MicrosoftExchangeOnPremise/Integrations/EWSv2/EWSv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -1135,7 +1135,7 @@ def parse_incident_from_item(item, is_fetch): # pragma: no cover
# other item attachment
label_attachment_type = 'attachmentItems'
label_attachment_id_type = 'attachmentItemsId'

formatted_message: str | bytes
# save the attachment
if hasattr(attachment, 'item') and attachment.item.mime_content:
# Some items arrive with bytes attachemnt
Expand All @@ -1161,11 +1161,15 @@ def parse_incident_from_item(item, is_fetch): # pragma: no cover
except ValueError as err:
if "There may be at most" not in str(err):
raise err
try:
formatted_message = attached_email.as_string()
except UnicodeEncodeError:
formatted_message = attached_email.as_bytes()
file_result = fileResult(get_attachment_name(attachment_name=attachment.name,
content_id=attachment.content_id,
is_inline=attachment.is_inline,
attachment_subject=attachment.item.subject) + ".eml",
attached_email.as_string())
formatted_message)

if file_result:
# check for error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
from exchangelib import Message, Mailbox, Contact, HTMLBody, Body
from EWSv2 import fetch_last_emails, get_message_for_body_type, parse_item_as_dict, parse_physical_address, get_attachment_name
from exchangelib.errors import UnauthorizedError, ErrorNameResolutionNoResults
from exchangelib import EWSDateTime, EWSTimeZone
from exchangelib import EWSDateTime, EWSTimeZone, EWSDate
from exchangelib.errors import ErrorInvalidIdMalformed, ErrorItemNotFound
import demistomock as demisto
from exchangelib.properties import ItemId
from exchangelib.items import Item


class TestNormalCommands:
Expand Down Expand Up @@ -590,6 +591,41 @@ def test_categories_parse_item_as_dict():
assert return_value.get("categories") == ['Purple category', 'Orange category']


def test_parse_incident_from_item():
"""
Given -
a Message with attachments contains non-ASCII characters.
When -
running the parse_incident_from_item function.
Then -
verify that the attachments were parsed correctly.
"""
from EWSv2 import parse_incident_from_item
from exchangelib.attachments import AttachmentId, ItemAttachment

message = Message(subject='message4',
message_id='message4',
text_body='Hello World',
body='message4',
datetime_received=EWSDateTime(2021, 7, 14, 13, 10, 00, tzinfo=EWSTimeZone('UTC')),
datetime_sent=EWSDateTime(2021, 7, 14, 13, 9, 00, tzinfo=EWSTimeZone('UTC')),
datetime_created=EWSDateTime(2021, 7, 14, 13, 11, 00, tzinfo=EWSTimeZone('UTC')),
id='message4',
attachments=[
ItemAttachment(
item=Item(mime_content=b'\x80\x81\x82'),
attachment_id=AttachmentId(),
last_modified_time=EWSDate(year=2021, month=1, day=25),
),
],
)

return_value = parse_incident_from_item(message, is_fetch=False)
assert return_value.get("attachment")


def test_list_parse_item_as_dict():
"""
Given -
Expand Down
6 changes: 6 additions & 0 deletions Packs/MicrosoftExchangeOnPremise/ReleaseNotes/2_1_12.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

#### Integrations

##### EWS v2

- Fixed an issue where ***fetch incidents*** command failed when parsing messages with incorrect encoding.
2 changes: 1 addition & 1 deletion Packs/MicrosoftExchangeOnPremise/pack_metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "Microsoft Exchange On-Premise",
"description": "Exchange Web Services",
"support": "xsoar",
"currentVersion": "2.1.11",
"currentVersion": "2.1.12",
"author": "Cortex XSOAR",
"url": "https://www.paloaltonetworks.com/cortex",
"email": "",
Expand Down

0 comments on commit 88b70c3

Please sign in to comment.