From dfde5367c002eed7e801f2fdc3ae45f19d6d40da Mon Sep 17 00:00:00 2001 From: Narcolapser Date: Fri, 23 Oct 2015 13:03:04 -0400 Subject: [PATCH] Tended to the requestion in issue #14 where the desired functinality was to be able to send groups to event and message to set or add them as recipients or contacts. This should now work. --- O365/event.py | 27 +++++++++++++++------------ O365/message.py | 16 +++++++++++----- tests/run_test.sh | 8 ++++++++ tests/run_test3.sh | 8 ++++++++ 4 files changed, 42 insertions(+), 17 deletions(-) diff --git a/O365/event.py b/O365/event.py index 4cefbaebcee8..5499868cacd1 100644 --- a/O365/event.py +++ b/O365/event.py @@ -214,10 +214,6 @@ def getAttendees(self): '''Gets list of event attendees.''' return self.json['Attendees'] -# def addAttendee(self,val): -# '''adds an attendee to the event. must call update for notification to send.''' -# self.json['Attendees'].append(val) - def setSubject(self,val): '''sets event subject line.''' self.json['Subject'] = val @@ -236,7 +232,7 @@ def setEnd(self,val): def setAttendee(self,val): ''' - set the recipient list. + set the attendee list. val: the one argument this method takes can be very flexible. you can send: a dictionary: this must to be a dictionary formated as such: @@ -250,17 +246,18 @@ def setAttendee(self,val): For each of these argument types the appropriate action will be taken to fit them to the needs of the library. ''' + self.json['Attendees'] = [] if isinstance(val,list): self.json['Attendees'] = val elif isinstance(val,dict): self.json['Attendees'] = [val] elif isinstance(val,str): if '@' in val: - self.json['Attendees'] = [] - self.addRecipient(val) + self.addAttendee(val) elif isinstance(val,Contact): - self.json['Attendees'] = [] - self.addRecipient(val) + self.addAttendee(val) + elif isinstance(val,Group): + self.addAttendee(val) else: return False return True @@ -271,12 +268,18 @@ def addAttendee(self,address,name=None): Arguments: address -- the email address of the person you are sending to. <<< Important that. - Address can also be of type contact. if it is name is superflous. Else, it - uses the name passed if you sent it one. - name -- the name of the person you are sending to. mostly just a decorator. + Address can also be of type Contact or type Group. + name -- the name of the person you are sending to. mostly just a decorator. If you + send an email address for the address arg, this will give you the ability + to set the name properly, other wise it uses the email address up to the + at sign for the name. But if you send a type Contact or type Group, this + argument is completely ignored. ''' if isinstance(address,Contact): self.json['Attendees'].append(address.getFirstEmailAddress()) + elif isinstance(address,Group): + for con in address.contacts: + self.json['Attendees'].append(address.getFirstEmailAddress()) else: if name is None: name = address[:address.index('@')] diff --git a/O365/message.py b/O365/message.py index 8589498213c5..95ea78caaa57 100644 --- a/O365/message.py +++ b/O365/message.py @@ -1,5 +1,6 @@ from O365.attachment import Attachment from O365.contact import Contact +from O365.group import Group import logging import json import requests @@ -166,8 +167,8 @@ def setRecipients(self,val): For each of these argument types the appropriate action will be taken to fit them to the needs of the library. ''' + self.json['ToRecipients'] = [] if isinstance(val,list): - self.json['ToRecipients'] = [] for con in val: if isinstance(con,Contact): self.addRecipient(con) @@ -177,7 +178,6 @@ def setRecipients(self,val): self.json['ToRecipients'] = [val] elif isinstance(val,str): if '@' in val: - self.json['ToRecipients'] = [] self.addRecipient(val) elif isinstance(val,Contact): self.addRecipient(val) @@ -194,12 +194,18 @@ def addRecipient(self,address,name=None): Arguments: address -- the email address of the person you are sending to. <<< Important that. - Address can also be of type contact. if it is name is superflous. Else, it - uses the name passed if you sent it one. - name -- the name of the person you are sending to. mostly just a decorator. + Address can also be of type Contact or type Group. + name -- the name of the person you are sending to. mostly just a decorator. If you + send an email address for the address arg, this will give you the ability + to set the name properly, other wise it uses the email address up to the + at sign for the name. But if you send a type Contact or type Group, this + argument is completely ignored. ''' if isinstance(address,Contact): self.json['ToRecipients'].append(address.getFirstEmailAddress()) + elif isinstance(address,Group): + for con in address.contacts: + self.json['ToRecipients'].append(address.getFirstEmailAddress()) else: if name is None: name = address[:address.index('@')] diff --git a/tests/run_test.sh b/tests/run_test.sh index 3c8fd6b55ddf..4caf91bfad69 100755 --- a/tests/run_test.sh +++ b/tests/run_test.sh @@ -1,10 +1,18 @@ +echo "python test_attachment.py" python test_attachment.py +echo "python test_cal.py" python test_cal.py +echo "python test_event.py" python test_event.py +echo "python test_inbox.py" python test_inbox.py +echo "python test_message.py" python test_message.py +echo "python test_schedule.py" python test_schedule.py +echo "python test_group.py" python test_group.py +echo "python test_contact.py" python test_contact.py echo "all tests done." diff --git a/tests/run_test3.sh b/tests/run_test3.sh index c637b9d53402..71ce788b930d 100755 --- a/tests/run_test3.sh +++ b/tests/run_test3.sh @@ -1,10 +1,18 @@ +echo "python3 test_attachment.py" python3 test_attachment.py +echo "python3 test_cal.py" python3 test_cal.py +echo "python3 test_event.py" python3 test_event.py +echo "python3 test_inbox.py" python3 test_inbox.py +echo "python3 test_message.py" python3 test_message.py +echo "python3 test_schedule.py" python3 test_schedule.py +echo "python3 test_group.py" python3 test_group.py +echo "python3 test_contact.py" python3 test_contact.py echo "all tests done."