Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'mark message as seen' #12

Merged
merged 4 commits into from
Aug 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions pymailtm/pymailtm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -111,6 +124,7 @@ class Message:
intro: str
text: str
html: str
seen: bool
data: Dict

def open_web(self):
Expand Down Expand Up @@ -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."""

Expand Down
Loading