mirror of
https://github.com/simple-login/app.git
synced 2024-11-16 17:08:30 +01:00
Support download email file in browser
This commit is contained in:
parent
9cf5b886cc
commit
c4b97b55dc
3 changed files with 29 additions and 5 deletions
23
app/s3.py
23
app/s3.py
|
@ -34,7 +34,28 @@ def upload_from_bytesio(key: str, bs: BytesIO, content_type="string"):
|
||||||
|
|
||||||
else:
|
else:
|
||||||
_session.resource("s3").Bucket(BUCKET).put_object(
|
_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
|
import time
|
||||||
from email import encoders
|
from email import encoders
|
||||||
from email.message import Message
|
from email.message import Message
|
||||||
|
@ -540,14 +541,15 @@ def handle_bounce(
|
||||||
disable_alias_link = f"{URL}/dashboard/unsubscribe/{gen_email.id}"
|
disable_alias_link = f"{URL}/dashboard/unsubscribe/{gen_email.id}"
|
||||||
|
|
||||||
# Store the bounced email
|
# 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"
|
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"
|
file_path = f"refused-emails/{random_name}.eml"
|
||||||
orig_msg = get_orig_message_from_bounce(msg)
|
s3.upload_email_from_bytesio(file_path, BytesIO(orig_msg.as_bytes()), random_name)
|
||||||
s3.upload_from_bytesio(file_path, BytesIO(orig_msg.as_bytes()))
|
|
||||||
|
|
||||||
refused_email = RefusedEmail.create(
|
refused_email = RefusedEmail.create(
|
||||||
path=file_path, full_report_path=full_report_path, user_id=user.id
|
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('Please let us know if you have any question.') }}
|
||||||
|
|
||||||
{{ render_text('Thanks, <br />SimpleLogin Team.') }}
|
{{ render_text('Thanks, <br />SimpleLogin Team.') }}
|
||||||
|
{{ raw_url(refused_email_url) }}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
Loading…
Reference in a new issue