mirror of
https://github.com/simple-login/app.git
synced 2024-11-10 09:13:45 +08:00
RefusedEmail.path can be null
This commit is contained in:
parent
88039844ef
commit
86ef7f54d9
3 changed files with 42 additions and 4 deletions
|
@ -982,7 +982,7 @@ class RefusedEmail(db.Model, ModelMixin):
|
|||
full_report_path = db.Column(db.String(128), unique=True, nullable=False)
|
||||
|
||||
# The original email, to display to user
|
||||
path = db.Column(db.String(128), unique=True, nullable=False)
|
||||
path = db.Column(db.String(128), unique=True, nullable=True)
|
||||
|
||||
user_id = db.Column(db.ForeignKey(User.id, ondelete="cascade"), nullable=False)
|
||||
|
||||
|
@ -993,7 +993,10 @@ class RefusedEmail(db.Model, ModelMixin):
|
|||
deleted = db.Column(db.Boolean, nullable=False, default=False, server_default="0")
|
||||
|
||||
def get_url(self, expires_in=3600):
|
||||
return s3.get_url(self.path, expires_in)
|
||||
if self.path:
|
||||
return s3.get_url(self.path, expires_in)
|
||||
else:
|
||||
return s3.get_url(self.full_report_path, expires_in)
|
||||
|
||||
def __repr__(self):
|
||||
return f"<Refused Email {self.id} {self.path} {self.delete_at}>"
|
||||
|
|
|
@ -548,8 +548,10 @@ def handle_bounce(
|
|||
full_report_path = f"refused-emails/full-{random_name}.eml"
|
||||
s3.upload_email_from_bytesio(full_report_path, BytesIO(msg.as_bytes()), random_name)
|
||||
|
||||
file_path = f"refused-emails/{random_name}.eml"
|
||||
s3.upload_email_from_bytesio(file_path, BytesIO(orig_msg.as_bytes()), random_name)
|
||||
file_path = None
|
||||
if orig_msg:
|
||||
file_path = f"refused-emails/{random_name}.eml"
|
||||
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
|
||||
|
|
33
migrations/versions/2020_032216_541ce53ab6e9_.py
Normal file
33
migrations/versions/2020_032216_541ce53ab6e9_.py
Normal file
|
@ -0,0 +1,33 @@
|
|||
"""empty message
|
||||
|
||||
Revision ID: 541ce53ab6e9
|
||||
Revises: 30c13ca016e4
|
||||
Create Date: 2020-03-22 16:51:01.141010
|
||||
|
||||
"""
|
||||
import sqlalchemy_utils
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = '541ce53ab6e9'
|
||||
down_revision = '30c13ca016e4'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.alter_column('refused_email', 'path',
|
||||
existing_type=sa.VARCHAR(length=128),
|
||||
nullable=True)
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade():
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.alter_column('refused_email', 'path',
|
||||
existing_type=sa.VARCHAR(length=128),
|
||||
nullable=False)
|
||||
# ### end Alembic commands ###
|
Loading…
Reference in a new issue