Skip to content

Commit

Permalink
Attempting ssl verification skipping.
Browse files Browse the repository at this point in the history
I've made an alteration to the library to allow for you to choose
to ignore ssl verification. This is in response to issue googleapis#60. I've
not really tested this though. My computer is not behaving but I
want to get this change pushed. So I'll push it now and try to get
my machine to behave later.
  • Loading branch information
Toben Archer authored and Toben Archer committed Sep 18, 2017
1 parent 619280f commit fdd824b
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 35 deletions.
18 changes: 9 additions & 9 deletions MANIFEST
Original file line number Diff line number Diff line change
@@ -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
6 changes: 4 additions & 2 deletions O365/attachment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions O365/cal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
'''
Expand All @@ -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']
Expand Down Expand Up @@ -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.
Expand Down
10 changes: 6 additions & 4 deletions O365/contact.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
'''
Expand All @@ -37,13 +37,15 @@ def __init__(self, json=None, auth=None):
else:
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
Expand All @@ -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:
Expand All @@ -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:
Expand Down
10 changes: 6 additions & 4 deletions O365/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -68,6 +68,8 @@ def __init__(self,json=None,auth=None,cal=None):
else:
self.json = {}

self.verify = verify


def create(self,calendar=None):
'''
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
10 changes: 6 additions & 4 deletions O365/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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']:
Expand Down
6 changes: 4 additions & 2 deletions O365/inbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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):
'''
Expand All @@ -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']:
Expand Down
13 changes: 8 additions & 5 deletions O365/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class Message(object):
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):
def __init__(self, json=None, auth=None, verify=True):
'''
Makes a new message wrapper for sending and recieving messages.
Expand All @@ -65,14 +65,17 @@ def __init__(self, json=None, auth=None):
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)
self.json['Id']), auth=self.auth,verify=self.verify)
log.info('response from O365 for retriving message attachments: %s', str(response))
json = response.json()

Expand Down Expand Up @@ -106,7 +109,7 @@ def sendMessage(self):
return False

response = requests.post(
self.send_url, data, headers=headers, auth=self.auth)
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:
Expand All @@ -120,7 +123,7 @@ def markAsRead(self):
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)
self.json['Id']), read, headers=headers, auth=self.auth,verify=self.verify)
except:
return False
return True
Expand Down Expand Up @@ -252,4 +255,4 @@ def setBodyHTML(self, val=None):
except:
self.json['Body'] = {}

# To the King!
# To the King!
6 changes: 4 additions & 2 deletions O365/schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit fdd824b

Please sign in to comment.