From d98cde440a95f7b19dad91dddfe35d1aff5ca37e Mon Sep 17 00:00:00 2001 From: Son NK <> Date: Sat, 1 Aug 2020 12:20:15 +0200 Subject: [PATCH 1/7] add how to test sending email using swaks and mailcatcher --- README.md | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/README.md b/README.md index d83b5991..a80af265 100644 --- a/README.md +++ b/README.md @@ -680,6 +680,42 @@ The code is formatted using https://github.com/psf/black, to format the code, si black . ``` +### Test sending email + +[swaks](http://www.jetmore.org/john/code/swaks/) is used for sending test emails to the `email_handler`. + +[mailcatcher](https://github.com/sj26/mailcatcher) is used to receive forwarded emails. + +There are several steps to set up the email handler + +1) run mailcatcher + +```bash +mailcatcher +``` + +2) Make sure to set the following variables in the `.env` file + +``` +NOT_SEND_EMAIL=true +POSTFIX_SERVER=localhost +POSTFIX_PORT=1025 +``` + +3) Run email_handler + +```bash +python email_handler.py +``` + +4) Send a test email + +```bash +swaks --to e1@d1.localhost --from hey@google.com --server 127.0.0.1:20381 +``` + +Now open http://localhost:1080/, you should see the test email. + ## API SimpleLogin current API clients are Chrome/Firefox/Safari extension and mobile (iOS/Android) app. From e8fc9752b5a9a10a4319e15e9ac6e0bacb068c12 Mon Sep 17 00:00:00 2001 From: Son NK <> Date: Sat, 1 Aug 2020 12:20:59 +0200 Subject: [PATCH 2/7] Add DomailMailbox model --- app/models.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/app/models.py b/app/models.py index 1c08ba42..86d3143d 100644 --- a/app/models.py +++ b/app/models.py @@ -1353,11 +1353,20 @@ class CustomDomain(db.Model, ModelMixin): db.Boolean, nullable=False, default=False, server_default="0" ) + _mailboxes = db.relationship("Mailbox", secondary="domain_mailbox", lazy="joined") + # an alias is created automatically the first time it receives an email catch_all = db.Column(db.Boolean, nullable=False, default=False, server_default="0") user = db.relationship(User, foreign_keys=[user_id]) + @property + def mailboxes(self): + if self._mailboxes: + return self._mailboxes + else: + return [self.user.default_mailbox] + def nb_alias(self): return Alias.filter_by(custom_domain_id=self.id).count() @@ -1625,6 +1634,21 @@ class DirectoryMailbox(db.Model, ModelMixin): ) +class DomainMailbox(db.Model, ModelMixin): + """store the owning mailboxes for a domain""" + + __table_args__ = ( + db.UniqueConstraint("domain_id", "mailbox_id", name="uq_domain_mailbox"), + ) + + domain_id = db.Column( + db.ForeignKey(CustomDomain.id, ondelete="cascade"), nullable=False + ) + mailbox_id = db.Column( + db.ForeignKey(Mailbox.id, ondelete="cascade"), nullable=False + ) + + _NB_RECOVERY_CODE = 8 _RECOVERY_CODE_LENGTH = 8 From ec8f12008538d0883b6138e234c14fe12123eaed Mon Sep 17 00:00:00 2001 From: Son NK <> Date: Sat, 1 Aug 2020 12:22:52 +0200 Subject: [PATCH 3/7] small fixes in directory.py --- app/dashboard/views/directory.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/app/dashboard/views/directory.py b/app/dashboard/views/directory.py index bcad92f9..5ddd7915 100644 --- a/app/dashboard/views/directory.py +++ b/app/dashboard/views/directory.py @@ -50,12 +50,9 @@ def directory(): dir_id = request.form.get("dir-id") dir = Directory.get(dir_id) - if not dir: + if not dir or dir.user_id != current_user.id: flash("Unknown error. Refresh the page", "warning") return redirect(url_for("dashboard.directory")) - elif dir.user_id != current_user.id: - flash("You cannot delete this directory", "warning") - return redirect(url_for("dashboard.directory")) mailbox_ids = request.form.getlist("mailbox_ids") # check if mailbox is not tempered with @@ -75,7 +72,7 @@ def directory(): flash("You must select at least 1 mailbox", "warning") return redirect(url_for("dashboard.directory")) - # first remove all existing alias-mailboxes links + # first remove all existing directory-mailboxes links DirectoryMailbox.query.filter_by(directory_id=dir.id).delete() db.session.flush() @@ -125,7 +122,7 @@ def directory(): or not mailbox.verified ): flash("Something went wrong, please retry", "warning") - return redirect(url_for("dashboard.custom_alias")) + return redirect(url_for("dashboard.directory")) mailboxes.append(mailbox) for mailbox in mailboxes: From f5bc166f3959f27257dd33f6ac22a4c3902432cf Mon Sep 17 00:00:00 2001 From: Son NK <> Date: Sat, 1 Aug 2020 12:31:02 +0200 Subject: [PATCH 4/7] able to choose mailboxes for a domain --- .../templates/dashboard/custom_domain.html | 93 ++++++++++++++++--- app/dashboard/views/custom_domain.py | 64 ++++++++++++- 2 files changed, 143 insertions(+), 14 deletions(-) diff --git a/app/dashboard/templates/dashboard/custom_domain.html b/app/dashboard/templates/dashboard/custom_domain.html index 34be64af..1ebc7008 100644 --- a/app/dashboard/templates/dashboard/custom_domain.html +++ b/app/dashboard/templates/dashboard/custom_domain.html @@ -20,7 +20,10 @@ {% if not current_user.is_premium() %}