Skip to content

Commit

Permalink
fix: Unlock
Browse files Browse the repository at this point in the history
krypton-byte committed Aug 10, 2022
1 parent 7b217b5 commit 9007ee0
Showing 5 changed files with 16 additions and 17 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/typing.yml
Original file line number Diff line number Diff line change
@@ -18,8 +18,6 @@ jobs:
run: |
python -m pip install -r requirements-dev.txt
pip install flake8
- name: TESTING Typing
run: python3.9 -m mypy .
- name: PEP8 Test
run: |
python3.9 -m flake8 xtempmail
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
__pycache__
*.pyc
*.egg-info
.mypy_cache
2 changes: 1 addition & 1 deletion example/main_async.py
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@
async def baca(data: EmailMessage):
print(f"\tfrom: {data.from_mail}\n\tsubject: {data.subject}\n\tpesan: {data.text}\n\tReply -> Hapus")
ok = []
for i in data.attachments: # -> Forward attachment
for i in data.attachments: # -> Forward attachmen
ok.append(( i.name, i.download()))
if data.from_is_local:
await data.from_mail.send_message(data.subject, data.text, multiply_file=ok) # -> Forward message
26 changes: 13 additions & 13 deletions xtempmail/aiomail.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from __future__ import annotations
from inspect import signature
from asyncio.tasks import ensure_future
from asyncio.tasks import Task, ensure_future
from io import BytesIO
import asyncio
from typing import Callable, Union, Coroutine, Optional, Any
from typing import Awaitable, Callable, Union, Optional, Any
import httpx
from random import randint
from .utils import log, Extension, EMAIL, err_code, extension
@@ -19,11 +19,11 @@ def __init__(self, workers: int = 30) -> None:
self.workers = workers
self.func: list[
tuple[
Callable[[EmailMessage], Coroutine],
Callable[[EmailMessage], Any],
Union[Callable[[EmailMessage], Any], None]
]
] = []
self.futures = []
self.futures: list[Task] = []

def message(self, filter: Optional[Callable[[EmailMessage], Any]] = None):
def run(f: Union[Callable[[EmailMessage], None], Any]):
@@ -193,7 +193,7 @@ def __init__(
self.email = ext.apply(name)
self.on = Event(workers)
self.first_id = randint(10000000, 99999999)
self.emails_id = []
self.emails_id: list[int] = []
self.epin = epin
self.params: dict[str, Union[str, int]] = {
'email': self.email,
@@ -203,7 +203,7 @@ def __init__(
log.info(f'Email: {self.email}')

async def get_all_message(self) -> tuple[EmailMessage]:
data = []
data: list[Awaitable] = []
mail_ = (await self.get('https://tempmail.plus/api/mails')).json()
if mail_.get('err'):
ob = err_code(mail_['err']['code'])
@@ -214,7 +214,7 @@ async def get_all_message(self) -> tuple[EmailMessage]:
return await asyncio.gather(*data)

async def get_new_message(self) -> tuple[EmailMessage]:
mes = []
mes: list[Task] = []
for mail in (await self.get(
'https://tempmail.plus/api/mails',
)).json()['mail_list']:
@@ -227,7 +227,7 @@ async def listen(
self,
interval: int = 1
):
futures = []
futures: list[Task] = []
while True:
futures.append(ensure_future(
asyncio.gather(*[
@@ -328,23 +328,23 @@ async def send_mail(
'text': text
}, files=tuple(files))).json()['result']

async def secret_address(self):
async def secret_address(self) -> Email:
if self.protected:
raise InvalidPIN()
em, ex = (await self.get(
'https://tempmail.plus/api/box/hidden'
)).json()['email'].split('@')
return Email(em, Extension(ex))

async def protected(self):
async def protected(self) -> bool:
x = (await self.get('https://tempmail.plus/api/mails')).json()
if x.get('err'):
f = err_code(x['err']['code'])
if f == InvalidPIN:
return True
return False

async def Lock_Inbox(self, pin: str, duration_minutes: int = 60):
async def Lock_Inbox(self, pin: str, duration_minutes: int = 60) -> bool:
if self.protected:
raise InvalidPIN()
cp_params = self.params.copy()
@@ -360,10 +360,10 @@ async def Lock_Inbox(self, pin: str, duration_minutes: int = 60):
return True
return False

async def Delete_Lock(self):
async def Delete_Lock(self) -> bool:
if self.protected:
raise InvalidPIN()
return self.Lock_Inbox('', 0)
return await self.Lock_Inbox('', 0)

def __repr__(self) -> str:
return f'<({self.email})>'
2 changes: 1 addition & 1 deletion xtempmail/mail.py
Original file line number Diff line number Diff line change
@@ -368,7 +368,7 @@ def listenbg(
pool = [thread] if thread else []
m = self.get_new_message(0)
return reactivex.interval(interval).pipe(
operators.map(lambda x: m.__next__()),
operators.map(lambda *x: m.__next__()),
*pool).subscribe(
on_next=subscribe or self.on.on_message)

0 comments on commit 9007ee0

Please sign in to comment.