Release candidate: 0.3.1

Improves logging and some failure handling.

Reviewed-on: Disroot/gpg-lacre#163
This commit is contained in:
pfm 2024-09-21 14:31:45 +02:00
commit ea3eb7c09b
3 changed files with 15 additions and 5 deletions

View file

@ -133,8 +133,8 @@ def _gpg_encrypt_to_bytes(message: EmailMessage, keys, recipients, encrypt_f, lm
msg_copy = _gpg_encrypt_copy(message, keys, recipients, encrypt_f, lmessage)
try:
return msg_copy.as_bytes(policy=SMTPUTF8)
except IndexError:
raise MailSerialisationException()
except IndexError as ie:
raise MailSerialisationException(ie)
def _gpg_encrypt_to_str(message: EmailMessage, keys, recipients, encrypt_f) -> str:

View file

@ -54,7 +54,7 @@ class MailEncryptionProxy:
# If the message can't be encrypted or serialised to a
# stream of bytes, deliver original payload in
# cleartext.
LOG.error('Unable to encrypt message, delivering in cleartext: %s', e)
LOG.exception('Unable to encrypt message, delivering in cleartext')
self._send_unencrypted(operation, envelope, send)
except xport.TransientFailure:
@ -71,13 +71,17 @@ class MailEncryptionProxy:
else:
LOG.exception('Unexpected exception caught, bouncing message')
return xport.RESULT_TRANS_FAIL
return xport.RESULT_PERM_FAIL
return xport.RESULT_OK
def _send_unencrypted(self, operation, envelope: Envelope, send: xport.SendFrom):
# Do not parse and re-generate the message, just send it as it is.
send(envelope.original_content, operation.recipients())
try:
send(envelope.original_content, operation.recipients())
except:
LOG.exception('Unencrypted delivery failed, returning PERMANENT FAILURE to sender')
raise xport.PermanentFailure()
def _beginning(self, e: Envelope) -> bytes:
double_eol_pos = e.original_content.find(DOUBLE_EOL_BYTES)

View file

@ -1,6 +1,7 @@
"""Key management utilities."""
from datetime import datetime, timedelta
import logging
from lacre.config import get_item
@ -9,6 +10,9 @@ from lacre.config import get_item
_DEFAULT_TTL = 1
LOG = logging.getLogger(__name__)
def calculate_expiry_date(now: datetime) -> datetime:
"""Calculate date-time of key queue item expiry.
@ -24,7 +28,9 @@ def _get_ttl():
max_hours = get_item('database', 'max_queue_hours', _DEFAULT_TTL)
try:
ttl = int(max_hours)
LOG.debug('Key configmration queue max item age: %d hours', ttl)
return ttl
except ValueError:
# Not a valid integer, so we return the default.
LOG.exception('Invalid max_queue_hours format: %s, using default (%d)', max_hours, _DEFAULT_TTL)
return _DEFAULT_TTL