-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Denis Pitkov
committed
Mar 11, 2023
1 parent
75cfe5e
commit e029730
Showing
8 changed files
with
138 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,4 +9,4 @@ | |
|
||
__author__ = 'Dionis1902' | ||
__email__ = 'den70007.ua@gmail.com' | ||
__version__ = '1.0.12' | ||
__version__ = '1.0.13' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import cloudscraper | ||
|
||
from .letter import Letter | ||
from ..exceptions import NotSetEmail, ProblemWithGetEmail | ||
from ..mail import Mail | ||
|
||
|
||
class TempMail(Mail): | ||
""" | ||
Class for work with https://temp-mail.org/ | ||
""" | ||
|
||
def __init__(self, proxy=None): | ||
super().__init__(proxy) | ||
|
||
self._s = cloudscraper.create_scraper(delay=10, browser="chrome") | ||
if proxy: | ||
self._s.proxies.update(self._proxies) | ||
|
||
self.__token = None | ||
|
||
def get_email(self): | ||
""" | ||
Get random email address from https://temp-mail.org/ | ||
""" | ||
|
||
r = (self._s.get if self.__token else self._s.post)('https://web2.temp-mail.org/mailbox', | ||
headers={'Authorization': 'Bearer ' + self.__token} if self.__token else None) | ||
if not r.ok: | ||
raise ProblemWithGetEmail() | ||
if not self.__token: | ||
self.__token = r.json().get('token') | ||
return self.set_email(r.json()['mailbox']) | ||
|
||
def get_inbox(self): | ||
if not self._email or not self.__token: | ||
raise NotSetEmail() | ||
|
||
r = self._s.get(f'https://web2.temp-mail.org/messages', headers={'Authorization': 'Bearer ' + self.__token}) | ||
if r.ok: | ||
return [Letter(self._email, _letter['from'], _letter['subject'], _letter['receivedAt'], _letter['bodyPreview']) for _letter in r.json().get('messages', [])] | ||
return [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import re | ||
|
||
from ..mail import letter | ||
from datetime import datetime | ||
|
||
|
||
class Letter(letter.Letter): | ||
def __init__(self, to, from_email, subject, timestamp, body): | ||
if '<' in from_email: | ||
name, from_email = re.findall(r'(.*) <(.*)>', from_email)[0] | ||
else: | ||
name = from_email = from_email | ||
|
||
super().__init__(to, name, from_email, subject, datetime.fromtimestamp(timestamp)) | ||
self.__body = body | ||
|
||
@property | ||
def letter(self): | ||
return self.__body |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from account_generator_helper import TempMail | ||
|
||
|
||
mail = TempMail() | ||
print('Mail :', mail.get_email()) # Mail : lolerip541@gpipes.com | ||
|
||
|
||
for _letter in mail.get_inbox(): | ||
print('Letter :', _letter) # Letter : (Letter ..) | ||
print('Letter content :', _letter.letter) # Letter content : ... | ||
|
||
|
||
@mail.letter_handler() | ||
def new_mail(letter): | ||
print('New mail :', letter) | ||
|
||
|
||
@mail.letter_handler(from_email='den70007.ua@gmail.com') | ||
def test_from(letter): | ||
print('Test from :', letter) | ||
|
||
|
||
@mail.letter_handler(re_subject='.* test .*') | ||
def test_re_subject(letter): | ||
print('Test re subject :', letter) | ||
|
||
|
||
@mail.letter_handler(from_email='den70007.ua@gmail.com', subject='Test letter') | ||
def test_handler(letter): | ||
print('Test handler :', letter) | ||
|
||
|
||
mail.poling() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters