OUT-542: Avoid creation of Winmail.dat attachments during background processing
authorThomas
Tue, 05 Mar 2019 11:22:29 +0100
changeset 2593 c266c7e55440
parent 2592 fef273b2d6e4
child 2594 b4351ec5c330
child 2595 8b720212bbdf
OUT-542: Avoid creation of Winmail.dat attachments during background processing
Extensions/MailItemExtensions.cs
ThisAddIn.cs
--- a/Extensions/MailItemExtensions.cs	Mon Mar 04 14:47:39 2019 +0100
+++ b/Extensions/MailItemExtensions.cs	Tue Mar 05 11:22:29 2019 +0100
@@ -52,7 +52,8 @@
         {
             Undefined,
             ProcessInBackground,
-            Processed
+            Processed,
+            ProcessedAvoidWinmailDat
         }
 
         // Default values for pEp properties.
@@ -340,6 +341,8 @@
             omi?.DeleteUserProperty(CryptableMailItem.USER_PROPERTY_KEY_ENABLE_PROTECTION);
             omi?.DeleteUserProperty(CryptableMailItem.USER_PROPERTY_KEY_IS_ORIGINALLY_ENCRYPTED);
             omi?.DeleteUserProperty(CryptableMailItem.USER_PROPERTY_KEY_ORIGINAL_RATING);
+            omi?.DeleteUserProperty(MailItemExtensions.USER_PROPERTY_KEY_ORIG_ENTRY_ID);
+            omi?.DeleteUserProperty(MailItemExtensions.USER_PROPERTY_KEY_PROCESSING_STATE);
 
             // Do not allow TNEF/RTF format with 'winmail.dat' attachment
             MapiHelper.SetProperty(omi, MapiProperty.PidLidUseTnef, false);
@@ -2036,10 +2039,13 @@
                     // Avoid creation of 'winmail.dat' attachment if needed
                     if (processedMessage.IsSecure == false)
                     {
-                        omi.AvoidWinmailDatAttachment();
+                        omi.SetProcessingState(MailItemExtensions.ProcessingState.ProcessedAvoidWinmailDat);
                     }
-
-                    omi.SetProcessingState(MailItemExtensions.ProcessingState.Processed);
+                    else
+                    {
+                        omi.SetProcessingState(MailItemExtensions.ProcessingState.Processed);
+                    }
+
                     omi.Send();
                 }
                 catch (Exception ex)
--- a/ThisAddIn.cs	Mon Mar 04 14:47:39 2019 +0100
+++ b/ThisAddIn.cs	Tue Mar 05 11:22:29 2019 +0100
@@ -3313,6 +3313,12 @@
                         Log.Verbose("Application_ItemSend: Message already processed. Sending directly...");
                         return;
                     }
+                    else if (processingState == MailItemExtensions.ProcessingState.ProcessedAvoidWinmailDat)
+                    {
+                        Log.Verbose("Application_ItemSend: Message already processed. Preventing Winmail.dat and sending directly...");
+                        omi.AvoidWinmailDatAttachment();
+                        return;
+                    }
 
                     // Check for special cases
                     bool processMessage = true;