From e905e151ca4eafd770650f5578db8810ca6c1cd5 Mon Sep 17 00:00:00 2001 From: Sibren Vasse Date: Sun, 17 May 2020 14:53:43 +0200 Subject: [PATCH] Create user setting for replacing reverse alias (default: false) --- .../templates/dashboard/setting.html | 21 +++++++++++++- app/dashboard/views/setting.py | 11 +++++++ app/models.py | 4 +++ email_handler.py | 7 +++-- .../versions/2020_051719_ce15cf3467b4_.py | 29 +++++++++++++++++++ 5 files changed, 69 insertions(+), 3 deletions(-) create mode 100644 migrations/versions/2020_051719_ce15cf3467b4_.py diff --git a/app/dashboard/templates/dashboard/setting.html b/app/dashboard/templates/dashboard/setting.html index b4e1eb8e..74d21181 100644 --- a/app/dashboard/templates/dashboard/setting.html +++ b/app/dashboard/templates/dashboard/setting.html @@ -173,7 +173,6 @@ -
Current Plan
@@ -238,6 +237,26 @@
+
+
+
Replace reverse alias
+
+ When replying to a reverse alias your email client will show the reverse alias ("ra+string@simplelogin.co") + as the original sender. This option will replace this string in the body of outgoing emails with the + original email address. This will break PGP signed emails, so only enable if you know what you're doing! +
+
+ +
+ + +
+ +
+
+
+
Quarantine
diff --git a/app/dashboard/views/setting.py b/app/dashboard/views/setting.py index 478d9314..53e64c6c 100644 --- a/app/dashboard/views/setting.py +++ b/app/dashboard/views/setting.py @@ -160,6 +160,7 @@ def setting(): db.session.commit() flash("Your preference has been updated", "success") return redirect(url_for("dashboard.setting")) + elif request.form.get("form-name") == "change-sender-format": sender_format = int(request.form.get("sender-format")) if SenderFormatEnum.has_value(sender_format): @@ -169,6 +170,16 @@ def setting(): db.session.commit() return redirect(url_for("dashboard.setting")) + elif request.form.get("form-name") == "replace-ra": + choose = request.form.get("replace-ra") + if choose == "on": + current_user.replace_reverse_alias = True + else: + current_user.replace_reverse_alias = False + db.session.commit() + flash("Your preference has been updated", "success") + return redirect(url_for("dashboard.setting")) + elif request.form.get("form-name") == "export-data": data = { "email": current_user.email, diff --git a/app/models.py b/app/models.py index 7ce2f710..92421735 100644 --- a/app/models.py +++ b/app/models.py @@ -194,6 +194,10 @@ class User(db.Model, ModelMixin, UserMixin): db.Integer, default="1", nullable=False, server_default="1" ) + replace_reverse_alias = db.Column( + db.Boolean, default=False, nullable=False, server_default="0" + ) + referral_id = db.Column( db.ForeignKey("referral.id", ondelete="SET NULL"), nullable=True, default=None ) diff --git a/email_handler.py b/email_handler.py index cd0ff2b7..567992ad 100644 --- a/email_handler.py +++ b/email_handler.py @@ -563,14 +563,17 @@ def handle_reply(envelope, smtp: SMTP, msg: Message, rcpt_to: str) -> (bool, str if custom_domain.dkim_verified: add_dkim_signature(msg, alias_domain) + msg_raw = msg.as_string().encode() + # replace the "ra+string@simplelogin.co" by the alias in the email body # as this is usually included in when replying - msg.replace(reply_email.encode(), alias.encode()) + if user.replace_reverse_alias: + msg_raw = msg_raw.replace(reply_email.encode(), alias.email.encode()) smtp.sendmail( alias.email, contact.website_email, - msg.as_bytes(), + msg_raw, envelope.mail_options, envelope.rcpt_options, ) diff --git a/migrations/versions/2020_051719_ce15cf3467b4_.py b/migrations/versions/2020_051719_ce15cf3467b4_.py new file mode 100644 index 00000000..c71c1ad3 --- /dev/null +++ b/migrations/versions/2020_051719_ce15cf3467b4_.py @@ -0,0 +1,29 @@ +"""empty message + +Revision ID: ce15cf3467b4 +Revises: 659d979b64ce +Create Date: 2020-05-17 19:38:30.255689 + +""" +import sqlalchemy_utils +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = 'ce15cf3467b4' +down_revision = '659d979b64ce' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.add_column('users', sa.Column('replace_reverse_alias', sa.Boolean(), server_default='0', nullable=False)) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_column('users', 'replace_reverse_alias') + # ### end Alembic commands ###