aboutsummaryrefslogtreecommitdiff
path: root/sjdbmk/sendmail.py
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--[-rwxr-xr-x]sjdbmk/sendmail.py (renamed from sendmail.py)17
1 files changed, 11 insertions, 6 deletions
diff --git a/sendmail.py b/sjdbmk/sendmail.py
index c118c77..ddd6f32 100755..100644
--- a/sendmail.py
+++ b/sjdbmk/sendmail.py
@@ -30,6 +30,11 @@ import requests
import msal # type: ignore
+def open_and_readlines(filename: str) -> list[str]:
+ with open(filename, "r") as fd:
+ return fd.readlines()
+
+
def acquire_token(app: msal.PublicClientApplication, config: ConfigParser) -> str:
result = app.acquire_token_by_username_password(
config["credentials"]["username"],
@@ -96,9 +101,9 @@ def sendmail(
try:
msgid = response["id"]
- except KeyError:
+ except KeyError as exc:
pprint(response)
- raise ValueError("Unable to add email to drafts")
+ raise ValueError("Unable to add email to drafts") from exc
assert isinstance(msgid, str)
@@ -169,7 +174,7 @@ def main() -> None:
cc=config["sendmail"]["cc_1"].split(" "),
bcc=[
w.strip()
- for w in open(config["sendmail"]["bcc_1_file"], "r").readlines()
+ for w in open_and_readlines(config["sendmail"]["bcc_1_file"])
if w.strip()
],
when=date.replace(
@@ -193,7 +198,7 @@ def main() -> None:
cc=config["sendmail"]["cc_2"].split(" "),
bcc=[
w.strip()
- for w in open(config["sendmail"]["bcc_2_file"], "r").readlines()
+ for w in open_and_readlines(config["sendmail"]["bcc_2_file"])
if w.strip()
],
when=date.replace(
@@ -220,7 +225,7 @@ def main() -> None:
cc=config["sendmail"]["cc_1"].split(" "),
bcc=[
w.strip()
- for w in open(config["sendmail"]["bcc_1_file"], "r").readlines()
+ for w in open_and_readlines(config["sendmail"]["bcc_1_file"])
if w.strip()
],
when=date.replace(
@@ -247,7 +252,7 @@ def main() -> None:
cc=config["sendmail"]["cc_2"].split(" "),
bcc=[
w.strip()
- for w in open(config["sendmail"]["bcc_2_file"], "r").readlines()
+ for w in open_and_readlines(config["sendmail"]["bcc_2_file"])
if w.strip()
],
when=date.replace(