def clean_message(self):
# Quick check if the message really came encrypted
message = self.cleaned_data.get("message")
lines = message.split("\r\n")
if getsizeof(message) > MAX_MESSAGE_SIZE:
self.add_error(
"message",
_('The message or file exceeds your allowed size limit.')
)
begin = "-----BEGIN PGP MESSAGE-----"
end = "-----END PGP MESSAGE-----"
try:
if lines[0] != begin or lines[-1] != end:
self.add_error("message", _('Invalid PGP message'))
except IndexError:
self.add_error("message", _('Invalid PGP message'))
return message
评论列表
文章目录