Spaces:
Sleeping
Sleeping
| from app.lib.graph.client import GraphClient | |
| _BASE = "https://graph.microsoft.com/v1.0" | |
| async def resolve_folder_id(client: GraphClient, display_name: str, mailbox_user: str) -> str: | |
| path = f"/users/{mailbox_user}/mailFolders" | |
| params: dict = {"$top": 100} | |
| while path: | |
| data = await client.get(path, params=params) | |
| for folder in data.get("value", []): | |
| if folder["displayName"].lower() == display_name.lower(): | |
| return folder["id"] | |
| next_link: str | None = data.get("@odata.nextLink") | |
| if next_link: | |
| path = next_link.removeprefix(_BASE) | |
| params = {} | |
| else: | |
| break | |
| raise ValueError( | |
| f"Mail folder '{display_name}' not found. " | |
| f"Verify it exists as a top-level folder in the monitored mailbox." | |
| ) | |