From 317eab64ceee500709611541da83a48ee82f41c4 Mon Sep 17 00:00:00 2001 From: Philip Rodriguez Date: Sun, 18 May 2025 12:19:17 -0400 Subject: [PATCH] Add support for a --suppressCryptoErrors commdna line flag that causes exceptions from encrypted message decoding to be ignored This should provide a path forward for people in situations like the one described in https://github.com/iluvadev/XstReader/issues/19 --- src/XstReader.Api/XstMessage.cs | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/src/XstReader.Api/XstMessage.cs b/src/XstReader.Api/XstMessage.cs index 4b4be59..89dd8ca 100644 --- a/src/XstReader.Api/XstMessage.cs +++ b/src/XstReader.Api/XstMessage.cs @@ -642,20 +642,31 @@ private void ReadSignedOrEncryptedMessage(byte[] messageBytes) } else { - string decryptedMessage = Crypto.DecryptWithCert(messageBytes); - string cleartextMessage; - - //Message is only signed - if (decryptedMessage.Contains("filename=smime.p7m")) + try { - cleartextMessage = Crypto.DecodeSigned(decryptedMessage); + string decryptedMessage = Crypto.DecryptWithCert(messageBytes); + string cleartextMessage; + + //Message is only signed + if (decryptedMessage.Contains("filename=smime.p7m")) + { + cleartextMessage = Crypto.DecodeSigned(decryptedMessage); + } + // message is only encrypted not signed + else + { + cleartextMessage = decryptedMessage; + } + ParseMimeMessage(cleartextMessage); } - // message is only encrypted not signed - else + catch (Exception ex) { - cleartextMessage = decryptedMessage; - } - ParseMimeMessage(cleartextMessage); + if (!Environment.GetCommandLineArgs().Contains("--suppressCryptoErrors")) + { + throw ex; + } + System.Diagnostics.Debug.WriteLine(ex); + }; } //remove P7M encrypted file from attachments list