Try to detect some more stranges cases

This commit is contained in:
nemunaire 2022-03-31 02:26:13 +02:00
parent 7909a77a20
commit 81bca8ccae

View File

@ -115,11 +115,21 @@ def check(msg, GNUPG_DIRECTORY, accept_public_key=True, beta=False):
yield MailTest("Standalone non-armored signature file discovered. Avoid using binary signature over SMTP (see RFC2015 #2. PGP data formats).", 2) yield MailTest("Standalone non-armored signature file discovered. Avoid using binary signature over SMTP (see RFC2015 #2. PGP data formats).", 2)
yield (part.get_payload(decode=True), lpart.get_payload(decode=True)) yield (part.get_payload(decode=True), lpart.get_payload(decode=True))
elif part.get_filename() is not None and (part.get_filename()[len(part.get_filename())-4:] == ".gpg" or part.get_filename()[len(part.get_filename())-4:] == ".asc") or ( elif payload is not None and not part.is_multipart() and part.get_payload(decode=True).find(b"-----BEGIN PGP MESSAGE-----") >= 0:
payload is not None and not part.is_multipart() and part.get_payload(decode=True).find(b"-----BEGIN PGP MESSAGE-----") >= 0):
yield MailTest("Standalone PGP message discovered.") yield MailTest("Standalone PGP message discovered.")
yield part.get_payload(decode=True) yield part.get_payload(decode=True)
elif part.get_filename() is not None and (part.get_filename()[len(part.get_filename())-4:] == ".gpg" or part.get_filename()[len(part.get_filename())-4:] == ".asc"):
yield MailTest("Standalone PGP message discovered with mismatched content-type: %s. This can lead to unexpected behaviour." % part.get_content_type(), 2)
data = part.get_payload(decode=True)
mime = _guess_mime(data)
if mime == "application/octet-stream":
yield MailTest("Non-armored file discovered. Avoid using binary PGP message over SMTP (see RFC2015 #2. PGP data formats).", 2)
yield MailTest("Falling back to default automation as nothing helped. Be warned it'll most likely failed.", 2)
yield data
lpart = part lpart = part
def skip(msg, gpgmail): def skip(msg, gpgmail):