diff --git a/MANIFEST b/MANIFEST index 3b7ebd9279582..65f111a7fa642 100644 --- a/MANIFEST +++ b/MANIFEST @@ -1,12 +1,12 @@ # file GENERATED by distutils, do NOT edit setup.cfg setup.py -O365\__init__.py -O365\attachment.py -O365\cal.py -O365\contact.py -O365\event.py -O365\group.py -O365\inbox.py -O365\message.py -O365\schedule.py +O365/__init__.py +O365/attachment.py +O365/cal.py +O365/contact.py +O365/event.py +O365/group.py +O365/inbox.py +O365/message.py +O365/schedule.py diff --git a/O365/attachment.py b/O365/attachment.py index 126a686ccbaac..c06770a507a0d 100644 --- a/O365/attachment.py +++ b/O365/attachment.py @@ -32,7 +32,7 @@ class Attachment( object ): create_url = 'https://outlook.office365.com/api/v1.0/me/messages/{0}/attachments' - def __init__(self,json=None,path=None): + def __init__(self,json=None,path=None,verify=True): ''' Creates a new attachment class, optionally from existing JSON. @@ -61,6 +61,8 @@ def __init__(self,json=None,path=None): else: self.json = {'@odata.type':'#Microsoft.OutlookServices.FileAttachment'} + self.verify = verify + def isType(self,typeString): '''Test to if the attachment is the same type as you are seeking. Do not include a period.''' return '.'+typeString.lower() in self.json['Name'].lower() @@ -99,7 +101,7 @@ def attach(self,message): data = json.dumps(self.json) - response = requests.post(self.create_url.format(mid),data,header=headers,auth=message.auth) + response = requests.post(self.create_url.format(mid),data,header=headers,auth=message.auth,verify=self.verify) log.debug('Response from server for attaching: {0}'.format(str(response))) return response diff --git a/O365/cal.py b/O365/cal.py index de54c96e10f3f..1f73b0e687b8c 100644 --- a/O365/cal.py +++ b/O365/cal.py @@ -26,7 +26,7 @@ class Calendar( object ): events_url = 'https://outlook.office365.com/api/v1.0/me/calendars/{0}/calendarview?startDateTime={1}&endDateTime={2}&$top={3}' time_string = '%Y-%m-%dT%H:%M:%SZ' - def __init__(self, json=None, auth=None): + def __init__(self, json=None, auth=None, verify=True): ''' Wraps all the information for managing calendars. ''' @@ -39,6 +39,8 @@ def __init__(self, json=None, auth=None): self.calendarId = json['Id'] self.name = json['Name'] + self.verify = verify + def getName(self): '''Get the calendar's Name.''' return self.json['Name'] @@ -84,7 +86,7 @@ def getEvents(self,start=None,end=None, eventCount=10): end = time.strftime(self.time_string,end) # This is where the actual call to Office365 happens. - response = requests.get(self.events_url.format(self.json['Id'],start,end,eventCount) ,auth=self.auth) + response = requests.get(self.events_url.format(self.json['Id'],start,end,eventCount) ,auth=self.auth, verify=self.verify) log.info('Response from O365: %s', str(response)) #This takes that response and then parses it into individual calendar events. diff --git a/O365/contact.py b/O365/contact.py index 4188a0897f19d..e122f42f5e4f9 100644 --- a/O365/contact.py +++ b/O365/contact.py @@ -23,7 +23,7 @@ class Contact( object ): con_url = 'https://outlook.office365.com/api/v1.0/me/contacts/{0}' time_string = '%Y-%m-%dT%H:%M:%SZ' - def __init__(self, json=None, auth=None): + def __init__(self, json=None, auth=None, verify=True): ''' Wraps all the informaiton for managing contacts. ''' @@ -38,12 +38,14 @@ def __init__(self, json=None, auth=None): log.debug('there was no json, putting in some dumby info.') self.json = {'DisplayName':'Jebediah Kerman'} + self.verify = verify + def delete(self): '''delete's a contact. cause who needs that guy anyway?''' headers = {'Content-type': 'application/json', 'Accept': 'text/plain'} log.debug('preparing to delete contact.') - response = requests.delete(self.con_url.format(str(self.contactId)),headers=headers,auth=self.auth) + response = requests.delete(self.con_url.format(str(self.contactId)),headers=headers,auth=self.auth,verify=self.verify) log.debug('response from delete attempt: {0}'.format(str(response))) return response.status_code == 204 @@ -60,7 +62,7 @@ def update(self): response = None try: - response = requests.patch(self.con_url.format(str(self.contactId)),data,headers=headers,auth=self.auth) + response = requests.patch(self.con_url.format(str(self.contactId)),data,headers=headers,auth=self.auth,verify=self.verify) log.debug('sent update request') except Exception as e: if response: @@ -85,7 +87,7 @@ def create(self): response = None try: - response = requests.post(self.con_url.format(str(self.contactId)),data,headers=headers,auth=self.auth) + response = requests.post(self.con_url.format(str(self.contactId)),data,headers=headers,auth=self.auth,verify=self.verify) log.debug('sent create request') except Exception as e: if response: @@ -159,6 +161,4 @@ def addEmail(self,address,name=None): '''takes a plain string email, and optionally name, and appends it to list.''' ins = {'Address':address,'Name':None} - - #To the King! diff --git a/O365/event.py b/O365/event.py index b2fbe9a97cbbd..722d475621b5d 100644 --- a/O365/event.py +++ b/O365/event.py @@ -47,7 +47,7 @@ class Event( object ): delete_url = 'https://outlook.office365.com/api/v1.0/me/events/{0}' - def __init__(self,json=None,auth=None,cal=None): + def __init__(self,json=None,auth=None,cal=None,verify=True): ''' Creates a new event wrapper. @@ -68,6 +68,8 @@ def __init__(self,json=None,auth=None,cal=None): else: self.json = {} + self.verify = verify + def create(self,calendar=None): ''' @@ -105,7 +107,7 @@ def create(self,calendar=None): response = None try: log.debug('sending post request now') - response = requests.post(self.create_url.format(calId),data,headers=headers,auth=self.auth) + response = requests.post(self.create_url.format(calId),data,headers=headers,auth=self.auth,verify=self.verify) log.debug('sent post request.') except Exception as e: if response: @@ -134,7 +136,7 @@ def update(self): response = None try: - response = requests.patch(self.update_url.format(self.json['Id']),data,headers=headers,auth=self.auth) + response = requests.patch(self.update_url.format(self.json['Id']),data,headers=headers,auth=self.auth,verify=self.verify) log.debug('sending patch request now') except Exception as e: if response: @@ -163,7 +165,7 @@ def delete(self): response = None try: log.debug('sending delete request') - response = requests.delete(self.delete_url.format(self.json['Id']),headers=headers,auth=self.auth) + response = requests.delete(self.delete_url.format(self.json['Id']),headers=headers,auth=self.auth,verify=self.verify) except Exception as e: if response: diff --git a/O365/group.py b/O365/group.py index 1f89d01cd91df..9a4a5974826f6 100644 --- a/O365/group.py +++ b/O365/group.py @@ -22,7 +22,7 @@ class Group( object ): con_folder_url = 'https://outlook.office365.com/api/v1.0/me/contactfolders/{0}/contacts' folder_url = 'https://outlook.office365.com/api/v1.0/me/contactfolders?$filter=DisplayName eq \'{0}\'' - def __init__(self, auth, folderName=None): + def __init__(self, auth, folderName=None,verify=True): ''' Creates a group class for managing all contacts associated with email+password. @@ -34,22 +34,24 @@ def __init__(self, auth, folderName=None): self.contacts = [] self.folderName = folderName + self.verify = verify + def getContacts(self): '''Begin the process of downloading contact metadata.''' if self.folderName is None: log.debug('fetching contacts.') - response = requests.get(self.con_url,auth=self.auth) + response = requests.get(self.con_url,auth=self.auth,verify=self.verify) log.info('Response from O365: %s', str(response)) else: log.debug('fetching contact folder.') - response = requests.get(self.folder_url.format(self.folderName),auth=self.auth) + response = requests.get(self.folder_url.format(self.folderName),auth=self.auth,verify=self.verify) fid = response.json()['value'][0]['Id'] log.debug('got a response of {0} and an Id of {1}'.format(response.status_code,fid)) log.debug('fetching contacts for {0}.'.format(self.folderName)) - response = requests.get(self.con_folder_url.format(fid),auth=self.auth) + response = requests.get(self.con_folder_url.format(fid),auth=self.auth,verify=self.verify) log.info('Response from O365: {0}'.format(str(response))) for contact in response.json()['value']: diff --git a/O365/inbox.py b/O365/inbox.py index e05fd54ede23a..fcb1b914e21e2 100644 --- a/O365/inbox.py +++ b/O365/inbox.py @@ -18,7 +18,7 @@ class Inbox( object ): #url for fetching emails. Takes a flag for whether they are read or not. inbox_url = 'https://outlook.office365.com/api/v1.0/me/messages' - def __init__(self, auth, getNow=True): + def __init__(self, auth, getNow=True, verify=True): ''' Creates a new inbox wrapper. Send email and password for authentication. @@ -35,6 +35,8 @@ def __init__(self, auth, getNow=True): self.filters = 'IsRead eq false' self.getMessages() + self.verify = verify + def getMessages(self, number = 10): ''' @@ -50,7 +52,7 @@ def getMessages(self, number = 10): ''' log.debug('fetching messages.') - response = requests.get(self.inbox_url,auth=self.auth,params={'$filter':self.filters, '$top':number}) + response = requests.get(self.inbox_url,auth=self.auth,params={'$filter':self.filters, '$top':number},verify=self.verify) log.info('Response from O365: %s', str(response)) for message in response.json()['value']: diff --git a/O365/message.py b/O365/message.py index 2a8410670fc80..d7b66792bb57d 100644 --- a/O365/message.py +++ b/O365/message.py @@ -8,261 +8,251 @@ log = logging.getLogger(__name__) class Message(object): - ''' - Management of the process of sending, recieving, reading, and editing emails. - - Note: the get and set methods are technically superflous. You can get more through control over - a message you are trying to craft throught he use of editing the message.json, but these - methods provide an easy way if you don't need all the power and would like the ease. - - Methods: - constructor -- creates a new message class, using json for existing, nothing for new. - fetchAttachments -- kicks off the process that downloads attachments. - sendMessage -- take local variables and form them to send the message. - markAsRead -- marks the analougs message in the cloud as read. - getSender -- gets a dictionary with the sender's information. - getSenderEmail -- gets the email address of the sender. - getSenderName -- gets the name of the sender, if possible. - getSubject -- gets the email's subject line. - getBody -- gets contents of the body of the email. - setFrom -- sets the email's sender in case username have permissions to send mail for - other account. - addRecipient -- adds a person to the recipient list. - setRecipients -- sets the list of recipients. - setSubject -- sets the subject line. - setBody -- sets the body. - - Variables: - att_url -- url for requestiong attachments. takes message GUID - send_url -- url for sending an email - update_url -- url for updating an email already existing in the cloud. - - ''' - - att_url = 'https://outlook.office365.com/api/v1.0/me/messages/{0}/attachments' - send_url = 'https://outlook.office365.com/api/v1.0/me/sendmail' - draft_url = 'https://outlook.office365.com/api/v1.0/me/folders/{folder_id}/messages' - update_url = 'https://outlook.office365.com/api/v1.0/me/messages/{0}' - - def __init__(self, json=None, auth=None): - ''' - Makes a new message wrapper for sending and recieving messages. - - Keyword Arguments: - json (default = None) -- Takes json if you have a pre-existing message to create from. - this is mostly used inside the library for when new messages are downloaded. - auth (default = None) -- Takes an (email,password) tuple that will be used for - authentication with office365. - ''' - if json: - self.json = json - self.hasAttachments = json['HasAttachments'] - - else: - self.json = {'Message': {'Body': {}}, - 'ToRecipients': [], 'CcRecipients': [], 'BccRecipients': []} - self.hasAttachments = False - - self.auth = auth - self.attachments = [] - self.reciever = None - - def fetchAttachments(self): - '''kicks off the process that downloads attachments locally.''' - if not self.hasAttachments: - log.debug('message has no attachments, skipping out early.') - return False - - response = requests.get(self.att_url.format( - self.json['Id']), auth=self.auth) - log.info('response from O365 for retriving message attachments: %s', str(response)) - json = response.json() - - for att in json['value']: - try: - self.attachments.append(Attachment(att)) - log.debug('successfully downloaded attachment for: %s.', self.auth[0]) - except Exception as e: - log.info('failed to download attachment for: %s', self.auth[0]) - - return len(self.attachments) - - def sendMessage(self): - '''takes local variabls and forms them into a message to be sent.''' - - headers = {'Content-type': 'application/json', 'Accept': 'text/plain'} - - try: - data = {'Message': {'Body': {}}} - data['Message']['Subject'] = self.json['Subject'] - data['Message']['Body']['Content'] = self.json['Body']['Content'] - data['Message']['Body']['ContentType'] = self.json['Body']['ContentType'] - if 'From' in self.json: - data['Message']['From'] = self.json['From'] - data['Message']['ToRecipients'] = self.json['ToRecipients'] - data['Message']['CcRecipients'] = self.json['CcRecipients'] - data['Message']['BccRecipients'] = self.json['BccRecipients'] - data['Message']['Attachments'] = [att.json for att in self.attachments] - data = json.dumps(data) - except Exception as e: - log.error( - 'Error while trying to compile the json string to send: {0}'.format(str(e))) - return False - - response = requests.post( - self.send_url, data, headers=headers, auth=self.auth) - log.debug('response from server for sending message:' + str(response)) - log.debug("respnse body: {}".format(response.text)) - if response.status_code != 202: - return False - - return True - - def markAsRead(self): - '''marks analogous message as read in the cloud.''' - read = '{"IsRead":true}' - headers = {'Content-type': 'application/json', 'Accept': 'application/json'} - try: - response = requests.patch(self.update_url.format( - self.json['Id']), read, headers=headers, auth=self.auth) - except: - return False - return True - - def getSender(self): - '''get all available information for the sender of the email.''' - return self.json['Sender'] - - def getSenderEmail(self): - '''get the email address of the sender.''' - return self.json['Sender']['EmailAddress']['Address'] - - def getSenderName(self): - '''try to get the name of the sender.''' - try: - return self.json['Sender']['EmailAddress']['Name'] - except: - return '' - - def getSubject(self): - '''get email subject line.''' - return self.json['Subject'] - - def getBody(self): - '''get email body.''' - return self.json['Body']['Content'] - - def setRecipients(self, val, r_type="To"): - ''' - set the recipient 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: - {"EmailAddress":{"Address":"recipient@example.com"}} - with other options such ass "Name" with address. but at minimum - it must have this. - a list: this must to be a list of libraries formatted the way - specified above, or it can be a list of dictionary objects of - type Contact or it can be an email address as string. The - method will sort out the libraries from the contacts. - a string: this is if you just want to throw an email address. - a contact: type Contact from this dictionary. - a group: type Group, which is a list of contacts. - For each of these argument types the appropriate action will be taken - to fit them to the needs of the library. - ''' - log.debug("Entered SET_RECIPIENTS function with type: {}".format(r_type)) - self.json[r_type + 'Recipients'] = [] - - if isinstance(val, list): - for con in val: - if isinstance(con, Contact): - self.addRecipient(con, r_type=r_type) - elif isinstance(con, str): - if '@' in con: - self.addRecipient(con, r_type=r_type) - elif isinstance(con, dict): - self.json[r_type + 'Recipients'].append(con) - elif isinstance(val, dict): - self.json[r_type + 'Recipients'] = [val] - elif isinstance(val, str): - if '@' in val: - self.addRecipient(val, r_type=r_type) - elif isinstance(val, Contact): - self.addRecipient(val, r_type=r_type) - elif isinstance(val, Group): - for person in val: - self.addRecipient(person, r_type=r_type) - else: - return False - return True - - def addRecipient(self, address, name=None, r_type="To"): - ''' - Adds a recipient to the recipients list. - - Arguments: - address -- the email address of the person you are sending to. <<< Important that. - 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[r_type + 'Recipients'].append(address.getFirstEmailAddress()) - elif isinstance(address, Group): - for con in address.contacts: - self.json[r_type + 'Recipients'].append(address.getFirstEmailAddress()) - else: - if name is None: - name = address[:address.index('@')] - self.json[r_type + 'Recipients'].append( - {'EmailAddress': {'Address': address, 'Name': name}}) - - def setFrom(self, address, name = None): - ''' - Set custom sender through an other account, in case you have permissions to send as - the other account. - ''' - if name == None: - name = address[:address.index('@')] - self.json['From'] = {"EmailAddress":{"Address":address, "Name": name}} - - def setSubject(self, val): - '''Sets the subect line of the email.''' - self.json['Subject'] = val - - def setBody(self, val): - '''Sets the body content of the email.''' - cont = False - - while not cont: - try: - self.json['Body']['Content'] = val - self.json['Body']['ContentType'] = 'Text' - cont = True - except: - self.json['Body'] = {} - - def setBodyHTML(self, val=None): - ''' - Sets the body content type to HTML for your pretty emails. - - arguments: - val -- Default: None. The content of the body you want set. If you don't pass a - value it is just ignored. - ''' - cont = False - - while not cont: - try: - self.json['Body']['ContentType'] = 'HTML' - if val: - self.json['Body']['Content'] = val - cont = True - except: - self.json['Body'] = {} - -# To the King! \ No newline at end of file + ''' + Management of the process of sending, recieving, reading, and editing emails. + + Note: the get and set methods are technically superflous. You can get more through control over + a message you are trying to craft throught he use of editing the message.json, but these + methods provide an easy way if you don't need all the power and would like the ease. + + Methods: + constructor -- creates a new message class, using json for existing, nothing for new. + fetchAttachments -- kicks off the process that downloads attachments. + sendMessage -- take local variables and form them to send the message. + markAsRead -- marks the analougs message in the cloud as read. + getSender -- gets a dictionary with the sender's information. + getSenderEmail -- gets the email address of the sender. + getSenderName -- gets the name of the sender, if possible. + getSubject -- gets the email's subject line. + getBody -- gets contents of the body of the email. + addRecipient -- adds a person to the recipient list. + setRecipients -- sets the list of recipients. + setSubject -- sets the subject line. + setBody -- sets the body. + + Variables: + att_url -- url for requestiong attachments. takes message GUID + send_url -- url for sending an email + update_url -- url for updating an email already existing in the cloud. + + ''' + + att_url = 'https://outlook.office365.com/api/v1.0/me/messages/{0}/attachments' + send_url = 'https://outlook.office365.com/api/v1.0/me/sendmail' + draft_url = 'https://outlook.office365.com/api/v1.0/me/folders/{folder_id}/messages' + update_url = 'https://outlook.office365.com/api/v1.0/me/messages/{0}' + + def __init__(self, json=None, auth=None, verify=True): + ''' + Makes a new message wrapper for sending and recieving messages. + + Keyword Arguments: + json (default = None) -- Takes json if you have a pre-existing message to create from. + this is mostly used inside the library for when new messages are downloaded. + auth (default = None) -- Takes an (email,password) tuple that will be used for + authentication with office365. + ''' + if json: + self.json = json + self.hasAttachments = json['HasAttachments'] + + else: + self.json = {'Message': {'Body': {}}, + 'ToRecipients': [], 'CcRecipients': [], 'BccRecipients': []} + self.hasAttachments = False + + self.auth = auth + self.attachments = [] + self.reciever = None + + self.verify = verify + + + def fetchAttachments(self): + '''kicks off the process that downloads attachments locally.''' + if not self.hasAttachments: + log.debug('message has no attachments, skipping out early.') + return False + + response = requests.get(self.att_url.format( + self.json['Id']), auth=self.auth,verify=self.verify) + log.info('response from O365 for retriving message attachments: %s', str(response)) + json = response.json() + + for att in json['value']: + try: + self.attachments.append(Attachment(att)) + log.debug('successfully downloaded attachment for: %s.', self.auth[0]) + except Exception as e: + log.info('failed to download attachment for: %s', self.auth[0]) + + return len(self.attachments) + + def sendMessage(self): + '''takes local variabls and forms them into a message to be sent.''' + + headers = {'Content-type': 'application/json', 'Accept': 'text/plain'} + + try: + data = {'Message': {'Body': {}}} + data['Message']['Subject'] = self.json['Subject'] + data['Message']['Body']['Content'] = self.json['Body']['Content'] + data['Message']['Body']['ContentType'] = self.json['Body']['ContentType'] + data['Message']['ToRecipients'] = self.json['ToRecipients'] + data['Message']['CcRecipients'] = self.json['CcRecipients'] + data['Message']['BccRecipients'] = self.json['BccRecipients'] + data['Message']['Attachments'] = [att.json for att in self.attachments] + data = json.dumps(data) + except Exception as e: + log.error( + 'Error while trying to compile the json string to send: {0}'.format(str(e))) + return False + + response = requests.post( + self.send_url, data, headers=headers, auth=self.auth,verify=self.verify) + log.debug('response from server for sending message:' + str(response)) + log.debug("respnse body: {}".format(response.text)) + if response.status_code != 202: + return False + + return True + + def markAsRead(self): + '''marks analogous message as read in the cloud.''' + read = '{"IsRead":true}' + headers = {'Content-type': 'application/json', 'Accept': 'application/json'} + try: + response = requests.patch(self.update_url.format( + self.json['Id']), read, headers=headers, auth=self.auth,verify=self.verify) + except: + return False + return True + + def getSender(self): + '''get all available information for the sender of the email.''' + return self.json['Sender'] + + def getSenderEmail(self): + '''get the email address of the sender.''' + return self.json['Sender']['EmailAddress']['Address'] + + def getSenderName(self): + '''try to get the name of the sender.''' + try: + return self.json['Sender']['EmailAddress']['Name'] + except: + return '' + + def getSubject(self): + '''get email subject line.''' + return self.json['Subject'] + + def getBody(self): + '''get email body.''' + return self.json['Body']['Content'] + + def setRecipients(self, val, r_type="To"): + ''' + set the recipient 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: + {"EmailAddress":{"Address":"recipient@example.com"}} + with other options such ass "Name" with address. but at minimum + it must have this. + a list: this must to be a list of libraries formatted the way + specified above, or it can be a list of dictionary objects of + type Contact or it can be an email address as string. The + method will sort out the libraries from the contacts. + a string: this is if you just want to throw an email address. + a contact: type Contact from this dictionary. + a group: type Group, which is a list of contacts. + For each of these argument types the appropriate action will be taken + to fit them to the needs of the library. + ''' + log.debug("Entered SET_RECIPIENTS function with type: {}".format(r_type)) + self.json[r_type + 'Recipients'] = [] + + if isinstance(val, list): + for con in val: + if isinstance(con, Contact): + self.addRecipient(con, r_type=r_type) + elif isinstance(con, str): + if '@' in con: + self.addRecipient(con, r_type=r_type) + elif isinstance(con, dict): + self.json[r_type + 'Recipients'].append(con) + elif isinstance(val, dict): + self.json[r_type + 'Recipients'] = [val] + elif isinstance(val, str): + if '@' in val: + self.addRecipient(val, r_type=r_type) + elif isinstance(val, Contact): + self.addRecipient(val, r_type=r_type) + elif isinstance(val, Group): + for person in val: + self.addRecipient(person, r_type=r_type) + else: + return False + return True + + def addRecipient(self, address, name=None, r_type="To"): + ''' + Adds a recipient to the recipients list. + + Arguments: + address -- the email address of the person you are sending to. <<< Important that. + 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[r_type + 'Recipients'].append(address.getFirstEmailAddress()) + elif isinstance(address, Group): + for con in address.contacts: + self.json[r_type + 'Recipients'].append(address.getFirstEmailAddress()) + else: + if name is None: + name = address[:address.index('@')] + self.json[r_type + 'Recipients'].append( + {'EmailAddress': {'Address': address, 'Name': name}}) + + def setSubject(self, val): + '''Sets the subect line of the email.''' + self.json['Subject'] = val + + def setBody(self, val): + '''Sets the body content of the email.''' + cont = False + + while not cont: + try: + self.json['Body']['Content'] = val + self.json['Body']['ContentType'] = 'Text' + cont = True + except: + self.json['Body'] = {} + + def setBodyHTML(self, val=None): + ''' + Sets the body content type to HTML for your pretty emails. + + arguments: + val -- Default: None. The content of the body you want set. If you don't pass a + value it is just ignored. + ''' + cont = False + + while not cont: + try: + self.json['Body']['ContentType'] = 'HTML' + if val: + self.json['Body']['Content'] = val + cont = True + except: + self.json['Body'] = {} + +# To the King! diff --git a/O365/schedule.py b/O365/schedule.py index 522796300dbdf..18e7caaf4b3eb 100644 --- a/O365/schedule.py +++ b/O365/schedule.py @@ -18,17 +18,19 @@ class Schedule( object ): ''' cal_url = 'https://outlook.office365.com/api/v1.0/me/calendars' - def __init__(self, auth): + def __init__(self, auth, verify=True): '''Creates a Schedule class for managing all calendars associated with email+password.''' log.debug('setting up for the schedule of the email %s',auth[0]) self.auth = auth self.calendars = [] + self.verify = verify + def getCalendars(self): '''Begin the process of downloading calendar metadata.''' log.debug('fetching calendars.') - response = requests.get(self.cal_url,auth=self.auth) + response = requests.get(self.cal_url,auth=self.auth,verify=self.verify) log.info('Response from O365: %s', str(response)) for calendar in response.json()['value']: diff --git a/setup.py b/setup.py index f6833587c9676..1ef58af4cc505 100644 --- a/setup.py +++ b/setup.py @@ -33,7 +33,7 @@ https://github.com/Narcolapser/python-o365''' setup(name='O365', - version='0.9.5', + version='0.9.6', description='Python library for working with Microsoft Office 365', long_description=long_desc, author='Toben Archer',