Set key import header in automatic mails
authorThomas
Thu, 10 May 2018 15:04:25 +0200
changeset 2185 a3f839db149f
parent 2182 9465322722a1
child 2186 3b2a86a7c126
child 2187 a4b790cb6178
child 2199 5c8c43f38243
Set key import header in automatic mails
ThisAddIn.cs
UI/KeySyncWizard.xaml.cs
--- a/ThisAddIn.cs	Thu May 10 11:50:41 2018 +0200
+++ b/ThisAddIn.cs	Thu May 10 15:04:25 2018 +0200
@@ -685,10 +685,12 @@
         /// <param name="validateSendingAccount">Validates that the SendingAccount matches the From identity of the given message.
         /// This can catch situations (and throw exceptions) where the default account would be used instead.</param>
         /// <param name="processMessage">Whether or not to process this message through the pEp engine.</param>
+        /// <param name="setKeyImportHeader">Whether or not to process this message through the pEp engine.</param>
         internal void CreateAndSendMessage(PEPMessage message,
                                            bool deleteAfterSend,
                                            bool validateSendingAccount,
-                                           bool processMessage = false)
+                                           bool processMessage = false,
+                                           bool setKeyImportHeader = false)
         {
             Outlook.MailItem newItem;
             Globals.ReturnStatus sts;
@@ -721,10 +723,31 @@
                     MapiHelper.SetProperty(newItem, MapiProperty.PidLidUseTnef, false);
 
                     // If ForceUnencrypted property is set, add it to mail item
+                    bool save = false;
                     if (message.ForceUnencrypted)
                     {
                         newItem.SetPEPProperty(MailItemExtensions.PEPProperty.ForceUnencrypted, true);
-                        newItem.Save();
+                        save = true;
+                    }
+
+                    // Set KeyImport header if necessary
+                    if (setKeyImportHeader)
+                    {
+                        newItem.SetPEPProperty(MailItemExtensions.PEPProperty.KeyImport, message.KeyImport);
+                        save = true;
+                    }
+
+                    // Save if necessary
+                    if (save)
+                    {
+                        try
+                        {
+                            newItem.Save();
+                        }
+                        catch (Exception ex)
+                        {
+                            Log.Error("CreateAndSendMessage: Error saving new item. " + ex.ToString());
+                        }
                     }
 
                     /* Send
--- a/UI/KeySyncWizard.xaml.cs	Thu May 10 11:50:41 2018 +0200
+++ b/UI/KeySyncWizard.xaml.cs	Thu May 10 15:04:25 2018 +0200
@@ -15,9 +15,6 @@
                                            INotifyPropertyChanged,
                                            Interfaces.IReset
     {
-        public const string PEP_PGP_SYNC_MESSAGE_SUBJECT    = "p≡p Key Import";
-        public const string PEP_PGP_SYNC_MESSAGE_BODY       = "";
-
         /// <summary>
         /// The message types for sync messages.
         /// </summary>
@@ -778,7 +775,7 @@
                         }
 
                         // Send message
-                        Globals.ThisAddIn.CreateAndSendMessage(message, true, true, processMessage);
+                        Globals.ThisAddIn.CreateAndSendMessage(message, true, true, processMessage, true);
 
                         // Log that message has been sent
                         this.sentMessages?.Add(messageType);