-
Notifications
You must be signed in to change notification settings - Fork 11
Open
Description
The current download_attachment method always has to write to file:
Lines 151 to 170 in f8200fa
| def download_attachment( | |
| self, | |
| attachment: EmailBodyPart, | |
| file_name: Union[str, Path], | |
| ) -> None: | |
| if not file_name: | |
| raise Exception("Destination file name is required") | |
| file_name = Path(file_name) | |
| blob_url = self.jmap_session.download_url.format( | |
| accountId=self.account_id, | |
| blobId=attachment.blob_id, | |
| name=attachment.name, | |
| type=attachment.type, | |
| ) | |
| r = self.requests_session.get( | |
| blob_url, stream=True, timeout=REQUEST_TIMEOUT | |
| ) | |
| r.raise_for_status() | |
| with open(file_name, "wb") as f: | |
| f.write(r.raw.data) |
It would be handy to optionally write to memory, ie. being able to use io.BytesIO objects. This would make the library more flexible to be used as a library. A use case being for example an ETL tool that processes the contents of email attachments.
I'm happy to contribute as well.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels