Skip to content

Commit

Permalink
add: readme
Browse files Browse the repository at this point in the history
  • Loading branch information
krypton-byte committed Aug 10, 2022
1 parent 9007ee0 commit 04eab1d
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 6 deletions.
83 changes: 80 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -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 <a href='https://tempmail.plus'>tempmail.plus</a>

## Installation
```python
$ pip install git+https://github.com/krypton-byte/xtempmail
```

# Feature
## Feature
<ul>
<li> Custom Name/Mail</li>
<li> Reply/send Message(support attachment file)</li>
Expand All @@ -17,10 +22,82 @@ $ pip install git+https://github.com/krypton-byte/xtempmail
<li> Synchronous</li>
</ul>

# 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
<img src="assets/res.webp">
2 changes: 1 addition & 1 deletion example/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand Down
4 changes: 2 additions & 2 deletions example/main_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand All @@ -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):
Expand Down

0 comments on commit 04eab1d

Please sign in to comment.