-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
79c858e
commit ee19b02
Showing
4 changed files
with
138 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,8 @@ | |
import dateparser | ||
import pytest | ||
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 EWSv2 import (fetch_last_emails, get_message_for_body_type, parse_item_as_dict, parse_physical_address, get_attachment_name, | ||
handle_attached_email_with_incorrect_message_id, handle_attached_email_with_incorrect_from_header, SMTP, email) | ||
from exchangelib.errors import UnauthorizedError, ErrorNameResolutionNoResults | ||
from exchangelib import EWSDateTime, EWSTimeZone, EWSDate | ||
from exchangelib.errors import ErrorInvalidIdMalformed, ErrorItemNotFound | ||
|
@@ -1077,3 +1078,45 @@ def test_get_item_as_eml(mocker): | |
|
||
get_item_as_eml("Inbox", "[email protected]") | ||
mock_file_result.assert_called_once_with("demisto_untitled_eml.eml", expected_data) | ||
|
||
|
||
@pytest.mark.parametrize("headers, expected_formatted_headers", [ | ||
pytest.param([("Message-ID", '<valid_header>')], [("Message-ID", '<valid_header>')], id="valid header"), | ||
pytest.param([("Message-ID", '<[valid_header]>')], [("Message-ID", '<valid_header>')], id="invalid header"), | ||
pytest.param([("Message-ID", 'Other type of header format')], [("Message-ID", 'Other type of header format')], | ||
id="untouched header format"), | ||
]) | ||
def test_handle_attached_email_with_incorrect_id(mocker, headers, expected_formatted_headers): | ||
""" | ||
Given: | ||
- case 1: valid Message-ID header value in attached email object | ||
- case 1: invalid Message-ID header value in attached email object | ||
- case 3: a Message-ID header value format which is not tested in the context of handle_attached_email_with_incorrect_id | ||
When: | ||
- fetching email which have an attached email with Message-ID header | ||
Then: | ||
- case 1: verify the header in the correct format | ||
- case 2: correct the invalid Message-ID header value | ||
- case 3: return the header value without without further handling | ||
""" | ||
mime_content = b'\xc400' | ||
email_policy = SMTP | ||
attached_email = email.message_from_bytes(mime_content, policy=email_policy) | ||
attached_email._headers = headers | ||
assert handle_attached_email_with_incorrect_message_id(attached_email)._headers == expected_formatted_headers | ||
|
||
|
||
def test_handle_attached_email_with_incorrect_from_header_fixes_malformed_header(): | ||
""" | ||
Given: | ||
An email message with a malformed From header. | ||
When: | ||
The handle_attached_email_with_incorrect_from_header function is called. | ||
Then: | ||
The From header is corrected and the email message object is updated. | ||
""" | ||
message = email.message_from_bytes(b"From: =?UTF-8?Q?Task_One=0DTest?= <[email protected]>", policy=SMTP) | ||
|
||
result = handle_attached_email_with_incorrect_from_header(message) | ||
|
||
assert result['From'] == 'Task One Test <[email protected]>' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
|
||
#### Integrations | ||
|
||
##### EWS v2 | ||
|
||
- Fixed an issue where fetching failed when email attachments had headers with an invalid format (`<[invalid_value]>` instead of `<valid_value>`), by removing the square brackets. | ||
- Fixed an issue where attachments with invalid characters in the From header were not being processed correctly by replacing the invalid characters with a white space character. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters