diff --git a/README.md b/README.md index 12045a2..920042f 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,14 @@ +[![Unittest](https://github.com/krypton-byte/xtempmail/actions/workflows/typing.yml/badge.svg)](https://github.com/krypton-byte/xtempmail/actions/workflows/typing.yml) +[![Upload to PyPi](https://github.com/krypton-byte/xtempmail/actions/workflows/release.yml/badge.svg)](https://github.com/krypton-byte/xtempmail/actions/workflows/release.yml) # Temporary Mail +Tempmail client for tempmail.plus + +## Installation ```python $ pip install git+https://github.com/krypton-byte/xtempmail ``` -# Feature +## Feature -# Example +## Example ``` example/main.py ``` -# Demo +## Usage Sync +```python +from xtempmail import Email, extension +import logging +from xtempmail.mail import EmailMessage, EMAIL +log = logging.getLogger('xtempmail') +log.setLevel(logging.INFO) +app = Email(name='krypton', ext=ext=EMAIL.MAILTO_PLUS)) + +@app.on.message() +def baca(data: EmailMessage): + print(f"\tFrom: {data.from_mail}\n\tSubject: {data.subject}\n\tBody: {data.text}\n\tReply -> Delete") + ok = [] + for i in data.attachments: # -> Forward attachment + ok.append(( i.name, i.download())) + if data.from_is_local: + data.from_mail.send_message(data.subject, data.text, multiply_file=ok) # -> Forward message + data.delete() #delete message + +@app.on.message(lambda msg:msg.attachments) +def get_message_media(data: EmailMessage): + print(f'Attachment: {[i.name for i in data.attachments]}') + +@app.on.message(lambda x:x.from_mail.__str__().endswith('@gmail.com')) +def getGmailMessage(data: EmailMessage): + print(f'Gmail: {data.from_mail}') + + +if __name__ == '__main__': + try: + app.listen_new_message(1) + except KeyboardInterrupt: + app.destroy() #destroy inbox +``` + +## Usage Async +```python + +import asyncio +import logging +from xtempmail.aiomail import EMAIL, EmailMessage, Email +log = logging.getLogger('xtempmail') +log.setLevel(logging.INFO) +app = Email(name='krypton', ext=EMAIL.MAILTO_PLUS) +@app.on.message() +async def baca(data: EmailMessage): + print(f"\tFrom: {data.from_mail}\n\tSubject: {data.subject}\n\tBody: {data.text}\n\tReply -> Delete") + ok = [] + 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 + await data.delete() #delete message + +@app.on.message(lambda msg:msg.attachments) +async def get_message_media(data: EmailMessage): + print(f'Attachment: {[i.name for i in data.attachments]}') + +@app.on.message(lambda x:x.from_mail.__str__().endswith('@gmail.com')) +async def getGmailMessage(data: EmailMessage): + print(f'Gmail: {data.from_mail}') + +if __name__ == '__main__': + try: + loop = asyncio.new_event_loop() + loop.run_until_complete(app.listen()) + except Exception: + asyncio.run(app.destroy()) + + +``` + +## Demo \ No newline at end of file diff --git a/example/main.py b/example/main.py index fd48ecf..08e1f7e 100644 --- a/example/main.py +++ b/example/main.py @@ -7,7 +7,7 @@ @app.on.message() def baca(data: EmailMessage): - print(f"\tfrom: {data.from_mail}\n\tsubject: {data.subject}\n\tpesan: {data.text}\n\tReply -> Hapus") + print(f"\tFrom: {data.from_mail}\n\tSubject: {data.subject}\n\tBody: {data.text}\n\tReply -> Delete") ok = [] for i in data.attachments: # -> Forward attachment ok.append(( i.name, i.download())) diff --git a/example/main_async.py b/example/main_async.py index 7faa49d..b361f83 100644 --- a/example/main_async.py +++ b/example/main_async.py @@ -6,7 +6,7 @@ app = Email(name='krypton', ext=EMAIL.MAILTO_PLUS) @app.on.message() async def baca(data: EmailMessage): - print(f"\tfrom: {data.from_mail}\n\tsubject: {data.subject}\n\tpesan: {data.text}\n\tReply -> Hapus") + print(f"\tFrom: {data.from_mail}\n\tSubject: {data.subject}\n\tBody: {data.text}\n\tReply -> Delete") ok = [] for i in data.attachments: # -> Forward attachmen ok.append(( i.name, i.download())) @@ -16,7 +16,7 @@ async def baca(data: EmailMessage): @app.on.message(lambda msg:msg.attachments) async def get_message_media(data: EmailMessage): - print(f'attachment: {[i.name for i in data.attachments]}') + print(f'Attachment: {[i.name for i in data.attachments]}') @app.on.message(lambda x:x.from_mail.__str__().endswith('@gmail.com')) async def getGmailMessage(data: EmailMessage):