-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add the possibility to send base64 encoded attachments to invenio-mail. #61
Add the possibility to send base64 encoded attachments to invenio-mail. #61
Conversation
|
||
if "attachments" in data: | ||
for attachment in data.get("attachments"): | ||
rawdata = b64decode(attachment.get("base64")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about limiting the max size?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was not sure about this: this code is called after the attachment has been pulled from the message queue, so I felt it is too late to do the check here. WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
after discussions (and sorry if we did not think about that earlier), maybe a better solution would:
- create a new func that accept attachments
- the new method will check the size
- if valid, it will call an async task
def send_email_attachments(data, attachments):
"""Nice docstring..."""
for att in attachments:
... if att size > config["MAX_ATTACHMENT_SIZE"]:
fail
... update data dict and add attachments ...
_send_email_attachments.apply_async(data)
@shared_task
def _send_email_attachments
msg = Message()
msg.__dict__.update(data)
msg.attach(content_type=content_type, data=rawdata, disposition=disposition)
...
WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds reasonable, but I'm not quite sure I completely understand your suggestion. The first function is not called via celery but directly? And by calling apply_async
a task will be generated? Ok, that would eliminate my objection.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a check for size limit and a test to see if it works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds reasonable, but I'm not quite sure I completely understand your suggestion. The first function is not called via celery but directly? And by calling
apply_async
a task will be generated? Ok, that would eliminate my objection.
You implemented it exactly as I was thinking 🥳
add test for checking for oversize attachment
|
||
if "attachments" in data: | ||
for attachment in data.get("attachments"): | ||
rawdata = b64decode(attachment.get("base64")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds reasonable, but I'm not quite sure I completely understand your suggestion. The first function is not called via celery but directly? And by calling
apply_async
a task will be generated? Ok, that would eliminate my objection.
You implemented it exactly as I was thinking 🥳
Thanks for your contribution! |
❤️ Thank you for your contribution!
Description
It is now possible to send emails with attachments by invenio-mail. They have to be base64 encoded, so they get decoded and attached to the mail.
Checklist
Ticks in all boxes and 🟢 on all GitHub actions status checks are required to merge:
Third-party code
If you've added third-party code (copy/pasted or new dependencies), please reach out to an architect.
Reminder
By using GitHub, you have already agreed to the GitHub’s Terms of Service including that: