def _decompress(self): if not self.is_compressed: self.context.trace("decompress ignored") return content_type = self.mime_message.get_content_type().lower() s_mime_type = self.mime_message.get_param('smime-type') if content_type != 'application/pkcs7-mime': raise AS2DeCompressException('decompress failed; content-type:{type} invalid', type=content_type) if s_mime_type != 'compressed-data': raise AS2DecryptException('decompress failed; s/mime-type:{type} invalid', type=s_mime_type) try: decompress_content = self.mime_message.get_payload(decode=True) content = SMIMEHelper.decompress_text(decompress_content) self.mime_message = email.message_from_string(content) self.context.trace("decompress finished") except: logger.exception("decompress failed; message-id: {id}".format(id=self.message_id)) raise AS2DeCompressException( "decompress failed; due to: {message}", message=sys.exc_info()[1])
def test_decompress_text(self): b64_decompress_content = '''ME8GCyqGSIb3DQEJEAEJoEAwPgIBADANBgsqhkiG9w0BCRADCDAqBgkqhkiG9w0BBwGgHQQbeJwL ycgsVgCiktTiEoXc1OLixPRUPQBULQeo ''' decompress_content = base64.decodestring(b64_decompress_content) content = SMIMEHelper.decompress_text(decompress_content) assert_equal(content, self.clearText)