2
2
import random
3
3
from datetime import datetime
4
4
from dataclasses import dataclass
5
+ from typing import Optional , List , Tuple , Dict
5
6
6
7
import requests
7
8
@@ -16,7 +17,7 @@ class OneSecMail:
16
17
inbox_update_interval = 0.5
17
18
"""How often to update the inbox in seconds"""
18
19
19
- def __init__ (self , address : str | None = None , username : str | None = None , domain : str | None = None ) -> None :
20
+ def __init__ (self , address : Optional [ str ] = None , username : Optional [ str ] = None , domain : Optional [ str ] = None ) -> None :
20
21
"""Create a new 1secmail.com email address
21
22
22
23
:param address: The full email address (username@domain)
@@ -36,7 +37,7 @@ def __init__(self, address: str | None = None, username: str | None = None, doma
36
37
self .domain = domain or random .choice (self .get_domains ())
37
38
"""The domain of the email address (after the @)"""
38
39
39
- def get_inbox (self ) -> list ['OneSecMail.MessageInfo' ]:
40
+ def get_inbox (self ) -> List ['OneSecMail.MessageInfo' ]:
40
41
"""Get the inbox of the email address"""
41
42
resp = self ._session .get (f'https://www.1secmail.com/api/v1/?action=getMessages&login={ self .username } &domain={ self .domain } ' )
42
43
resp .raise_for_status ()
@@ -56,7 +57,7 @@ def download_attachment(self, id: int, file: str) -> bytes:
56
57
resp .raise_for_status ()
57
58
return resp .content
58
59
59
- def wait_for_message (self , timeout : int | None = 60 , filter : callable = lambda _ : True ) -> 'OneSecMail.Message' :
60
+ def wait_for_message (self , timeout : Optional [ int ] = 60 , filter : callable = lambda _ : True ) -> 'OneSecMail.Message' :
60
61
"""Wait for a message to arrive in the inbox
61
62
62
63
:param timeout: How long to wait for a message to arrive, in seconds
@@ -76,7 +77,7 @@ def wait_for_message(self, timeout: int | None = 60, filter: callable = lambda _
76
77
77
78
@staticmethod
78
79
@utils .cache
79
- def get_domains () -> tuple [str , ...]:
80
+ def get_domains () -> Tuple [str , ...]:
80
81
"""List of allowed email domains"""
81
82
resp = requests .get ('https://www.1secmail.com/api/v1/?action=getDomainList' )
82
83
resp .raise_for_status ()
@@ -118,7 +119,7 @@ def message(self) -> 'OneSecMail.Message':
118
119
return self ._mail_instance .get_message (self .id )
119
120
120
121
@classmethod
121
- def from_dict (cls , mail_instance : 'OneSecMail' , msg_info : dict [str , any ]) -> 'OneSecMail.MessageInfo' :
122
+ def from_dict (cls , mail_instance : 'OneSecMail' , msg_info : Dict [str , any ]) -> 'OneSecMail.MessageInfo' :
122
123
"""Create a MessageInfo from a raw api response"""
123
124
return cls (
124
125
_mail_instance = mail_instance ,
@@ -155,12 +156,12 @@ def date(self) -> datetime:
155
156
return datetime .fromisoformat (self .date_str )
156
157
157
158
@property
158
- def attachments (self ) -> list ['OneSecMail.Attachment' ]:
159
+ def attachments (self ) -> List ['OneSecMail.Attachment' ]:
159
160
"""List of attachments in the message (files)"""
160
161
return [OneSecMail .Attachment .from_dict (self ._mail_instance , self .id , attachment ) for attachment in self ._attachments ]
161
162
162
163
@classmethod
163
- def from_dict (cls , mail_instance : 'OneSecMail' , msg : dict [str , any ]) -> 'OneSecMail.Message' :
164
+ def from_dict (cls , mail_instance : 'OneSecMail' , msg : Dict [str , any ]) -> 'OneSecMail.Message' :
164
165
"""Create a Message from a raw api response"""
165
166
return cls (
166
167
_mail_instance = mail_instance ,
@@ -192,7 +193,7 @@ def download(self) -> bytes:
192
193
return self ._mail_instance .download_attachment (self ._message_id , self .filename )
193
194
194
195
@classmethod
195
- def from_dict (cls , mail_instance : 'OneSecMail' , message_id : int , attachment : dict [str , any ]) -> 'OneSecMail.Attachment' :
196
+ def from_dict (cls , mail_instance : 'OneSecMail' , message_id : int , attachment : Dict [str , any ]) -> 'OneSecMail.Attachment' :
196
197
"""Create an Attachment from a raw api response"""
197
198
return cls (
198
199
_mail_instance = mail_instance ,
0 commit comments