Merge pull request #121 from simple-login/sender-format
User can choose sender format
This commit is contained in:
commit
00313ffdf4
|
@ -166,6 +166,41 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="card" id="sender-format">
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="card-title">Sender address format</div>
|
||||||
|
<div class="mt-1 mb-3">
|
||||||
|
When your alias receives an email, says from <b>John Wick <john@wick.com></b>,
|
||||||
|
SimpleLogin forwards it to your mailbox. <br>
|
||||||
|
|
||||||
|
Due to some email constraints, SimpleLogin cannot keep the sender email address
|
||||||
|
in the original form and needs to <b>transform</b> it to one of the 2 below formats.
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<form method="post" action="#sender-format">
|
||||||
|
<input type="hidden" name="form-name" value="change-sender-format">
|
||||||
|
|
||||||
|
<div class="form-check">
|
||||||
|
<input class="form-check-input" type="radio" name="sender-format" id="exampleRadios1" value="1"
|
||||||
|
{% if current_user.use_via_format_for_sender %} checked {% endif %}>
|
||||||
|
<label class="form-check-label" for="exampleRadios1">
|
||||||
|
<b>john@wick.com via SimpleLogin</b>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-check">
|
||||||
|
<input class="form-check-input" type="radio" name="sender-format" id="exampleRadios2" value="0"
|
||||||
|
{% if not current_user.use_via_format_for_sender %} checked {% endif %}>
|
||||||
|
<label class="form-check-label" for="exampleRadios2">
|
||||||
|
<b>John Wick - john at wick.com</b>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button class="btn btn-outline-primary mt-3">Update</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
|
@ -183,7 +218,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<div class="card-title">Quarantine
|
<div class="card-title">Quarantine
|
||||||
<div class="small-text mt-1 mb-3" style="max-width: 40rem">
|
<div class="small-text mt-1 mb-3" style="max-width: 40rem">
|
||||||
|
|
|
@ -155,6 +155,15 @@ def setting():
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
flash("Your preference has been updated", "success")
|
flash("Your preference has been updated", "success")
|
||||||
return redirect(url_for("dashboard.setting"))
|
return redirect(url_for("dashboard.setting"))
|
||||||
|
elif request.form.get("form-name") == "change-sender-format":
|
||||||
|
sender_format = int(request.form.get("sender-format"))
|
||||||
|
if sender_format == 0:
|
||||||
|
current_user.use_via_format_for_sender = False
|
||||||
|
else:
|
||||||
|
current_user.use_via_format_for_sender = True
|
||||||
|
db.session.commit()
|
||||||
|
flash("Your sender format preference has been updated", "success")
|
||||||
|
return redirect(url_for("dashboard.setting"))
|
||||||
|
|
||||||
elif request.form.get("form-name") == "export-data":
|
elif request.form.get("form-name") == "export-data":
|
||||||
data = {
|
data = {
|
||||||
|
|
|
@ -365,16 +365,22 @@ def get_orig_message_from_bounce(msg: Message) -> Message:
|
||||||
return part
|
return part
|
||||||
|
|
||||||
|
|
||||||
def new_addr(old_addr, new_email) -> str:
|
def new_addr(old_addr, new_email, user: User) -> str:
|
||||||
"""replace First Last <first@example.com> by
|
"""replace First Last <first@example.com> by
|
||||||
first@example.com by SimpleLogin <new_email>
|
first@example.com by SimpleLogin <new_email>
|
||||||
|
|
||||||
`new_email` is a special reply address
|
`new_email` is a special reply address
|
||||||
"""
|
"""
|
||||||
name, old_email = parseaddr(old_addr)
|
name, old_email = parseaddr(old_addr)
|
||||||
new_name = f"{old_email} via SimpleLogin"
|
if user.use_via_format_for_sender:
|
||||||
new_addr = formataddr((new_name, new_email)).strip()
|
new_name = f"{old_email} via SimpleLogin"
|
||||||
|
else:
|
||||||
|
name = name or ""
|
||||||
|
new_name = (
|
||||||
|
name + (" - " if name else "") + old_email.replace("@", " at ")
|
||||||
|
).strip()
|
||||||
|
|
||||||
|
new_addr = formataddr((new_name, new_email)).strip()
|
||||||
return new_addr.strip()
|
return new_addr.strip()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -148,6 +148,12 @@ class User(db.Model, ModelMixin, UserMixin):
|
||||||
|
|
||||||
profile_picture = db.relationship(File, foreign_keys=[profile_picture_id])
|
profile_picture = db.relationship(File, foreign_keys=[profile_picture_id])
|
||||||
|
|
||||||
|
# Use the "via" format for sender address, i.e. "name@example.com via SimpleLogin"
|
||||||
|
# If False, use the format "Name - name at example.com"
|
||||||
|
use_via_format_for_sender = db.Column(
|
||||||
|
db.Boolean, default=True, nullable=False, server_default="1"
|
||||||
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create(cls, email, name, password=None, **kwargs):
|
def create(cls, email, name, password=None, **kwargs):
|
||||||
user: User = super(User, cls).create(email=email, name=name, **kwargs)
|
user: User = super(User, cls).create(email=email, name=name, **kwargs)
|
||||||
|
|
|
@ -290,7 +290,9 @@ def replace_header_when_forward(msg: Message, alias: Alias, header: str):
|
||||||
)
|
)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
new_addrs.append(new_addr(contact.website_from, contact.reply_email))
|
new_addrs.append(
|
||||||
|
new_addr(contact.website_from, contact.reply_email, alias.user)
|
||||||
|
)
|
||||||
need_replace = True
|
need_replace = True
|
||||||
|
|
||||||
if need_replace:
|
if need_replace:
|
||||||
|
@ -438,7 +440,7 @@ def handle_forward(envelope, smtp: SMTP, msg: Message, rcpt_to: str) -> (bool, s
|
||||||
# replace the email part in from: header
|
# replace the email part in from: header
|
||||||
contact_from_header = msg["From"]
|
contact_from_header = msg["From"]
|
||||||
contact_name, contact_email = parseaddr(contact_from_header)
|
contact_name, contact_email = parseaddr(contact_from_header)
|
||||||
new_from_header = new_addr(contact_from_header, contact.reply_email)
|
new_from_header = new_addr(contact_from_header, contact.reply_email, user)
|
||||||
add_or_replace_header(msg, "From", new_from_header)
|
add_or_replace_header(msg, "From", new_from_header)
|
||||||
LOG.d("new_from_header:%s, old header %s", new_from_header, contact_from_header)
|
LOG.d("new_from_header:%s, old header %s", new_from_header, contact_from_header)
|
||||||
|
|
||||||
|
|
29
migrations/versions/2020_032822_224fd8963462_.py
Normal file
29
migrations/versions/2020_032822_224fd8963462_.py
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
"""empty message
|
||||||
|
|
||||||
|
Revision ID: 224fd8963462
|
||||||
|
Revises: 67c61eead8d2
|
||||||
|
Create Date: 2020-03-28 22:30:19.428692
|
||||||
|
|
||||||
|
"""
|
||||||
|
import sqlalchemy_utils
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision = '224fd8963462'
|
||||||
|
down_revision = '67c61eead8d2'
|
||||||
|
branch_labels = None
|
||||||
|
depends_on = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade():
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.add_column('users', sa.Column('use_via_format_for_sender', sa.Boolean(), server_default='1', nullable=False))
|
||||||
|
# ### end Alembic commands ###
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade():
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.drop_column('users', 'use_via_format_for_sender')
|
||||||
|
# ### end Alembic commands ###
|
Loading…
Reference in a new issue