Skip to content

Commit

Permalink
Merge pull request #2 from cubicbyte/inbox-interval
Browse files Browse the repository at this point in the history
Add custom inbox update interval support
  • Loading branch information
cubicbyte authored Oct 28, 2023
2 parents 1162d4e + 9dbe828 commit 2e75950
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ email = OneSecMail()

# request_email(email=email.address)

# Speed up inbox refresh rate
OneSecMail.inbox_update_interval = 0.1 # every 100ms

# Accept only emails with a specific subject, raise error after 60 seconds
msg = email.wait_for_message(timeout=60, filter=lambda m: m.subject == 'Hello World!')
print(msg.body)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def read(path: str) -> str:

setup(
name='tempmail-python',
version='2.3.0',
version='2.3.1',
description='Python library for generating and managing temporary email addresses.',
long_description=read('README.md'),
long_description_content_type='text/markdown',
Expand Down
5 changes: 4 additions & 1 deletion tempmail/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
class OneSecMail:
"""1secmail.com API wrapper"""

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:
"""Create a new 1secmail.com email address
Expand Down Expand Up @@ -67,7 +70,7 @@ def wait_for_message(self, timeout: int | None = 60, filter: callable = lambda _
for msg_info in inbox:
if filter(msg_info.message):
return msg_info.message
time.sleep(1)
time.sleep(OneSecMail.inbox_update_interval)

raise TimeoutError('Timed out waiting for message')

Expand Down

0 comments on commit 2e75950

Please sign in to comment.