diff --git a/envelope.py b/envelope.py index 2a0cf03..a3f6e4e 100644 --- a/envelope.py +++ b/envelope.py @@ -74,7 +74,16 @@ def check(msg, GNUPG_DIRECTORY, accept_public_key=True, beta=False): # Looking for signed content for part in msg.walk(): payload = part.get_payload() - if part.get_content_type() == "application/pgp-signature" or ( + if payload is not None and not part.is_multipart() and part.get_payload(decode=True).find(b"-----BEGIN PGP SIGNED MESSAGE-----") >= 0: + res = re.match(".*(-----BEGIN PGP SIGNED MESSAGE-----(.*)-----BEGIN PGP SIGNATURE-----(.*)-----END PGP SIGNATURE-----).*", payload, re.DOTALL) + if res is not None: + yield from assume_oldstyle(payload) + else: + res = re.match(b".*(-----BEGIN PGP SIGNED MESSAGE-----(.*)-----BEGIN PGP SIGNATURE-----(.*)-----END PGP SIGNATURE-----).*", part.get_payload(decode=True), re.DOTALL) + if res is not None: + yield from assume_oldstyle(part.get_payload(decode=True)) + + elif part.get_content_type() == "application/pgp-signature" or ( payload is not None and not part.is_multipart() and part.get_payload(decode=True).find(b"-----BEGIN PGP SIGNATURE-----") >= 0 ): if part.get_content_type() != "application/pgp-signature": @@ -91,12 +100,3 @@ def check(msg, GNUPG_DIRECTORY, accept_public_key=True, beta=False): yield MailTest("Public key file discovered, but content-type mismatched: got %s instead of application/pgp-keys." % part.get_content_type(), 2) yield from import_pubkey(part.get_payload(decode=True), GNUPG_DIRECTORY) return - - elif payload is not None and not part.is_multipart() and part.get_payload(decode=True).find(b"-----BEGIN PGP SIGNED MESSAGE-----") >= 0: - res = re.match(".*(-----BEGIN PGP SIGNED MESSAGE-----(.*)-----BEGIN PGP SIGNATURE-----(.*)-----END PGP SIGNATURE-----).*", payload, re.DOTALL) - if res is not None: - yield from assume_oldstyle(payload) - else: - res = re.match(b".*(-----BEGIN PGP SIGNED MESSAGE-----(.*)-----BEGIN PGP SIGNATURE-----(.*)-----END PGP SIGNATURE-----).*", part.get_payload(decode=True), re.DOTALL) - if res is not None: - yield from assume_oldstyle(part.get_payload(decode=True))