mirror of
https://github.com/simple-login/app.git
synced 2024-09-28 20:51:29 +02:00
Support download email file in browser
This commit is contained in:
parent
9cf5b886cc
commit
c4b97b55dc
23
app/s3.py
23
app/s3.py
@ -34,7 +34,28 @@ def upload_from_bytesio(key: str, bs: BytesIO, content_type="string"):
|
||||
|
||||
else:
|
||||
_session.resource("s3").Bucket(BUCKET).put_object(
|
||||
Key=key, Body=bs, ContentType=content_type
|
||||
Key=key, Body=bs, ContentType=content_type,
|
||||
)
|
||||
|
||||
|
||||
def upload_email_from_bytesio(path: str, bs: BytesIO, filename):
|
||||
bs.seek(0)
|
||||
|
||||
if LOCAL_FILE_UPLOAD:
|
||||
file_path = os.path.join(UPLOAD_DIR, path)
|
||||
file_dir = os.path.dirname(file_path)
|
||||
os.makedirs(file_dir, exist_ok=True)
|
||||
with open(file_path, "wb") as f:
|
||||
f.write(bs.read())
|
||||
|
||||
else:
|
||||
_session.resource("s3").Bucket(BUCKET).put_object(
|
||||
Key=path,
|
||||
Body=bs,
|
||||
# Support saving a remote file using Http header
|
||||
# Also supports Safari. More info at
|
||||
# https://github.com/eligrey/FileSaver.js/wiki/Saving-a-remote-file#using-http-header
|
||||
ContentDisposition=f'attachment; filename="{filename}.eml";',
|
||||
)
|
||||
|
||||
|
||||
|
@ -30,6 +30,7 @@ It should contain the following info:
|
||||
|
||||
|
||||
"""
|
||||
import uuid
|
||||
import time
|
||||
from email import encoders
|
||||
from email.message import Message
|
||||
@ -540,14 +541,15 @@ def handle_bounce(
|
||||
disable_alias_link = f"{URL}/dashboard/unsubscribe/{gen_email.id}"
|
||||
|
||||
# Store the bounced email
|
||||
random_name = random_string(50)
|
||||
orig_msg = get_orig_message_from_bounce(msg)
|
||||
# generate a name for the email
|
||||
random_name = str(uuid.uuid4())
|
||||
|
||||
full_report_path = f"refused-emails/full-{random_name}.eml"
|
||||
s3.upload_from_bytesio(full_report_path, BytesIO(msg.as_bytes()))
|
||||
s3.upload_email_from_bytesio(full_report_path, BytesIO(msg.as_bytes()), random_name)
|
||||
|
||||
file_path = f"refused-emails/{random_name}.eml"
|
||||
orig_msg = get_orig_message_from_bounce(msg)
|
||||
s3.upload_from_bytesio(file_path, BytesIO(orig_msg.as_bytes()))
|
||||
s3.upload_email_from_bytesio(file_path, BytesIO(orig_msg.as_bytes()), random_name)
|
||||
|
||||
refused_email = RefusedEmail.create(
|
||||
path=file_path, full_report_path=full_report_path, user_id=user.id
|
||||
|
@ -14,4 +14,5 @@
|
||||
{{ render_text('Please let us know if you have any question.') }}
|
||||
|
||||
{{ render_text('Thanks, <br />SimpleLogin Team.') }}
|
||||
{{ raw_url(refused_email_url) }}
|
||||
{% endblock %}
|
||||
|
Loading…
Reference in New Issue
Block a user