Skip to content

Commit

Permalink
Outlook API enhancements and examples section updates
Browse files Browse the repository at this point in the history
  • Loading branch information
vgrem committed Apr 9, 2023
1 parent 9fc342a commit 11a408c
Show file tree
Hide file tree
Showing 26 changed files with 197 additions and 55 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,12 +236,12 @@ client.me.send_mail(

Additional examples & scenarios:

- [download a message](examples/outlook/download_messages.py)
- [list messages](examples/outlook/list_message.py)
- [move messages to a different folder](examples/outlook/move_message.py)
- [search messages](examples/outlook/search_message.py)
- [send messages](examples/outlook/send_message.py)
- [send messages with attachments](examples/outlook/send_message_with_attachment.py)
- [download a message](examples/outlook/messages/download.py)
- [list messages](examples/outlook/messages/list_all.py)
- [move messages to a different folder](examples/outlook/messages/move.py)
- [search messages](examples/outlook/messages/search.py)
- [send messages](examples/outlook/messages/send.py)
- [send messages with attachments](examples/outlook/messages/send_with_attachment.py)
- [enable sending emails on behalf of another user in your organization](https://learn.microsoft.com/en-us/microsoft-365/solutions/allow-members-to-send-as-or-send-on-behalf-of-group)

Refer to [examples section](examples/outlook) for other scenarios
Expand Down
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
client = GraphClient(acquire_token_by_username_password)

# local_path = "../../tests/data/Sample.txt"
local_path = "../../tests/data/big_buck_bunny.mp4"
local_path = "../../../tests/data/big_buck_bunny.mp4"


def print_progress(range_pos):
Expand Down
4 changes: 2 additions & 2 deletions generator/import_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ def export_to_file(path, content):

parser = ArgumentParser()
parser.add_argument("-e", "--endpoint", dest="endpoint",
help="Import metadata endpoint", default="microsoftgraph")
help="Import metadata endpoint", default="sharepoint")
parser.add_argument("-p", "--path",
dest="path", default="./metadata/MicrosoftGraph.xml",
dest="path", default="./metadata/SharePoint.xml",
help="Import metadata endpoint")

args = parser.parse_args()
Expand Down
159 changes: 122 additions & 37 deletions generator/metadata/SharePoint.xml

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions office365/directory/users/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,20 +93,20 @@ def send_mail(self, subject, body, to_recipients, cc_recipients=[], bcc_recipien
:param bool save_to_sent_items: Indicates whether to save the message in Sent Items. Specify it only if
the parameter is false; default is true
"""
message = Message(self.context)
message.subject = subject
message.body = body
[message.to_recipients.add(Recipient.from_email(email)) for email in to_recipients]
[message.bcc_recipients.add(Recipient.from_email(email)) for email in bcc_recipients]
[message.cc_recipients.add(Recipient.from_email(email)) for email in cc_recipients]
return_type = Message(self.context)
return_type.subject = subject
return_type.body = body
[return_type.to_recipients.add(Recipient.from_email(email)) for email in to_recipients]
[return_type.bcc_recipients.add(Recipient.from_email(email)) for email in bcc_recipients]
[return_type.cc_recipients.add(Recipient.from_email(email)) for email in cc_recipients]

payload = {
"message": message,
"message": return_type,
"saveToSentItems": save_to_sent_items
}
qry = ServiceOperationQuery(self, "sendmail", None, payload)
self.context.add_query(qry)
return message
return return_type

def export_personal_data(self, storage_location):
"""
Expand Down
8 changes: 8 additions & 0 deletions office365/outlook/convert_id_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,11 @@

class ConvertIdResult(ClientValue):
"""The result of an ID format conversion performed by the translateExchangeIds function."""

def __init__(self, source_id=None, target_id=None):
"""
:param str source_id: The identifier that was converted. This value is the original, un-converted identifier.
:param str target_id: The converted identifier. This value is not present if the conversion failed.
"""
self.sourceId = source_id
self.targetId = target_id
27 changes: 27 additions & 0 deletions office365/outlook/item.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import datetime

from office365.entity import Entity
from office365.runtime.types.collections import StringCollection

Expand All @@ -17,4 +19,29 @@ def categories(self):
"""
return self.properties.get("categories", StringCollection())

@property
def created_datetime(self):
"""
The Timestamp type represents date and time information using ISO 8601 format and is always in UTC time.
For example, midnight UTC on Jan 1, 2014 is 2014-01-01T00:00:00Z
"""
return self.properties.get("createdDateTime", datetime.datetime.min)

@property
def last_modified_datetime(self):
"""
The Timestamp type represents date and time information using ISO 8601 format and is always in UTC time.
For example, midnight UTC on Jan 1, 2014 is 2014-01-01T00:00:00Z
"""
return self.properties.get("lastModifiedDateTime", datetime.datetime.min)

def get_property(self, name, default_value=None):
if default_value is None:
property_mapping = {
"createdDateTime": self.created_datetime,
"lastModifiedDateTime": self.last_modified_datetime
}
default_value = property_mapping.get(name, None)
return super(OutlookItem, self).get_property(name, default_value)


20 changes: 19 additions & 1 deletion office365/outlook/mail/messages/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,25 @@ def reply_all(self):
self.context.add_query(qry)
return self

def create_reply(self, comment=None):
"""
Create a draft to reply to the sender of a message in either JSON or MIME format.
:param str comment:
"""
return_type = Message(self.context)
payload = {
"comment" : comment
}
qry = ServiceOperationQuery(self, "createReply", None, payload, None, return_type)
self.context.add_query(qry)
return self

def create_reply_all(self):
"""
Create a draft to reply to the sender and all the recipients of the specified message.
You can then update the draft to add reply content to the body or change other message properties, or,
simply send the draft.
:return:
"""
qry = ServiceOperationQuery(self, "createReplyAll")
self.context.add_query(qry)
Expand Down Expand Up @@ -243,6 +256,11 @@ def sender(self):
Find out more about setting the from and sender properties of a message."""
return self.get_property('sender', Recipient())

@property
def parent_folder_id(self):
"""The unique identifier for the message's parent mailFolder."""
return self.get_property('parentFolderId', None)

def get_property(self, name, default_value=None, track_changes=False):
if default_value is None:
property_type_mapping = {
Expand Down
4 changes: 4 additions & 0 deletions tests/outlook/test_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ def test3_send_message(self):
message.update()
message.send().execute_query()

#def test4_create_reply(self):
# message = self.__class__.target_message.create_reply().execute_query()
# self.assertIsNotNone(message.resource_path)

# def test4_forward_message(self):
# self.__class__.target_message.forward([test_user_principal_name_alt]).execute_query()

Expand Down

0 comments on commit 11a408c

Please sign in to comment.