diff --git a/pymailtm/pymailtm.py b/pymailtm/pymailtm.py index 67b4d5e..0fcaed2 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 CouldNotGetUpdateMessageException(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): @@ -153,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."""