Skip to content

Commit 006d025

Browse files
committed
1 parent a4d0bee commit 006d025

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

O365/message.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,9 @@ def to_api_data(self, restrict_keys=None):
686686
# this property does not form part of the message itself
687687
message[cc('parentFolderId')] = self.folder_id
688688

689+
if self.message_headers:
690+
message[cc('internetMessageHeaders')] = self.message_headers
691+
689692
if restrict_keys:
690693
for key in list(message.keys()):
691694
if key not in restrict_keys:

tests/test_message.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,25 @@ def test_save_draft_with_with_large_attachment_when_object_id_is_set(self):
211211
assert msg.con.calls[2].payload == b"conte"
212212
assert msg.con.calls[3].payload == b"nt"
213213

214+
def test_save_draft_with_custom_header(self):
215+
msg = message()
216+
msg.subject = "Test"
217+
my_custom_header = [{"name": "x-my-custom-header", "value": "myHeaderValue"}]
218+
msg.message_headers = my_custom_header
219+
220+
assert msg.save_draft() is True
221+
[call] = msg.con.calls
222+
assert call.url == self.base_url + "me/mailFolders/Drafts/messages"
223+
assert call.payload == {
224+
"body": {"content": "", "contentType": "HTML"},
225+
"flag": {"flagStatus": "notFlagged"},
226+
"importance": "normal",
227+
"isDeliveryReceiptRequested": False,
228+
"isReadReceiptRequested": False,
229+
"subject": "Test",
230+
"internetMessageHeaders": my_custom_header,
231+
}
232+
214233
def test_save_message(self):
215234
msg = message(__cloud_data__={"id": "123", "isDraft": False})
216235
msg.subject = "Changed"
@@ -291,6 +310,25 @@ def test_send(self):
291310
"saveToSentItems": False,
292311
}
293312

313+
def test_send_with_headers(self):
314+
my_testheader = {"x-my-custom-header": "some_value"}
315+
msg = message(__cloud_data__={"internetMessageHeaders": [my_testheader]})
316+
assert msg.send(save_to_sent_folder=False)
317+
[call] = msg.con.calls
318+
assert call.url == self.base_url + "me/sendMail"
319+
assert call.payload == {
320+
"message": {
321+
"body": {"content": "", "contentType": "HTML"},
322+
"flag": {"flagStatus": "notFlagged"},
323+
"importance": "normal",
324+
"isDeliveryReceiptRequested": False,
325+
"isReadReceiptRequested": False,
326+
"subject": "",
327+
"internetMessageHeaders": [my_testheader],
328+
},
329+
"saveToSentItems": False,
330+
}
331+
294332
def test_send_existing_object(self):
295333
msg = message(__cloud_data__={"id": "123"})
296334
assert msg.send()

0 commit comments

Comments
 (0)