Skip to content

Commit b75eab7

Browse files
author
Simon Hellbe
committed
Add message methods for categories
1 parent 4b707d6 commit b75eab7

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

O365/message.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ class Message(object):
2020
fetchAttachments -- kicks off the process that downloads attachments.
2121
sendMessage -- take local variables and form them to send the message.
2222
markAsRead -- marks the analougs message in the cloud as read.
23+
setCategories -- sets the list of categories in the cloud
24+
getCategories -- gets the email's categories
2325
getSender -- gets a dictionary with the sender's information.
2426
getSenderEmail -- gets the email address of the sender.
2527
getSenderName -- gets the name of the sender, if possible.
@@ -128,6 +130,21 @@ def markAsRead(self):
128130
return False
129131
return True
130132

133+
def setCategories(self, categories=""):
134+
'''sets message categories in the cloud.'''
135+
categories = json.dumps(dict(Categories=categories))
136+
headers = {'Content-type': 'application/json', 'Accept': 'application/json'}
137+
try:
138+
response = requests.patch(self.update_url.format(
139+
self.json['Id']), categories, headers=headers, auth=self.auth,verify=self.verify)
140+
except:
141+
return False
142+
return True
143+
144+
def getCategories(self):
145+
'''gets the message's categories'''
146+
return self.json['Categories']
147+
131148
def getSender(self):
132149
'''get all available information for the sender of the email.'''
133150
return self.json['Sender']

tests/test_message.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def post(url,data,headers,auth):
5858
else:
5959
return Resp(None,202)
6060

61-
61+
6262

6363
message.requests.post = post
6464

@@ -72,23 +72,23 @@ def patch(url,data,headers,auth):
7272
if headers['Content-type'] != 'application/json':
7373
raise
7474
if headers['Accept'] != 'application/json':
75-
raise
75+
raise
7676
return True
7777

7878
message.requests.patch = patch
7979

8080
auth = ('test@unit.com','pass')
8181

8282
class TestMessage (unittest.TestCase):
83-
83+
8484
def setUp(self):
8585
ur = json.loads(un_rep)['value'][0]
8686
self.unread = message.Message(ur,auth)
8787
re = json.loads(read_rep)['value'][0]
8888
self.read = message.Message(re,auth)
8989
att = json.loads(att_m_rep)['value'][0]
9090
self.att = message.Message(att,auth)
91-
91+
9292
self.newm = message.Message(auth=auth)
9393

9494
def test_fetchAttachments(self):
@@ -117,6 +117,9 @@ def test_sendMessage(self):
117117
def test_markAsRead(self):
118118
self.unread.markAsRead()
119119

120+
def test_setCategories(self):
121+
self.unread.setCategories(["Green", "Yellow"])
122+
120123
def test_setRecipients(self):
121124
self.assertTrue(len(self.read.json['ToRecipients']) == 1)
122125
self.assertTrue(len(self.unread.json['ToRecipients']) == 1)
@@ -125,7 +128,7 @@ def test_setRecipients(self):
125128
self.read.setRecipients('bob@unit.com')
126129
self.assertTrue(self.read.json['ToRecipients'][0]['EmailAddress']['Address'] == 'bob@unit.com')
127130

128-
self.unread.setRecipients({'EmailAddress':{'Address':'bob@unit.com','Name':'What about'}})
131+
self.unread.setRecipients({'EmailAddress':{'Address':'bob@unit.com','Name':'What about'}})
129132
self.assertTrue(self.unread.json['ToRecipients'][0]['EmailAddress']['Address'] == 'bob@unit.com')
130133
self.assertTrue(self.unread.json['ToRecipients'][0]['EmailAddress']['Name'] == 'What about')
131134

0 commit comments

Comments
 (0)