From 7606b6d1859b13eac29d66bb82803a5e0c8bbb7c Mon Sep 17 00:00:00 2001 From: SHELA Date: Tue, 27 Dec 2022 16:59:49 +0200 Subject: [PATCH 1/2] Update pymailtm.py mark as seen --- pymailtm/pymailtm.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/pymailtm/pymailtm.py b/pymailtm/pymailtm.py index 67b4d5e..18cf482 100644 --- a/pymailtm/pymailtm.py +++ b/pymailtm/pymailtm.py @@ -60,10 +60,23 @@ def get_messages(self, page=1): message_data["intro"], text, html, + message_data["seen"], message_data)) return messages + def mark_seen_message(self, message_id): + headers = self.auth_headers + headers["Content-Type"] = "application/ld+json"; + + r = requests.patch( + f"{self.api_address}/messages/{message_id}", headers=headers, + data=json.dumps({'seen': True})) + if r.status_code not in [200, 201]: + print(r.text) + raise CouldNotGetAccountException(f"HTTP {r.status_code}") + return r.json() + def delete_account(self): """Try to delete the account. Returns True if it succeeds.""" r = requests.delete("{}/accounts/{}".format(self.api_address, @@ -111,6 +124,7 @@ class Message: intro: str text: str html: str + seen: bool data: Dict def open_web(self): From 6461d37c8e93a662139297a452b82b582686e63d Mon Sep 17 00:00:00 2001 From: SHELA Date: Tue, 27 Dec 2022 17:01:03 +0200 Subject: [PATCH 2/2] Update pymailtm.py --- pymailtm/pymailtm.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pymailtm/pymailtm.py b/pymailtm/pymailtm.py index 18cf482..0fcaed2 100644 --- a/pymailtm/pymailtm.py +++ b/pymailtm/pymailtm.py @@ -74,7 +74,7 @@ def mark_seen_message(self, message_id): data=json.dumps({'seen': True})) if r.status_code not in [200, 201]: print(r.text) - raise CouldNotGetAccountException(f"HTTP {r.status_code}") + raise CouldNotGetUpdateMessageException(f"HTTP {r.status_code}") return r.json() def delete_account(self): @@ -167,6 +167,10 @@ class CouldNotGetMessagesException(Exception): """Raised if a GET on /messages returns with a failed status code.""" +class CouldNotGetUpdateMessageException(Exception): + """Raised if a PATCH on /messages returns with a failed status code.""" + + class CouldNotGetAccountException(Exception): """Raised if a POST on /accounts or /authorization_token returns with a failed status code."""