From 80d5624164fd1a4fd05bc4e669e316f07c1036b8 Mon Sep 17 00:00:00 2001 From: Bohdan Marukhnenko Date: Thu, 23 Nov 2023 11:40:01 +0200 Subject: [PATCH 1/4] Fixed need for python 3.10+ caused by typing --- tempmail/providers.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/tempmail/providers.py b/tempmail/providers.py index b7efbb6..755b055 100644 --- a/tempmail/providers.py +++ b/tempmail/providers.py @@ -2,6 +2,7 @@ import random from datetime import datetime from dataclasses import dataclass +from typing import Optional, List, Tuple, Dict import requests @@ -16,7 +17,7 @@ class OneSecMail: inbox_update_interval = 0.5 """How often to update the inbox in seconds""" - def __init__(self, address: str | None = None, username: str | None = None, domain: str | None = None) -> None: + def __init__(self, address: Optional[str] = None, username: Optional[str] = None, domain: Optional[str] = None) -> None: """Create a new 1secmail.com email address :param address: The full email address (username@domain) @@ -36,7 +37,7 @@ def __init__(self, address: str | None = None, username: str | None = None, doma self.domain = domain or random.choice(self.get_domains()) """The domain of the email address (after the @)""" - def get_inbox(self) -> list['OneSecMail.MessageInfo']: + def get_inbox(self) -> List['OneSecMail.MessageInfo']: """Get the inbox of the email address""" resp = self._session.get(f'https://www.1secmail.com/api/v1/?action=getMessages&login={self.username}&domain={self.domain}') resp.raise_for_status() @@ -56,7 +57,7 @@ def download_attachment(self, id: int, file: str) -> bytes: resp.raise_for_status() return resp.content - def wait_for_message(self, timeout: int | None = 60, filter: callable = lambda _: True) -> 'OneSecMail.Message': + def wait_for_message(self, timeout: Optional[int] = 60, filter: callable = lambda _: True) -> 'OneSecMail.Message': """Wait for a message to arrive in the inbox :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 _ @staticmethod @utils.cache - def get_domains() -> tuple[str, ...]: + def get_domains() -> Tuple[str, ...]: """List of allowed email domains""" resp = requests.get('https://www.1secmail.com/api/v1/?action=getDomainList') resp.raise_for_status() @@ -118,7 +119,7 @@ def message(self) -> 'OneSecMail.Message': return self._mail_instance.get_message(self.id) @classmethod - def from_dict(cls, mail_instance: 'OneSecMail', msg_info: dict[str, any]) -> 'OneSecMail.MessageInfo': + def from_dict(cls, mail_instance: 'OneSecMail', msg_info: Dict[str, any]) -> 'OneSecMail.MessageInfo': """Create a MessageInfo from a raw api response""" return cls( _mail_instance=mail_instance, @@ -155,12 +156,12 @@ def date(self) -> datetime: return datetime.fromisoformat(self.date_str) @property - def attachments(self) -> list['OneSecMail.Attachment']: + def attachments(self) -> List['OneSecMail.Attachment']: """List of attachments in the message (files)""" return [OneSecMail.Attachment.from_dict(self._mail_instance, self.id, attachment) for attachment in self._attachments] @classmethod - def from_dict(cls, mail_instance: 'OneSecMail', msg: dict[str, any]) -> 'OneSecMail.Message': + def from_dict(cls, mail_instance: 'OneSecMail', msg: Dict[str, any]) -> 'OneSecMail.Message': """Create a Message from a raw api response""" return cls( _mail_instance=mail_instance, @@ -192,7 +193,7 @@ def download(self) -> bytes: return self._mail_instance.download_attachment(self._message_id, self.filename) @classmethod - def from_dict(cls, mail_instance: 'OneSecMail', message_id: int, attachment: dict[str, any]) -> 'OneSecMail.Attachment': + def from_dict(cls, mail_instance: 'OneSecMail', message_id: int, attachment: Dict[str, any]) -> 'OneSecMail.Attachment': """Create an Attachment from a raw api response""" return cls( _mail_instance=mail_instance, From b22f75872bf2afda509278231e323a37e7d55e5c Mon Sep 17 00:00:00 2001 From: Bohdan Marukhnenko Date: Thu, 23 Nov 2023 11:40:48 +0200 Subject: [PATCH 2/4] Bump version --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 0b6ed11..da5e65d 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ def read(path: str) -> str: setup( name='tempmail-python', - version='2.3.1', + version='2.3.2', description='Python library for generating and managing temporary email addresses.', long_description=read('README.md'), long_description_content_type='text/markdown', From 2ba7b0838dc1fd99f919860f3efd75416a0dfe35 Mon Sep 17 00:00:00 2001 From: Bohdan Marukhnenko Date: Sat, 6 Jan 2024 18:08:54 +0200 Subject: [PATCH 3/4] Added python 3.7+ support --- README.md | 3 +++ setup.py | 7 +++++-- tempmail/providers.py | 21 +++++++++++++++------ tempmail/utils.py | 2 +- 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 2890aa5..2587fde 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,7 @@ # Python Temp Email Library + +[![Python 3.7+](https://img.shields.io/badge/python-3.7+-blue.svg)](https://www.python.org/downloads) + **tempmail-python** is a Python library for generating and managing temporary email addresses using the 1secmail service. It provides functions for creating email addresses, checking for new messages, and retrieving message contents. ## Installation diff --git a/setup.py b/setup.py index da5e65d..33c1969 100644 --- a/setup.py +++ b/setup.py @@ -1,9 +1,11 @@ from setuptools import setup, find_packages + def read(path: str) -> str: with open(path, 'r', encoding='utf-8') as f: return f.read() + setup( name='tempmail-python', version='2.3.2', @@ -13,15 +15,16 @@ def read(path: str) -> str: author='cubicbyte', author_email='bmaruhnenko@gmail.com', url='https://github.com/cubicbyte/tempmail-python', - packages = find_packages(), + packages=find_packages(), license='MIT', keywords='disposable-email temporary-email temp-email temp-mail email mail email-generator mail-generator', install_requires=[ 'requests>=2.19.0', ], + python_requires='>=3.7', classifiers=[ 'Development Status :: 5 - Production/Stable', 'Programming Language :: Python :: 3', 'License :: OSI Approved :: MIT License', ], -) \ No newline at end of file +) diff --git a/tempmail/providers.py b/tempmail/providers.py index 755b055..3a6fdc0 100644 --- a/tempmail/providers.py +++ b/tempmail/providers.py @@ -1,14 +1,16 @@ import time import random +from typing import Dict, Optional, Tuple, List, Callable from datetime import datetime from dataclasses import dataclass -from typing import Optional, List, Tuple, Dict import requests from . import utils -__all__ = ('OneSecMail',) +__all__ = ( + 'OneSecMail', +) class OneSecMail: @@ -17,7 +19,12 @@ class OneSecMail: inbox_update_interval = 0.5 """How often to update the inbox in seconds""" - def __init__(self, address: Optional[str] = None, username: Optional[str] = None, domain: Optional[str] = None) -> None: + def __init__( + self, + address: Optional[str] = None, + username: Optional[str] = None, + domain: Optional[str] = None, + ) -> None: """Create a new 1secmail.com email address :param address: The full email address (username@domain) @@ -57,7 +64,8 @@ def download_attachment(self, id: int, file: str) -> bytes: resp.raise_for_status() return resp.content - def wait_for_message(self, timeout: Optional[int] = 60, filter: callable = lambda _: True) -> 'OneSecMail.Message': + def wait_for_message(self, timeout: Optional[int] = 60, + filter: Callable[['OneSecMail.Message'], bool] = lambda _: True) -> 'OneSecMail.Message': """Wait for a message to arrive in the inbox :param timeout: How long to wait for a message to arrive, in seconds @@ -148,7 +156,7 @@ class Message: html_body: str "Message body (html format)" _mail_instance: 'OneSecMail' - _attachments: list[dict[str, any]] + _attachments: List[Dict[str, any]] @property def date(self) -> datetime: @@ -158,7 +166,8 @@ def date(self) -> datetime: @property def attachments(self) -> List['OneSecMail.Attachment']: """List of attachments in the message (files)""" - return [OneSecMail.Attachment.from_dict(self._mail_instance, self.id, attachment) for attachment in self._attachments] + return [OneSecMail.Attachment.from_dict(self._mail_instance, self.id, attachment) + for attachment in self._attachments] @classmethod def from_dict(cls, mail_instance: 'OneSecMail', msg: Dict[str, any]) -> 'OneSecMail.Message': diff --git a/tempmail/utils.py b/tempmail/utils.py index 6dc265c..bf9ef81 100644 --- a/tempmail/utils.py +++ b/tempmail/utils.py @@ -11,7 +11,7 @@ def random_string(length: int): def cache(func): """Cache the result of a function with saved type hints""" - @functools.lru_cache + @functools.lru_cache(maxsize=128) @functools.wraps(func) def wrapper(*args, **kwargs): return func(*args, **kwargs) From ebb9e689f3dac73eb5aef27aba1cf4e0e7328351 Mon Sep 17 00:00:00 2001 From: Bohdan Date: Mon, 8 Jan 2024 16:05:58 +0200 Subject: [PATCH 4/4] Bumped version --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 33c1969..61059c1 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ def read(path: str) -> str: setup( name='tempmail-python', - version='2.3.2', + version='2.3.3', description='Python library for generating and managing temporary email addresses.', long_description=read('README.md'), long_description_content_type='text/markdown',