ITK-dev-shared-components 2.17.2__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.2 → itk_dev_shared_components-2.18.0}/PKG-INFO +1 -1
- {itk_dev_shared_components-2.17.2 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/boliglaan/login.py +2 -2
- {itk_dev_shared_components-2.17.2 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/boliglaan/search/search_advis.py +23 -15
- {itk_dev_shared_components-2.17.2 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/eflyt/eflyt_case.py +36 -17
- {itk_dev_shared_components-2.17.2 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/graph/mail.py +72 -41
- {itk_dev_shared_components-2.17.2 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components.egg-info/PKG-INFO +1 -1
- {itk_dev_shared_components-2.17.2 → itk_dev_shared_components-2.18.0}/pyproject.toml +1 -1
- {itk_dev_shared_components-2.17.2 → itk_dev_shared_components-2.18.0}/LICENSE +0 -0
- {itk_dev_shared_components-2.17.2 → itk_dev_shared_components-2.18.0}/README.md +0 -0
- {itk_dev_shared_components-2.17.2 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/__init__.py +0 -0
- {itk_dev_shared_components-2.17.2 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/boliglaan/__init__.py +0 -0
- {itk_dev_shared_components-2.17.2 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/boliglaan/common.py +0 -0
- {itk_dev_shared_components-2.17.2 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/boliglaan/search/__init__.py +0 -0
- {itk_dev_shared_components-2.17.2 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/eflyt/__init__.py +0 -0
- {itk_dev_shared_components-2.17.2 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/eflyt/eflyt_letter.py +0 -0
- {itk_dev_shared_components-2.17.2 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/eflyt/eflyt_login.py +0 -0
- {itk_dev_shared_components-2.17.2 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/eflyt/eflyt_search.py +0 -0
- {itk_dev_shared_components-2.17.2 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/eflyt/eflyt_util.py +0 -0
- {itk_dev_shared_components-2.17.2 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/getorganized/__init__.py +0 -0
- {itk_dev_shared_components-2.17.2 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/getorganized/go_api.py +0 -0
- {itk_dev_shared_components-2.17.2 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/graph/__init__.py +0 -0
- {itk_dev_shared_components-2.17.2 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/graph/authentication.py +0 -0
- {itk_dev_shared_components-2.17.2 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/graph/common.py +0 -0
- {itk_dev_shared_components-2.17.2 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/graph/file.py +0 -0
- {itk_dev_shared_components-2.17.2 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/graph/site.py +0 -0
- {itk_dev_shared_components-2.17.2 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/kmd_nova/__init__.py +0 -0
- {itk_dev_shared_components-2.17.2 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/kmd_nova/authentication.py +0 -0
- {itk_dev_shared_components-2.17.2 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/kmd_nova/cpr.py +0 -0
- {itk_dev_shared_components-2.17.2 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/kmd_nova/nova_cases.py +0 -0
- {itk_dev_shared_components-2.17.2 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/kmd_nova/nova_documents.py +0 -0
- {itk_dev_shared_components-2.17.2 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/kmd_nova/nova_notes.py +0 -0
- {itk_dev_shared_components-2.17.2 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/kmd_nova/nova_objects.py +0 -0
- {itk_dev_shared_components-2.17.2 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/kmd_nova/nova_tasks.py +0 -0
- {itk_dev_shared_components-2.17.2 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/kmd_nova/util.py +0 -0
- {itk_dev_shared_components-2.17.2 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/misc/__init__.py +0 -0
- {itk_dev_shared_components-2.17.2 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/misc/address_lookup.py +0 -0
- {itk_dev_shared_components-2.17.2 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/misc/cpr_util.py +0 -0
- {itk_dev_shared_components-2.17.2 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/misc/cvr_lookup.py +0 -0
- {itk_dev_shared_components-2.17.2 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/misc/file_util.py +0 -0
- {itk_dev_shared_components-2.17.2 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/sap/__init__.py +0 -0
- {itk_dev_shared_components-2.17.2 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/sap/fmcacov.py +0 -0
- {itk_dev_shared_components-2.17.2 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/sap/gridview_util.py +0 -0
- {itk_dev_shared_components-2.17.2 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/sap/multi_session.py +0 -0
- {itk_dev_shared_components-2.17.2 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/sap/opret_kundekontakt.py +0 -0
- {itk_dev_shared_components-2.17.2 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/sap/sap_login.py +0 -0
- {itk_dev_shared_components-2.17.2 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/sap/sap_util.py +0 -0
- {itk_dev_shared_components-2.17.2 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/sap/tree_util.py +0 -0
- {itk_dev_shared_components-2.17.2 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/smtp/__init__.py +0 -0
- {itk_dev_shared_components-2.17.2 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components/smtp/smtp_util.py +0 -0
- {itk_dev_shared_components-2.17.2 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components.egg-info/SOURCES.txt +0 -0
- {itk_dev_shared_components-2.17.2 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components.egg-info/dependency_links.txt +0 -0
- {itk_dev_shared_components-2.17.2 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components.egg-info/requires.txt +0 -0
- {itk_dev_shared_components-2.17.2 → itk_dev_shared_components-2.18.0}/itk_dev_shared_components.egg-info/top_level.txt +0 -0
- {itk_dev_shared_components-2.17.2 → 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
|
|
@@ -27,8 +27,8 @@ def login(username: str, password: str):
|
|
|
27
27
|
kmd_logon.ButtonControl(AutomationId="UserPwLogonButton").GetInvokePattern().Invoke()
|
|
28
28
|
|
|
29
29
|
boliglaan = uiautomation.WindowControl(Name="KMD Boliglån", searchDepth=1)
|
|
30
|
-
if not boliglaan.Exists(maxSearchSeconds=
|
|
31
|
-
raise RuntimeError("Boliglån didn't appear within
|
|
30
|
+
if not boliglaan.Exists(maxSearchSeconds=60):
|
|
31
|
+
raise RuntimeError("Boliglån didn't appear within 60 seconds")
|
|
32
32
|
|
|
33
33
|
|
|
34
34
|
def kill_boliglaan():
|
|
@@ -4,7 +4,7 @@ and handling the advis search results.
|
|
|
4
4
|
|
|
5
5
|
from dataclasses import dataclass
|
|
6
6
|
from datetime import date
|
|
7
|
-
from typing import Literal
|
|
7
|
+
from typing import Any, Literal
|
|
8
8
|
|
|
9
9
|
import uiautomation
|
|
10
10
|
|
|
@@ -70,20 +70,21 @@ def search_advis(cpr: str | None = None, date_from: date | None = None, date_to:
|
|
|
70
70
|
for type_ in types:
|
|
71
71
|
popup.CheckBoxControl(Name=type_).GetTogglePattern().SetToggleState(1, waitTime=0)
|
|
72
72
|
|
|
73
|
-
popup.ButtonControl(Name="Søg").
|
|
73
|
+
popup.ButtonControl(Name="Søg").Click(simulateMove=False)
|
|
74
74
|
|
|
75
75
|
|
|
76
76
|
def select_advis(cpr: str, case_number: str):
|
|
77
77
|
"""Select the advis from the search list with the given cpr and case number."""
|
|
78
78
|
boliglaan = common.get_boliglaan()
|
|
79
|
-
|
|
79
|
+
grid = boliglaan.TabControl(Name="TabbedGroup", searchDepth=4).GroupControl(Name="Advis").DataGridControl(AutomationId="AdvisGridControl")
|
|
80
|
+
grid_pattern = grid.GetGridPattern()
|
|
80
81
|
|
|
81
|
-
for row in
|
|
82
|
-
row_case_number = row
|
|
83
|
-
case_cpr = row
|
|
82
|
+
for row in range(grid_pattern.RowCount):
|
|
83
|
+
row_case_number = _get_grid_value(grid_pattern, row, 1)
|
|
84
|
+
case_cpr = _get_grid_value(grid_pattern, row, 2)
|
|
84
85
|
|
|
85
86
|
if case_cpr == cpr and row_case_number == case_number:
|
|
86
|
-
row.DoubleClick(simulateMove=False)
|
|
87
|
+
grid_pattern.GetItem(row, 0).DoubleClick(simulateMove=False)
|
|
87
88
|
return
|
|
88
89
|
|
|
89
90
|
raise LookupError(f"Couldn't find advis: {cpr} - {case_number}")
|
|
@@ -92,17 +93,19 @@ def select_advis(cpr: str, case_number: str):
|
|
|
92
93
|
def get_advis_list() -> list[Advis]:
|
|
93
94
|
"""Get the advis search result as a list of Advis objects."""
|
|
94
95
|
boliglaan = common.get_boliglaan()
|
|
95
|
-
|
|
96
|
+
|
|
97
|
+
grid = boliglaan.TabControl(Name="TabbedGroup", searchDepth=4).GroupControl(Name="Advis").DataGridControl(AutomationId="AdvisGridControl")
|
|
98
|
+
grid_pattern = grid.GetGridPattern()
|
|
96
99
|
|
|
97
100
|
result = []
|
|
98
101
|
|
|
99
|
-
for row in
|
|
100
|
-
date_str: str = row
|
|
101
|
-
case_number = row
|
|
102
|
-
cpr = row
|
|
103
|
-
type_ = row
|
|
104
|
-
state = row
|
|
105
|
-
case_type = row
|
|
102
|
+
for row in range(grid_pattern.RowCount):
|
|
103
|
+
date_str: str = _get_grid_value(grid_pattern, row, 0)
|
|
104
|
+
case_number = _get_grid_value(grid_pattern, row, 1)
|
|
105
|
+
cpr = _get_grid_value(grid_pattern, row, 2)
|
|
106
|
+
type_ = _get_grid_value(grid_pattern, row, 3)
|
|
107
|
+
state = _get_grid_value(grid_pattern, row, 4)
|
|
108
|
+
case_type = _get_grid_value(grid_pattern, row, 6)
|
|
106
109
|
|
|
107
110
|
day, month, year = (int(part) for part in date_str.split("-"))
|
|
108
111
|
date_ = date(year, month, day)
|
|
@@ -110,3 +113,8 @@ def get_advis_list() -> list[Advis]:
|
|
|
110
113
|
result.append(Advis(date=date_, cpr=cpr, case_number=case_number, type=type_, state=state, case_type=case_type))
|
|
111
114
|
|
|
112
115
|
return result
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def _get_grid_value(grid_pattern: uiautomation.GridPattern, row: int, column: int) -> Any:
|
|
119
|
+
"""Helper function to get the value of a grid item."""
|
|
120
|
+
return grid_pattern.GetItem(row, column).GetPattern(uiautomation.PatternId.ValuePattern).Value
|
|
@@ -5,6 +5,11 @@ from datetime import date, datetime
|
|
|
5
5
|
from selenium import webdriver
|
|
6
6
|
from selenium.webdriver.common.by import By
|
|
7
7
|
from selenium.webdriver.common.keys import Keys
|
|
8
|
+
from selenium.webdriver.support.ui import WebDriverWait
|
|
9
|
+
from selenium.webdriver.support import expected_conditions as EC
|
|
10
|
+
from selenium.common.exceptions import TimeoutException
|
|
11
|
+
|
|
12
|
+
WAIT_TIMEOUT = 10 # Seconds to wait for ASP.NET postbacks in approve_case.
|
|
8
13
|
|
|
9
14
|
|
|
10
15
|
@dataclass
|
|
@@ -131,23 +136,34 @@ def change_tab(browser: webdriver.Chrome, tab_index: int):
|
|
|
131
136
|
|
|
132
137
|
|
|
133
138
|
def approve_case(browser: webdriver.Chrome):
|
|
134
|
-
"""Approve a case
|
|
135
|
-
|
|
139
|
+
"""Approve a case, including cases where the anmeldelse is already approved and only the
|
|
140
|
+
persons remain. Uses waits around the ASP.NET postbacks to avoid stale/not-interactable
|
|
141
|
+
races. If any person on the case is blocking approval, approve each person individually.
|
|
136
142
|
"""
|
|
137
143
|
change_tab(browser, 0)
|
|
138
144
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
145
|
+
browser.find_element(By.ID, "ctl00_ContentPlaceHolder2_ptFanePerson_ncPersonTab_txtDeadline").clear()
|
|
146
|
+
browser.find_element(By.ID, "ctl00_ContentPlaceHolder2_ptFanePerson_ncPersonTab_txtDeadlineNote").clear()
|
|
147
|
+
|
|
148
|
+
# 1. Approve the anmeldelse only if that step is available (skip if already approved).
|
|
149
|
+
godkend = browser.find_element(By.ID, "ctl00_ContentPlaceHolder2_ptFanePerson_stcPersonTab1_btnGodkend")
|
|
150
|
+
if godkend.is_enabled():
|
|
151
|
+
godkend.click()
|
|
152
|
+
# 2. Confirm OK only if the confirmation dialog actually appears.
|
|
153
|
+
try:
|
|
154
|
+
WebDriverWait(browser, WAIT_TIMEOUT).until(
|
|
155
|
+
EC.element_to_be_clickable((By.ID, "ctl00_ContentPlaceHolder2_ptFanePerson_stcPersonTab1_btnApproveYes"))
|
|
156
|
+
).click()
|
|
157
|
+
except TimeoutException:
|
|
158
|
+
pass
|
|
159
|
+
|
|
160
|
+
# 3. Approve the persons; clickability decides bulk vs per-person and waits out the
|
|
161
|
+
# postback (no is_enabled() on a stale element).
|
|
162
|
+
try:
|
|
163
|
+
WebDriverWait(browser, WAIT_TIMEOUT).until(
|
|
164
|
+
EC.element_to_be_clickable((By.ID, "ctl00_ContentPlaceHolder2_ptFanePerson_stcPersonTab1_btnGodkendAlle"))
|
|
165
|
+
).click()
|
|
166
|
+
except TimeoutException:
|
|
151
167
|
# Approve each person individually
|
|
152
168
|
person_count = len(browser.find_elements(By.XPATH, '//table[@id="ctl00_ContentPlaceHolder2_GridViewMovingPersons"]//tr')) - 1
|
|
153
169
|
|
|
@@ -155,9 +171,12 @@ def approve_case(browser: webdriver.Chrome):
|
|
|
155
171
|
browser.find_element(By.XPATH, f'//table[@id="ctl00_ContentPlaceHolder2_GridViewMovingPersons"]//tr[{i+2}]//td[2]').click()
|
|
156
172
|
|
|
157
173
|
browser.find_element(By.ID, "ctl00_ContentPlaceHolder2_ptFanePerson_stcPersonTab1_btnGodkend").click()
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
174
|
+
try:
|
|
175
|
+
WebDriverWait(browser, WAIT_TIMEOUT).until(
|
|
176
|
+
EC.element_to_be_clickable((By.ID, "ctl00_ContentPlaceHolder2_ptFanePerson_stcPersonTab1_btnApproveYes"))
|
|
177
|
+
).click()
|
|
178
|
+
except TimeoutException:
|
|
179
|
+
pass
|
|
161
180
|
|
|
162
181
|
# Go back to the case
|
|
163
182
|
browser.find_element(By.XPATH, '//table[@id="ctl00_ContentPlaceHolder2_GridViewMovingPersons"]//tr[1]//td[2]').click()
|
|
@@ -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
|