示例#1
0
	def getMessages(self):
		'''
		Downloads messages to local memory.
		
		You create an inbox to be the container class for messages, this method
		then pulls those messages down to the local disk. This is called in the
		init method, so it's kind of pointless for you. Unless you think new
		messages have come in.

		You can filter only certain emails by setting filters. See the set and
		get filters methods for more information.
		'''

		log.debug('fetching messages.')			
		response = requests.get(self.inbox_url,auth=self.auth,params={'$filter':self.filters})
		log.info('Response from O365: %s', str(response))
		
		for message in response.json()['value']:
			try:
				duplicate = False
				for i,m in enumerate(self.messages):
					if message['Id'] == m.json['Id']:
						self.messages[i] = Message(message,self.auth)
						duplicate = True
						break
				
				if not duplicate:
					self.messages.append(Message(message,self.auth))

				log.debug('appended message: %s',message['Subject'])
			except Exception as e:
				log.info('failed to append message: %',str(e))

		log.debug('all messages retrieved and put in to the list.')
		return True
示例#2
0
    def getMessages(self, number=10):
        '''
		Downloads messages to local memory.
		
		You create an inbox to be the container class for messages, this method
		then pulls those messages down to the local disk. This is called in the
		init method, so it's kind of pointless for you. Unless you think new
		messages have come in.

		You can filter only certain emails by setting filters. See the set and
		get filters methods for more information.

				Returns true if there are messages. Returns false if there were no 
				messages available that matched the filters specified. 
		'''

        log.debug('fetching messages.')
        response = requests.get(self.inbox_url,
                                auth=self.auth,
                                params={
                                    '$orderby': self.order_by,
                                    '$filter': self.filters,
                                    '$top': number
                                },
                                verify=self.verify)
        if response.status_code in [400, 500]:
            self.errors = response.text
            return False
        elif response.status_code in [401]:
            self.errors = response.reason
            return False

        log.info('Response from O365: %s', str(response))

        #check that there are messages
        try:
            response.json()['value']
        except KeyError as e:
            log.debug('no messages')
            return False

        for message in response.json()['value']:
            try:
                duplicate = False
                for i, m in enumerate(self.messages):
                    if message['Id'] == m.json['Id']:
                        self.messages[i] = Message(message, self.auth)
                        duplicate = True
                        break

                if not duplicate:
                    self.messages.append(Message(message, self.auth))

                log.debug('appended message: %s', message['Subject'])
            except Exception as e:
                log.info('failed to append message: %', str(e))

        log.debug('all messages retrieved and put in to the list.')
        return True
示例#3
0
    def getMail(self, mail_id):
        log.debug('fetching mail %s .' % mail_id)
        response = requests.get("%s('%s')" % (self.inbox_url, mail_id),
                                auth=self.auth)
        log.info('Response from O365: %s', str(response))

        return Message(response.json(), self.auth)
示例#4
0
    def new_message(self, resource=None):
        """ Creates a new message to be sent or stored

        :param str resource: Custom resource to be used in this message
         (Defaults to parent main_resource)
        :return: New empty message
        :rtype: Message
        """
        return Message(parent=self, main_resource=resource, is_draft=True)
示例#5
0
 def new_message(self, resource=None):
     """
     Creates a new message to be send or stored
     :param resource: Custom resource to be used in this message. defaults to parent main_resource.
     """
     return Message(parent=self, main_resource=resource, is_draft=True)