From 55925858929fa13583cad105a44e6bded45d976a Mon Sep 17 00:00:00 2001 From: krypton-byte Date: Sat, 27 Nov 2021 09:40:34 +0700 Subject: [PATCH] &attachment --- example/main.py | 2 ++ xtempmail/mail.py | 9 +++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/example/main.py b/example/main.py index 1684522..ba04424 100644 --- a/example/main.py +++ b/example/main.py @@ -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") diff --git a/xtempmail/mail.py b/xtempmail/mail.py index 74ffa80..103a351 100644 --- a/xtempmail/mail.py +++ b/xtempmail/mail.py @@ -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: @@ -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"] @@ -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']