Skip to content

Commit

Permalink
&attachment
Browse files Browse the repository at this point in the history
  • Loading branch information
krypton-byte committed Nov 27, 2021
1 parent 5e75e05 commit 5592585
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 2 additions & 0 deletions example/main.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from xtempmail import Email, extension
import logging
from xtempmail.mail import EmailMessage

log = logging.getLogger('xtempmail')
log.setLevel(logging.INFO)
app = Email(name='krypton', ext=extension[1])

@app.on.message()
def baca(data: EmailMessage):
print(f"\tfrom: {data.from_mail}\n\tsubject: {data.subject}\n\tpesan: {data.text}\n\tReply -> Hapus")
Expand Down
9 changes: 5 additions & 4 deletions xtempmail/mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,20 @@ class Attachment:
:param name: filename
:param size: Filesize
"""
def __init__(self, mail, mail_id: int, attachment_id:int, content_id: str, name: str, size:int ) -> None:
def __init__(self, mail, mail_id: int, attachment_id:int, content_id: str, name: str, size:int, myemail: str) -> None:
self.mail = mail
self.mail_id = mail_id
self.id = attachment_id
self.content_id = content_id
self.name = name
self.size = size
self.myemail = myemail
def download(self, filename=False)->Union[BytesIO, int]:
"""
:param filename: str->save as file, bool -> BytesIO
"""
log.info(f'Download File, Attachment ID: {self.id} FROM: {self.mail.__repr__()} NAME: {self.name.__repr__()}')
bins=requests.get(f'https://tempmail.plus/api/mails/{self.mail_id}/attachments/{self.id}',params={'email':self.mail, 'epin':''})
bins=requests.get(f'https://tempmail.plus/api/mails/{self.mail_id}/attachments/{self.id}',params={'email':self.myemail, 'epin':''})
if isinstance(filename, str):
return open(filename,'wb').write(bins.content)
else:
Expand All @@ -121,7 +122,7 @@ def __init__(self, **kwargs) -> None:
self.attachments: list[Attachment]=[]
self.from_mail = StrangerMail(kwargs['to'], kwargs['from_mail'])
for i in kwargs.pop('attachments',{}):
attach = Attachment(**i, mail_id=kwargs['to'].email, mail=kwargs['from_mail'])
attach = Attachment(**i, mail_id=kwargs['mail_id'], mail=kwargs['from_mail'], myemail=kwargs['to'])
self.attachments.append(attach)
self.date: str = kwargs["date"]
self.from_is_local:bool = kwargs["from_is_local"]
Expand Down Expand Up @@ -227,7 +228,7 @@ def send_mail(self, to: str, subject: str, text: str, file = None, filename = 'f
if i.__len__() == 1:
files.append(('file',open(i[0],'rb')))
elif i.__len__() > 1:
x=('file', (i[0],i[1].getvalue()))
x=('file', (i[0], i[1].getvalue()))
files.append(x)
return self.post('https://tempmail.plus/api/mails/', data={'email': self.email,'to': to,'subject': subject,'content_type': 'text/html','text': text},files=tuple(files)).json()['result']

Expand Down

0 comments on commit 5592585

Please sign in to comment.