Skip to content

Commit

Permalink
Use func in init func to look for latest ym webmail version
Browse files Browse the repository at this point in the history
  • Loading branch information
rklf committed Jan 11, 2024
1 parent c243106 commit 77b1f15
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

setup(
name='yopmail',
version='1.7',
version='1.8',
description="A Python module to get mails from a Yopmail inbox, save them",
long_description=long_description,
long_description_content_type='text/markdown',
Expand Down
17 changes: 15 additions & 2 deletions yopmail/yopmail.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@ def __init__(self, username, proxies=None):
self.yp = None
self.yj = None
self.ytime = None
self.version = self.find_version(proxies=proxies) or '9.0'


def find_version(self, proxies=None) -> str:
# Looking for:
# <script src="/ver/[VERSION]/webmail.js"></script>
if req := self.session.get(self.url, proxies=proxies):
bs = BeautifulSoup(req.text, 'html.parser')
el = bs.find('script', {'src': re.compile(r'\/ver\/([0-9.]*)\/webmail.js')})
self.version = el['src'].split('/')[2]
return self.version
return None

def request(self, url: str, params=None, proxies=None, context: str = None) -> Optional[requests.models.Response]:
proxies = proxies if proxies is not None else self.proxies
Expand All @@ -57,7 +69,7 @@ def request(self, url: str, params=None, proxies=None, context: str = None) -> O

if self.yj is None:
context = 'yj'
req = self.session.get('https://yopmail.com/ver/8.7/webmail.js', proxies=proxies)
req = self.session.get(f'https://yopmail.com/ver/{self.version}/webmail.js', proxies=proxies)
if not req:
if req.status_code == 429:
raise requests.ConnectionError(f"Too Many Requests (429 status code) error, use a proxy or try again later")
Expand Down Expand Up @@ -107,7 +119,7 @@ def get_inbox(self, page=1, proxies=None) -> requests.models.Response|None:
'ctrl': '', # mailid or ''
'yp': self.yp,
'yj': self.yj,
'v': '8.7',
'v': self.version,
'r_c': '', # '' or recaptcha?
'id': '', # idaff / sometimes "none" / nextmailid='last' / mailid = id('m%d'%mail_nr)
'ad': '0', # 0 or 1 (advertising i guess)
Expand All @@ -133,6 +145,7 @@ def get_mail_body(self, mail_id: int, show_image=False, proxies=None) -> Yopmail
params = {
'b': self.username,
'id': mail_id # mail_id "{'i' to show images || 'm' to don't}e_ZGpjZGV1ZwRkZwD0ZQNjAmx0AmpkAj=="
# 'r_c': '', # recaptcha
}
req = self.request(f'{self.url}mail', params=params, proxies=proxies, context='mail body')
mail_html = str(BeautifulSoup(req.text, 'html.parser').find('div', {'id': 'mail'}))
Expand Down

0 comments on commit 77b1f15

Please sign in to comment.