ITK-dev-shared-components 2.17.4__tar.gz → 2.18.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {itk_dev_shared_components-2.17.4 → itk_dev_shared_components-2.18.0}/PKG-INFO +1 -1
- {itk_dev_shared_components-2.17.4 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/graph/mail.py +72 -41
- {itk_dev_shared_components-2.17.4 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components.egg-info/PKG-INFO +1 -1
- {itk_dev_shared_components-2.17.4 → itk_dev_shared_components-2.18.0}/pyproject.toml +1 -1
- {itk_dev_shared_components-2.17.4 → itk_dev_shared_components-2.18.0}/LICENSE +0 -0
- {itk_dev_shared_components-2.17.4 → itk_dev_shared_components-2.18.0}/README.md +0 -0
- {itk_dev_shared_components-2.17.4 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/__init__.py +0 -0
- {itk_dev_shared_components-2.17.4 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/boliglaan/__init__.py +0 -0
- {itk_dev_shared_components-2.17.4 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/boliglaan/common.py +0 -0
- {itk_dev_shared_components-2.17.4 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/boliglaan/login.py +0 -0
- {itk_dev_shared_components-2.17.4 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/boliglaan/search/__init__.py +0 -0
- {itk_dev_shared_components-2.17.4 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/boliglaan/search/search_advis.py +0 -0
- {itk_dev_shared_components-2.17.4 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/eflyt/__init__.py +0 -0
- {itk_dev_shared_components-2.17.4 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/eflyt/eflyt_case.py +0 -0
- {itk_dev_shared_components-2.17.4 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/eflyt/eflyt_letter.py +0 -0
- {itk_dev_shared_components-2.17.4 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/eflyt/eflyt_login.py +0 -0
- {itk_dev_shared_components-2.17.4 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/eflyt/eflyt_search.py +0 -0
- {itk_dev_shared_components-2.17.4 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/eflyt/eflyt_util.py +0 -0
- {itk_dev_shared_components-2.17.4 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/getorganized/__init__.py +0 -0
- {itk_dev_shared_components-2.17.4 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/getorganized/go_api.py +0 -0
- {itk_dev_shared_components-2.17.4 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/graph/__init__.py +0 -0
- {itk_dev_shared_components-2.17.4 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/graph/authentication.py +0 -0
- {itk_dev_shared_components-2.17.4 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/graph/common.py +0 -0
- {itk_dev_shared_components-2.17.4 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/graph/file.py +0 -0
- {itk_dev_shared_components-2.17.4 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/graph/site.py +0 -0
- {itk_dev_shared_components-2.17.4 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/kmd_nova/__init__.py +0 -0
- {itk_dev_shared_components-2.17.4 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/kmd_nova/authentication.py +0 -0
- {itk_dev_shared_components-2.17.4 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/kmd_nova/cpr.py +0 -0
- {itk_dev_shared_components-2.17.4 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/kmd_nova/nova_cases.py +0 -0
- {itk_dev_shared_components-2.17.4 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/kmd_nova/nova_documents.py +0 -0
- {itk_dev_shared_components-2.17.4 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/kmd_nova/nova_notes.py +0 -0
- {itk_dev_shared_components-2.17.4 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/kmd_nova/nova_objects.py +0 -0
- {itk_dev_shared_components-2.17.4 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/kmd_nova/nova_tasks.py +0 -0
- {itk_dev_shared_components-2.17.4 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/kmd_nova/util.py +0 -0
- {itk_dev_shared_components-2.17.4 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/misc/__init__.py +0 -0
- {itk_dev_shared_components-2.17.4 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/misc/address_lookup.py +0 -0
- {itk_dev_shared_components-2.17.4 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/misc/cpr_util.py +0 -0
- {itk_dev_shared_components-2.17.4 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/misc/cvr_lookup.py +0 -0
- {itk_dev_shared_components-2.17.4 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/misc/file_util.py +0 -0
- {itk_dev_shared_components-2.17.4 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/sap/__init__.py +0 -0
- {itk_dev_shared_components-2.17.4 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/sap/fmcacov.py +0 -0
- {itk_dev_shared_components-2.17.4 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/sap/gridview_util.py +0 -0
- {itk_dev_shared_components-2.17.4 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/sap/multi_session.py +0 -0
- {itk_dev_shared_components-2.17.4 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/sap/opret_kundekontakt.py +0 -0
- {itk_dev_shared_components-2.17.4 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/sap/sap_login.py +0 -0
- {itk_dev_shared_components-2.17.4 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/sap/sap_util.py +0 -0
- {itk_dev_shared_components-2.17.4 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/sap/tree_util.py +0 -0
- {itk_dev_shared_components-2.17.4 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/smtp/__init__.py +0 -0
- {itk_dev_shared_components-2.17.4 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/smtp/smtp_util.py +0 -0
- {itk_dev_shared_components-2.17.4 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components.egg-info/SOURCES.txt +0 -0
- {itk_dev_shared_components-2.17.4 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components.egg-info/dependency_links.txt +0 -0
- {itk_dev_shared_components-2.17.4 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components.egg-info/requires.txt +0 -0
- {itk_dev_shared_components-2.17.4 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components.egg-info/top_level.txt +0 -0
- {itk_dev_shared_components-2.17.4 → itk_dev_shared_components-2.18.0}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: itk_dev_shared_components
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.18.0
|
|
4
4
|
Summary: Shared components to use in RPA projects
|
|
5
5
|
Author-email: ITK Development <itk-rpa@mkb.aarhus.dk>
|
|
6
6
|
Project-URL: Homepage, https://github.com/itk-dev-rpa/itk-dev-shared-components
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
from dataclasses import dataclass, field
|
|
4
4
|
import io
|
|
5
|
+
from typing import Generator
|
|
6
|
+
from urllib.parse import quote
|
|
5
7
|
|
|
6
8
|
import requests
|
|
7
9
|
from bs4 import BeautifulSoup
|
|
@@ -51,11 +53,14 @@ class Attachment:
|
|
|
51
53
|
size: int
|
|
52
54
|
|
|
53
55
|
|
|
54
|
-
def get_emails_from_folder(user: str, folder_path: str, graph_access: GraphAccess, limit: int = 100) -> tuple[Email]:
|
|
56
|
+
def get_emails_from_folder(user: str, folder_path: str, graph_access: GraphAccess, limit: int | None = 100) -> tuple[Email] | Generator[Email, None, None]:
|
|
55
57
|
"""Get all emails from the specified user and folder.
|
|
56
58
|
You need to authorize against Graph to get the GraphAccess before using this function
|
|
57
59
|
see the graph.authentication module.
|
|
58
60
|
|
|
61
|
+
If limit is an integer a tuple of the first <limit> emails is returned.
|
|
62
|
+
If limit is None a generator over all emails in the folder is returned instead.
|
|
63
|
+
|
|
59
64
|
Args:
|
|
60
65
|
user: The user who owns the folder.
|
|
61
66
|
folder_path: The absolute path of the folder e.g. 'Inbox/Economy/May'
|
|
@@ -65,17 +70,58 @@ def get_emails_from_folder(user: str, folder_path: str, graph_access: GraphAcces
|
|
|
65
70
|
Returns:
|
|
66
71
|
tuple[Email]: The emails from the given folder.
|
|
67
72
|
"""
|
|
68
|
-
|
|
73
|
+
selectors = ",".join(("body", "from", "hasAttachments", "id", "receivedDateTime", "subject", "toRecipients"))
|
|
74
|
+
|
|
75
|
+
tuple_mode = isinstance(limit, int)
|
|
76
|
+
|
|
77
|
+
if tuple_mode and not 0 < limit <= 1000:
|
|
69
78
|
raise ValueError("Limit must be between 1 and 1000.")
|
|
70
79
|
|
|
71
80
|
folder_id = get_folder_id_from_path(user, folder_path, graph_access)
|
|
72
81
|
|
|
73
|
-
endpoint = f"https://graph.microsoft.com/v1.0/users/{user}/mailFolders/{folder_id}/messages?$
|
|
82
|
+
endpoint = f"https://graph.microsoft.com/v1.0/users/{user}/mailFolders/{folder_id}/messages?$select={selectors}"
|
|
74
83
|
|
|
75
|
-
|
|
76
|
-
|
|
84
|
+
# --- Tuple mode ---
|
|
85
|
+
if tuple_mode:
|
|
86
|
+
endpoint += f"&$top={limit}"
|
|
87
|
+
emails, _ = _get_emails(endpoint, user, graph_access)
|
|
88
|
+
return emails
|
|
89
|
+
|
|
90
|
+
# --- Generator mode ---
|
|
91
|
+
return _iterate_emails(endpoint, user, graph_access)
|
|
77
92
|
|
|
78
|
-
|
|
93
|
+
|
|
94
|
+
def _iterate_emails(endpoint: str, user: str, graph_access: GraphAccess) -> Generator[Email, None, None]:
|
|
95
|
+
"""Yield all emails from the given endpoint, following pagination until exhausted.
|
|
96
|
+
|
|
97
|
+
Args:
|
|
98
|
+
endpoint: The endpoint to get the first page of emails from.
|
|
99
|
+
user: The user who owns the emails.
|
|
100
|
+
graph_access: The GraphAccess object used to authenticate.
|
|
101
|
+
|
|
102
|
+
Yields:
|
|
103
|
+
Email: The emails from the endpoint, one page at a time.
|
|
104
|
+
"""
|
|
105
|
+
while endpoint is not None:
|
|
106
|
+
emails, endpoint = _get_emails(endpoint, user, graph_access)
|
|
107
|
+
yield from emails
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def _get_emails(endpoint: str, user: str, graph_access: GraphAccess) -> tuple[tuple[Email], str | None]:
|
|
111
|
+
"""A helper function to get a tuple of emails from the given endpoint.
|
|
112
|
+
|
|
113
|
+
Args:
|
|
114
|
+
endpoint: The endpoint to get from.
|
|
115
|
+
user: The user who owns the emails.
|
|
116
|
+
graph_access: The GraphAccess object used to authenticate.
|
|
117
|
+
|
|
118
|
+
Returns:
|
|
119
|
+
A tuple of emails and a next-page endpoint if any.
|
|
120
|
+
"""
|
|
121
|
+
response = get_request(endpoint, graph_access)
|
|
122
|
+
response_json = response.json()
|
|
123
|
+
emails_raw = response_json['value']
|
|
124
|
+
return _unpack_email_response(user, emails_raw), response_json.get("@odata.nextLink")
|
|
79
125
|
|
|
80
126
|
|
|
81
127
|
def get_email_as_mime(email: Email, graph_access: GraphAccess) -> io.BytesIO:
|
|
@@ -114,43 +160,44 @@ def get_folder_id_from_path(user: str, folder_path: str, graph_access: GraphAcce
|
|
|
114
160
|
main_folder = folders[0]
|
|
115
161
|
child_folders = folders[1:]
|
|
116
162
|
|
|
117
|
-
folder_id = None
|
|
118
|
-
|
|
119
163
|
# Get main folder
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
folder_id = _find_folder(response, main_folder)
|
|
164
|
+
base_endpoint = f"https://graph.microsoft.com/v1.0/users/{user}/mailFolders"
|
|
165
|
+
folder_id = _find_folder_by_name(base_endpoint, graph_access, main_folder)
|
|
123
166
|
if folder_id is None:
|
|
124
167
|
raise ValueError(f"Top level folder '{main_folder}' was not found for user '{user}'.")
|
|
125
168
|
|
|
126
169
|
# Get child folders
|
|
127
170
|
for child_folder in child_folders:
|
|
128
|
-
|
|
129
|
-
folder_id =
|
|
171
|
+
base_endpoint = f"https://graph.microsoft.com/v1.0/users/{user}/mailFolders/{folder_id}/childFolders"
|
|
172
|
+
folder_id = _find_folder_by_name(base_endpoint, graph_access, child_folder)
|
|
130
173
|
if folder_id is None:
|
|
131
174
|
raise ValueError(f"Child folder '{child_folder}' not found under '{main_folder}' for user '{user}'.")
|
|
132
175
|
|
|
133
176
|
return folder_id
|
|
134
177
|
|
|
135
178
|
|
|
136
|
-
def
|
|
137
|
-
"""
|
|
179
|
+
def _find_folder_by_name(base_endpoint: str, graph_access: GraphAccess, target_folder: str) -> str | None:
|
|
180
|
+
"""Find a mail folder by its display name using a server-side $filter.
|
|
181
|
+
|
|
182
|
+
Using $filter lets Graph return only the matching folder(s), so no client-side
|
|
183
|
+
pagination is needed. Note that Graph's 'eq' on displayName is case-insensitive.
|
|
138
184
|
|
|
139
185
|
Args:
|
|
140
|
-
|
|
141
|
-
graph_access:
|
|
142
|
-
target_folder:
|
|
186
|
+
base_endpoint: The mailFolders or childFolders endpoint to search under.
|
|
187
|
+
graph_access: The GraphAccess object used to authenticate.
|
|
188
|
+
target_folder: The display name of the folder to find.
|
|
143
189
|
|
|
144
190
|
Returns:
|
|
145
|
-
|
|
191
|
+
The id of the folder, or None if no folder with that name exists.
|
|
146
192
|
"""
|
|
147
|
-
|
|
148
|
-
|
|
193
|
+
# Escape single quotes for OData by doubling them, then url-encode the whole expression.
|
|
194
|
+
filter_value = target_folder.replace("'", "''")
|
|
195
|
+
query = quote(f"displayName eq '{filter_value}'")
|
|
196
|
+
endpoint = f"{base_endpoint}?$filter={query}"
|
|
149
197
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
return folder_id
|
|
198
|
+
response = get_request(endpoint, graph_access).json()
|
|
199
|
+
folders = response['value']
|
|
200
|
+
return folders[0]['id'] if folders else None
|
|
154
201
|
|
|
155
202
|
|
|
156
203
|
def list_email_attachments(email: Email, graph_access: GraphAccess) -> tuple[Attachment]:
|
|
@@ -258,22 +305,6 @@ def delete_email(email: Email, graph_access: GraphAccess, *, permanent: bool = F
|
|
|
258
305
|
move_email(email, "deleteditems", graph_access, well_known_folder=True)
|
|
259
306
|
|
|
260
307
|
|
|
261
|
-
def _find_folder(response: dict, target_folder: str) -> str:
|
|
262
|
-
"""Find the target folder in
|
|
263
|
-
|
|
264
|
-
Args:
|
|
265
|
-
response: The json dict of the HTTP response.
|
|
266
|
-
target_folder: The folder to find.
|
|
267
|
-
|
|
268
|
-
Returns:
|
|
269
|
-
str: The id of the target folder.
|
|
270
|
-
"""
|
|
271
|
-
for g_folder in response['value']:
|
|
272
|
-
if g_folder['displayName'] == target_folder:
|
|
273
|
-
return g_folder['id']
|
|
274
|
-
return None
|
|
275
|
-
|
|
276
|
-
|
|
277
308
|
def _unpack_email_response(user: str, emails_raw: list[dict[str, str]]) -> tuple[Email]:
|
|
278
309
|
"""Unpack a json HTTP response and create a list of Email objects.
|
|
279
310
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: itk_dev_shared_components
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.18.0
|
|
4
4
|
Summary: Shared components to use in RPA projects
|
|
5
5
|
Author-email: ITK Development <itk-rpa@mkb.aarhus.dk>
|
|
6
6
|
Project-URL: Homepage, https://github.com/itk-dev-rpa/itk-dev-shared-components
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|