Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Add python 3.7+ support #5

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

Merged
merged 1 commit into from
Jan 6, 2024
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions 3 README.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 5 additions & 2 deletions 7 setup.py
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -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',
],
)
)
21 changes: 15 additions & 6 deletions 21 tempmail/providers.py
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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':
Expand Down
2 changes: 1 addition & 1 deletion 2 tempmail/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.