Replace ValueErrors with an EasyWks-specific error class

This commit is contained in:
s3lph 2021-09-26 18:49:41 +02:00
parent eb7e913dd9
commit e0085d7bfb

View file

@ -10,7 +10,7 @@ from .types import SubmissionRequest, ConfirmationResponse, PublishResponse, Con
from email.message import MIMEPart, Message
from email.parser import BytesParser
from email.policy import default, SMTP
from email.policy import default
from email.utils import getaddresses
from pgpy import PGPMessage, PGPKey, PGPUID
@ -57,7 +57,7 @@ def _get_pgp_publickey(parts: List[MIMEPart]) -> PGPKey:
except PGPError:
pass
if not pubkey:
raise EasyWksError('No PGP public key pubkey in message')
raise EasyWksError('No PGP public key in message')
return pubkey
@ -134,11 +134,11 @@ def process_mail(mail: bytes = None):
raise EasyWksError('Message has more than one recipients')
_, rcpt_mail = rcpt[0]
if rcpt_mail != submission_address:
raise EasyWksError(f'Message not addressed to submission address {submission_address} for domain {sender_domain}')
raise EasyWksError(f'Message not addressed to submission address {submission_address} '
f'for domain {sender_domain}')
leafs = _get_mime_leafs(msg)
pgp: PGPMessage = _get_pgp_message(leafs)
decrypted = pgp_decrypt(sender_domain, pgp)
rmsg = None
if decrypted.is_signed:
request: ConfirmationResponse = _parse_confirmation_response(decrypted, submission_address, sender_mail)
try: