Use pgp_enabled() instead of pgp_finger_print

This commit is contained in:
Son NK 2020-11-24 11:18:16 +01:00
parent 5997e5b5b5
commit c707342695
5 changed files with 18 additions and 8 deletions

View file

@ -48,7 +48,7 @@
🚫
</span>
{% endif %}
{% if mailbox.pgp_finger_print %}
{% if mailbox.pgp_enabled() %}
<span class="cursor" data-toggle="tooltip" data-original-title="PGP Enabled">🗝</span>
{% endif %}

View file

@ -29,7 +29,7 @@
🚫
</span>
{% endif %}
{% if mailbox.pgp_finger_print %}
{% if mailbox.pgp_enabled() %}
<span class="cursor" data-toggle="tooltip" data-original-title="PGP Enabled">🗝</span>
{% endif %}
</h1>
@ -120,7 +120,7 @@
</div>
<div class="card" {% if not mailbox.pgp_finger_print %} disabled {% endif %}>
<div class="card" {% if not mailbox.pgp_enabled() %} disabled {% endif %}>
<form method="post">
<input type="hidden" name="form-name" value="generic-subject">
@ -139,7 +139,7 @@
<label class="form-label">Generic Subject</label>
<input name="generic-subject"
{% if not mailbox.pgp_finger_print %} disabled {% endif %}
{% if not mailbox.pgp_enabled() %} disabled {% endif %}
class="form-control" maxlength="78"
placeholder="Generic Subject"
value="{{ mailbox.generic_subject or "" }}"
@ -147,7 +147,7 @@
</div>
<button class="btn btn-primary" name="action"
{% if not mailbox.pgp_finger_print %} disabled {% endif %}
{% if not mailbox.pgp_enabled() %} disabled {% endif %}
value="save">Save
</button>
{% if mailbox.generic_subject %}

View file

@ -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()

View file

@ -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)

View file

@ -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)