Skip to content

Commit 1eba227

Browse files
committed
add account_id, imap_error, graph_error
1 parent 7b31288 commit 1eba227

1 file changed

Lines changed: 32 additions & 17 deletions

File tree

bin/list-outlook-account-emails.py

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020

2121
AccountInfo = tuple[int, int | None, str]
22+
FolderResult = tuple[str, str]
2223
CsvRow = list[str]
2324

2425

@@ -27,46 +28,57 @@ def get_cluster() -> str:
2728
return "-".join(hostname.split("-")[:2])
2829

2930

30-
def get_imap_folder_names(account_id: int) -> str:
31+
def get_imap_folder_names(account_id: int) -> FolderResult:
3132
try:
3233
cp = connection_pool(account_id)
3334
with cp.get() as crispin_client:
3435
folders = crispin_client.folders()
3536

36-
return ",".join(
37-
sorted(folder.display_name for folder in folders)
37+
return (
38+
",".join(sorted(folder.display_name for folder in folders)),
39+
"",
3840
)
39-
except Exception:
40-
return ""
41+
except Exception as exc:
42+
return "", str(exc)
4143

4244

4345
def get_graph_folder_names(
4446
account_id: int, namespace_id: int | None
45-
) -> str:
47+
) -> FolderResult:
4648
if namespace_id is None:
47-
return ""
49+
return "", "missing namespace"
4850

4951
try:
5052
events_provider = MicrosoftEventsProvider(account_id, namespace_id)
51-
return ",".join(
52-
sorted(
53-
folder["displayName"]
54-
for folder in events_provider.client._iter(
55-
"/me/mailFolders"
53+
return (
54+
",".join(
55+
sorted(
56+
folder["displayName"]
57+
for folder in events_provider.client._iter(
58+
"/me/mailFolders"
59+
)
5660
)
57-
)
61+
),
62+
"",
5863
)
59-
except Exception:
60-
return ""
64+
except Exception as exc:
65+
return "", str(exc)
6166

6267

6368
def process_account(cluster: str, account_info: AccountInfo) -> CsvRow:
6469
account_id, namespace_id, email_address = account_info
70+
imap_folder_names, imap_error = get_imap_folder_names(account_id)
71+
graph_folder_names, graph_error = get_graph_folder_names(
72+
account_id, namespace_id
73+
)
6574
return [
6675
cluster,
76+
str(account_id),
6777
email_address,
68-
get_imap_folder_names(account_id),
69-
get_graph_folder_names(account_id, namespace_id),
78+
imap_folder_names,
79+
imap_error,
80+
graph_folder_names,
81+
graph_error,
7082
]
7183

7284

@@ -90,9 +102,12 @@ def main(concurrency: int) -> None:
90102
writer.writerow(
91103
[
92104
"cluster",
105+
"account_id",
93106
"email_address",
94107
"imap_folder_names",
108+
"imap_error",
95109
"graph_folder_names",
110+
"graph_error",
96111
]
97112
)
98113

0 commit comments

Comments
 (0)