File size: 832 Bytes
0a367ef
4c83ab6
 
 
 
7da71bc
 
4c83ab6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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."
    )