Skip to content

Commit

Permalink
providers.py: Added new date property
Browse files Browse the repository at this point in the history
  • Loading branch information
cubicbyte committed Aug 7, 2023
1 parent 501f407 commit 0b7436d
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions tempmail/providers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import time
import random
from datetime import datetime
from dataclasses import dataclass

import requests
Expand Down Expand Up @@ -80,6 +81,10 @@ class MessageInfo:
date_str: str
_mail: 'OneSecMail'

@property
def date(self) -> datetime:
return datetime.fromisoformat(self.date_str)

@property
def message(self) -> 'OneSecMail.Message':
return self._mail.get_message(self.id)
Expand All @@ -99,13 +104,21 @@ class Message:
id: int
from_addr: str
subject: str
date: str
date_str: str
body: str
test_body: str
html_body: str
_mail: 'OneSecMail'
_attachments: list[dict[str, any]]

@property
def date(self) -> datetime:
return datetime.fromisoformat(self.date_str)

@property
def attachments(self) -> list['OneSecMail.Attachment']:
return [OneSecMail.Attachment.from_dict(self._mail, self.id, attachment) for attachment in self._attachments]

@classmethod
def from_dict(cls, mail: 'OneSecMail', msg: dict[str, any]) -> 'OneSecMail.Message':
return cls(
Expand All @@ -114,16 +127,12 @@ def from_dict(cls, mail: 'OneSecMail', msg: dict[str, any]) -> 'OneSecMail.Messa
id=msg['id'],
from_addr=msg['from'],
subject=msg['subject'],
date=msg['date'],
date_str=msg['date'],
body=msg['textBody'],
test_body=msg['textBody'],
html_body=msg['htmlBody'],
)

@property
def attachments(self) -> list['OneSecMail.Attachment']:
return [OneSecMail.Attachment.from_dict(self._mail, self.id, attachment) for attachment in self._attachments]

@dataclass
class Attachment:
filename: str
Expand Down

0 comments on commit 0b7436d

Please sign in to comment.