#
# Paranoid will check the message text to make sure that all the plaintext is
# in fact signed (bounded by a PGP packet)
-def GetClearSig(Msg,Paranoid = 0):
+#
+# lax_multipart: treat multipart bodies other than multipart/signed
+# as one big plain text body
+def GetClearSig(Msg, Paranoid = 0, lax_multipart = False):
if not Msg.__class__ == email.message.Message:
raise RuntimeError, "GetClearSign() not called with a email.message.Message"
+ if Paranoid and lax_multipart:
+ raise RuntimeError, "Paranoid and lax_multipart don't mix well"
+
# See if this is a MIME encoded multipart signed message
if Msg.is_multipart():
if not Msg.get_content_type() == "multipart/signed":
+ if lax_multipart:
+ payloads = Msg.get_payload()
+ msg = "\n".join(map( lambda p: p.get_payload(decode=True), payloads))
+ return (msg, 0)
raise UDFormatError, "Cannot handle multipart messages not of type multipart/signed";
if Paranoid:
(Signed, Signature) = payloads
- if Signed.get_content_type() != "text/plain":
- raise UDFormatError, "Invalid pgp/mime encoding [wrong plaintext type]";
+ if Signed.get_content_type() != "text/plain" and not lax_multipart:
+ raise UDFormatError, "Invalid pgp/mime encoding for first part[wrong plaintext type]";
if Signature.get_content_type() != "application/pgp-signature":
- raise UDFormatError, "Invalid pgp/mime encoding [wrong signature type]";
+ raise UDFormatError, "Invalid pgp/mime encoding for second part [wrong signature type]";
# Append the PGP boundary header and the signature text to re-form the
# original signed block [needs to convert to \r\n]