aboutsummaryrefslogtreecommitdiff
path: root/sjdbmk/common.py
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--sjdbmk/common.py5
1 files changed, 5 insertions, 0 deletions
diff --git a/sjdbmk/common.py b/sjdbmk/common.py
index d65b3d5..1d315cc 100644
--- a/sjdbmk/common.py
+++ b/sjdbmk/common.py
@@ -26,6 +26,7 @@ import shutil
import requests
import msal # type: ignore
+
def acquire_token(
graph_client_id: str,
graph_authority: str,
@@ -44,6 +45,7 @@ def acquire_token(
return result["access_token"]
raise ValueError("Authentication error in password login")
+
def search_mail(token: str, query_string: str) -> list[dict[str, Any]]:
hits = requests.post(
"https://graph.microsoft.com/v1.0/search/query",
@@ -69,6 +71,7 @@ def search_mail(token: str, query_string: str) -> list[dict[str, Any]]:
assert isinstance(hits[0], dict)
return hits
+
def encode_sharing_url(url: str) -> str:
return "u!" + base64.urlsafe_b64encode(url.encode("utf-8")).decode("ascii").rstrip("=")
@@ -94,6 +97,7 @@ def download_share_url(token: str, url: str, local_filename: str, chunk_size: in
shutil.copyfileobj(r.raw, fd)
fd.flush()
+
def filter_mail_results_by_sender(original: Iterable[dict[str, Any]], sender: str) -> Iterator[dict[str, Any]]:
for hit in original:
if hit["resource"]["sender"]["emailAddress"]["address"].lower() == sender.lower():
@@ -112,5 +116,6 @@ def filter_mail_results_by_subject_regex_groups(
if matched:
yield (hit, [matched.group(group) for group in subject_regex_groups])
+
class DailyBulletinError(Exception):
pass