Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add message_id parameter #63

Merged
merged 3 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions AUTHORS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
* Abhishek Ram <[email protected]> @abhishek-ram
* Chad Gates @chadgates
* Bruno Ribeiro da Silva <[email protected]> @loop0
* Robin C Samuel @robincsamuel
- Abhishek Ram <[email protected]> @abhishek-ram
- Chad Gates @chadgates
- Bruno Ribeiro da Silva <[email protected]> @loop0
- Robin C Samuel @robincsamuel
- Brandon Joyce @brandonjoyce
16 changes: 12 additions & 4 deletions pyas2lib/as2.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ def build(
content_type="application/edi-consent",
additional_headers=None,
disposition_notification_to="[email protected]",
message_id=None,
):

"""Function builds the AS2 message. Compresses, signs and encrypts
Expand All @@ -354,6 +355,10 @@ def build(
:param disposition_notification_to:
Email address for disposition-notification-to header entry.
(default "[email protected]")

:param message_id:
The message id to be used for the message. If not provided a
unique message id is generated. (default None)
"""

# Validations
Expand All @@ -372,10 +377,13 @@ def build(
"Encryption of messages is enabled but encrypt key is not set for the receiver."
)

# Generate message id using UUID 1 as it uses both hostname and time
self.message_id = (
email_utils.make_msgid(domain=self.sender.domain).lstrip("<").rstrip(">")
)
if message_id:
self.message_id = message_id
abhishek-ram marked this conversation as resolved.
Show resolved Hide resolved
else:
# Generate message id using UUID 1 as it uses both hostname and time
self.message_id = (
email_utils.make_msgid(domain=self.sender.domain).lstrip("<").rstrip(">")
)

# Set up the message headers
as2_headers = {
Expand Down
8 changes: 8 additions & 0 deletions pyas2lib/tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,14 @@ def test_plain_message_without_domain(self):
out_message.build(self.test_data)
self.assertEqual(out_message.message_id.split("@")[1], socket.getfqdn())

def test_plain_message_with_custom_message_id(self):
"""Test Message building with a custom message id"""

# Build an As2 message to be transmitted to partner
out_message = as2.Message(self.org, self.partner)
out_message.build(self.test_data, message_id="some_custom_id")
self.assertEqual(out_message.message_id, "some_custom_id")

def find_org(self, as2_id):
return self.org

Expand Down
Loading