diff --git a/app/dashboard/templates/dashboard/mailbox.html b/app/dashboard/templates/dashboard/mailbox.html index 3696f524..a40b2619 100644 --- a/app/dashboard/templates/dashboard/mailbox.html +++ b/app/dashboard/templates/dashboard/mailbox.html @@ -48,7 +48,7 @@ 🚫 {% endif %} - {% if mailbox.pgp_finger_print %} + {% if mailbox.pgp_enabled() %} 🗝 {% endif %} diff --git a/app/dashboard/templates/dashboard/mailbox_detail.html b/app/dashboard/templates/dashboard/mailbox_detail.html index 17b0f62e..29beac34 100644 --- a/app/dashboard/templates/dashboard/mailbox_detail.html +++ b/app/dashboard/templates/dashboard/mailbox_detail.html @@ -29,7 +29,7 @@ 🚫 {% endif %} - {% if mailbox.pgp_finger_print %} + {% if mailbox.pgp_enabled() %} 🗝 {% endif %} @@ -120,7 +120,7 @@ -
+
@@ -139,7 +139,7 @@ {% if mailbox.generic_subject %} diff --git a/app/models.py b/app/models.py index 6ac2af67..0976a9b1 100644 --- a/app/models.py +++ b/app/models.py @@ -953,7 +953,7 @@ class Alias(db.Model, ModelMixin): def mailbox_support_pgp(self) -> bool: """return True of one of the mailboxes support PGP""" for mb in self.mailboxes: - if mb.pgp_finger_print: + if mb.pgp_enabled(): return True return False @@ -1683,6 +1683,12 @@ class Mailbox(db.Model, ModelMixin): user = db.relationship(User, foreign_keys=[user_id]) + def pgp_enabled(self) -> bool: + if self.pgp_finger_print and not self.disable_pgp: + return True + + return False + def nb_alias(self): return ( AliasMailbox.filter_by(mailbox_id=self.id).count() diff --git a/app/pgp_utils.py b/app/pgp_utils.py index 60e54cd3..bc15360e 100644 --- a/app/pgp_utils.py +++ b/app/pgp_utils.py @@ -65,7 +65,7 @@ def encrypt_file(data: BytesIO, fingerprint: str) -> str: # maybe the fingerprint is not loaded on this host, try to load it found = False # searching for the key in mailbox - mailbox = Mailbox.get_by(pgp_finger_print=fingerprint) + mailbox = Mailbox.get_by(pgp_finger_print=fingerprint, disable_pgp=False) if mailbox: LOG.d("(re-)load public key for %s", mailbox) load_public_key(mailbox.pgp_public_key) diff --git a/email_handler.py b/email_handler.py index 95001da9..1ab113bb 100644 --- a/email_handler.py +++ b/email_handler.py @@ -662,7 +662,11 @@ def forward_email_to_mailbox( ) # create PGP email if needed - if mailbox.pgp_finger_print and user.is_premium() and not alias.disable_pgp: + if ( + mailbox.pgp_enabled() + and user.is_premium() + and not alias.disable_pgp + ): LOG.d("Encrypt message using mailbox %s", mailbox) if mailbox.generic_subject: LOG.d("Use a generic subject for %s", mailbox)