Skip to content

Commit

Permalink
Merge pull request googleapis#124 from jasonlopez01/subfolder_fluency
Browse files Browse the repository at this point in the history
Improved subfolder navigation
  • Loading branch information
Narcolapser authored Sep 19, 2018
2 parents 586361c + 419f4fc commit a2141d8
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
5 changes: 4 additions & 1 deletion O365/fluent_inbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,14 @@ def __init__(self, verify=True):
:param verify: whether or not to verify SSL certificate
"""
self.url = FluentInbox._get_url('inbox')
self.folder = None
self.fetched_count = 0
self._filter = ''
self._search = ''
self.verify = verify
self.messages = []

def from_folder(self, folder_name, user_id=None):
def from_folder(self, folder_name, parent_id=None, user_id=None):
""" Configure to use this folder for fetching the mails
:param folder_name: name of the outlook folder
Expand All @@ -60,6 +61,7 @@ def from_folder(self, folder_name, user_id=None):

folder_id = self.get_folder(value=folder_name,
by='DisplayName',
parent_id=parent_id,
user_id=user_id)['Id']

if user_id:
Expand Down Expand Up @@ -111,6 +113,7 @@ def get_folder(self, value, by='Id', parent_id=None, user_id=None):

for folder in response:
if folder[by] == value:
self.folder = folder
return(folder)

all_folders.append(folder['displayName'])
Expand Down
29 changes: 29 additions & 0 deletions examples/FolderOperations/search_subfolders.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import getpass
from O365 import Connection, FluentInbox


def main():
username = input("Username: ")
password = getpass.getpass("Password: ")
authentication = (username, password)
Connection.login(*authentication)
inbox = FluentInbox()

# set inbox as current folder to use as parent, self.folder attribute
inbox.from_folder("Inbox")

# reset current folder as subfolder
inbox.from_folder("Subfolder", parent_id=inbox.folder["Id"])
for msg in inbox.search("Subject:Urgent").fetch_first(10):
print(msg.getSubject())

# reset current folder as a child folder of Subfolder
inbox.from_folder("Sub_subfolder", parent_id=inbox.folder["Id"])
for msg in inbox.fetech_first(10):
print(msg.getSubject())

return 0


if __name__ == "__main__":
main()

0 comments on commit a2141d8

Please sign in to comment.