@@ -12,12 +12,10 @@ class FluentInbox(object):
12
12
'1.0' : 'https://outlook.office365.com/api/v1.0/me/messages' ,
13
13
'2.0' : 'https://graph.microsoft.com/v1.0/me/messages' ,
14
14
},
15
-
16
15
'folders' : {
17
16
'1.0' : 'https://outlook.office365.com/api/v1.0/me/Folders' ,
18
17
'2.0' : 'https://graph.microsoft.com/v1.0/me/MailFolders' ,
19
18
},
20
-
21
19
'folder' : {
22
20
'1.0' : 'https://outlook.office365.com/api/v1.0/me/Folders/{folder_id}/messages' ,
23
21
'2.0' : 'https://graph.microsoft.com/v1.0/me/MailFolders/{folder_id}/messages' ,
@@ -26,6 +24,14 @@ class FluentInbox(object):
26
24
'1.0' : 'https://outlook.office365.com/api/v1.0/me/Folders/{folder_id}/childfolders' ,
27
25
'2.0' : 'https://graph.microsoft.com/v1.0/me/MailFolders/{folder_id}/childfolders' ,
28
26
},
27
+ 'user_folders' : {
28
+ '1.0' : 'https://outlook.office365.com/api/v1.0/users/{user_id}/Folders' ,
29
+ '2.0' : 'https://graph.microsoft.com/v1.0/users/{user_id}/MailFolders' ,
30
+ },
31
+ 'user_folder' : {
32
+ '1.0' : 'https://outlook.office365.com/api/v1.0/users/{user_id}/Folders/{folder_id}/messages' ,
33
+ '2.0' : 'https://graph.microsoft.com/v1.0/users/{user_id}/MailFolders/{folder_id}/messages' ,
34
+ }
29
35
}
30
36
31
37
def __init__ (self , verify = True ):
@@ -40,35 +46,28 @@ def __init__(self, verify=True):
40
46
self .verify = verify
41
47
self .messages = []
42
48
43
- def from_folder (self , folder_name ):
49
+ def from_folder (self , folder_name , user_id = None ):
44
50
""" Configure to use this folder for fetching the mails
45
51
46
52
:param folder_name: name of the outlook folder
53
+ :param user_id: user id the folder belongs to (shared mailboxes)
47
54
"""
48
55
self ._reset ()
49
- response = Connection .get_response (FluentInbox ._get_url ('folders' ),
50
- verify = self .verify ,
51
- params = {'$top' : 100 })
52
-
53
- folder_id = None
54
- all_folders = []
55
-
56
- for folder in response :
57
- if folder ['displayName' ] == folder_name :
58
- folder_id = folder ['id' ]
59
- break
60
56
61
- all_folders .append (folder ['displayName' ])
57
+ folder_id = self .get_folder (value = folder_name ,
58
+ by = 'DisplayName' ,
59
+ user_id = user_id )['Id' ]
62
60
63
- if not folder_id :
64
- raise RuntimeError ('Folder "{}" is not found, available folders '
65
- 'are {}' .format (folder_name , all_folders ))
66
-
67
- self .url = FluentInbox ._get_url ('folder' ).format (folder_id = folder_id )
61
+ if user_id :
62
+ self .url = FluentInbox ._get_url ('user_folder' ).format (
63
+ user_id = user_id , folder_id = folder_id )
64
+ else :
65
+ self .url = FluentInbox ._get_url ('folder' ).format (
66
+ folder_id = folder_id )
68
67
69
68
return self
70
69
71
- def get_folder (self , value , by = 'Id' , parent_id = None ):
70
+ def get_folder (self , value , by = 'Id' , parent_id = None , user_id = None ):
72
71
"""
73
72
Return a folder by a given attribute. If multiple folders exist by
74
73
this attribute, only the first will be returned
@@ -84,11 +83,15 @@ def get_folder(self, value, by='Id', parent_id=None):
84
83
85
84
:param value: Value that we are searching for
86
85
:param by: Search on this key (default: Id)
86
+ :param user_id: user id the folder belongs to (shared mailboxes)
87
87
:returns: Single folder data
88
88
"""
89
89
if parent_id :
90
90
folders_url = FluentInbox ._get_url ('child_folders' ).format (
91
91
folder_id = parent_id )
92
+ elif user_id :
93
+ folders_url = FluentInbox ._get_url ('user_folders' ).format (
94
+ user_id = user_id )
92
95
else :
93
96
folders_url = FluentInbox ._get_url ('folders' )
94
97
@@ -110,14 +113,17 @@ def get_folder(self, value, by='Id', parent_id=None):
110
113
'Folder "{}" is not found by "{}", available folders '
111
114
'are {}' .format (value , by , all_folders ))
112
115
113
- def list_folders (self , parent_id = None ):
116
+ def list_folders (self , parent_id = None , user_id = None ):
114
117
"""
115
118
:param parent_id: Id of parent folder to list. Default to top folder
116
119
:return: List of all folder data
117
120
"""
118
121
if parent_id :
119
122
folders_url = FluentInbox ._get_url ('child_folders' ).format (
120
123
folder_id = parent_id )
124
+ elif user_id :
125
+ folders_url = FluentInbox ._get_url ('user_folders' ).format (
126
+ user_id = user_id )
121
127
else :
122
128
folders_url = FluentInbox ._get_url ('folders' )
123
129
0 commit comments