22import random
33from datetime import datetime
44from dataclasses import dataclass
5+ from typing import Optional , List , Tuple , Dict
56
67import requests
78
@@ -16,7 +17,7 @@ class OneSecMail:
1617 inbox_update_interval = 0.5
1718 """How often to update the inbox in seconds"""
1819
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 :
2021 """Create a new 1secmail.com email address
2122
2223 :param address: The full email address (username@domain)
@@ -36,7 +37,7 @@ def __init__(self, address: str | None = None, username: str | None = None, doma
3637 self .domain = domain or random .choice (self .get_domains ())
3738 """The domain of the email address (after the @)"""
3839
39- def get_inbox (self ) -> list ['OneSecMail.MessageInfo' ]:
40+ def get_inbox (self ) -> List ['OneSecMail.MessageInfo' ]:
4041 """Get the inbox of the email address"""
4142 resp = self ._session .get (f'https://www.1secmail.com/api/v1/?action=getMessages&login={ self .username } &domain={ self .domain } ' )
4243 resp .raise_for_status ()
@@ -56,7 +57,7 @@ def download_attachment(self, id: int, file: str) -> bytes:
5657 resp .raise_for_status ()
5758 return resp .content
5859
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' :
6061 """Wait for a message to arrive in the inbox
6162
6263 :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 _
7677
7778 @staticmethod
7879 @utils .cache
79- def get_domains () -> tuple [str , ...]:
80+ def get_domains () -> Tuple [str , ...]:
8081 """List of allowed email domains"""
8182 resp = requests .get ('https://www.1secmail.com/api/v1/?action=getDomainList' )
8283 resp .raise_for_status ()
@@ -118,7 +119,7 @@ def message(self) -> 'OneSecMail.Message':
118119 return self ._mail_instance .get_message (self .id )
119120
120121 @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' :
122123 """Create a MessageInfo from a raw api response"""
123124 return cls (
124125 _mail_instance = mail_instance ,
@@ -155,12 +156,12 @@ def date(self) -> datetime:
155156 return datetime .fromisoformat (self .date_str )
156157
157158 @property
158- def attachments (self ) -> list ['OneSecMail.Attachment' ]:
159+ def attachments (self ) -> List ['OneSecMail.Attachment' ]:
159160 """List of attachments in the message (files)"""
160161 return [OneSecMail .Attachment .from_dict (self ._mail_instance , self .id , attachment ) for attachment in self ._attachments ]
161162
162163 @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' :
164165 """Create a Message from a raw api response"""
165166 return cls (
166167 _mail_instance = mail_instance ,
@@ -192,7 +193,7 @@ def download(self) -> bytes:
192193 return self ._mail_instance .download_attachment (self ._message_id , self .filename )
193194
194195 @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' :
196197 """Create an Attachment from a raw api response"""
197198 return cls (
198199 _mail_instance = mail_instance ,
0 commit comments