ThisAddIn.cs
branchsync
changeset 2594 b4351ec5c330
parent 2568 c2085f8016dc
parent 2593 c266c7e55440
child 2610 09fde2338362
equal deleted inserted replaced
2577:f5b55f5a3184 2594:b4351ec5c330
   788         /// <param name="message">The message to send.</param>
   788         /// <param name="message">The message to send.</param>
   789         /// <param name="deleteAfterSend">Whether the message is deleted after sending (true) or a copy is saved (false).</param>
   789         /// <param name="deleteAfterSend">Whether the message is deleted after sending (true) or a copy is saved (false).</param>
   790         /// <param name="validateSendingAccount">Validates that the SendingAccount matches the From identity of the given message.
   790         /// <param name="validateSendingAccount">Validates that the SendingAccount matches the From identity of the given message.
   791         /// This can catch situations (and throw exceptions) where the default account would be used instead.</param>
   791         /// This can catch situations (and throw exceptions) where the default account would be used instead.</param>
   792         /// <param name="processMessage">Whether or not to process this message through the pEp engine.</param>
   792         /// <param name="processMessage">Whether or not to process this message through the pEp engine.</param>
   793         /// <param name="setKeyImportHeader">Whether or not to process this message through the pEp engine.</param>
       
   794         internal void CreateAndSendMessage(PEPMessage message,
   793         internal void CreateAndSendMessage(PEPMessage message,
   795                                            bool deleteAfterSend,
   794                                            bool deleteAfterSend,
   796                                            bool validateSendingAccount,
   795                                            bool validateSendingAccount,
   797                                            bool processMessage = false,
   796                                            bool processMessage = false)
   798                                            bool setKeyImportHeader = false)
       
   799         {
   797         {
   800             Outlook.MailItem newItem;
   798             Outlook.MailItem newItem;
   801             Globals.ReturnStatus sts;
   799             Globals.ReturnStatus sts;
   802 
   800 
   803             this.isItemSendHandlerEnabled = processMessage;
   801             this.isItemSendHandlerEnabled = processMessage;
   825                     }
   823                     }
   826 
   824 
   827                     // Do not allow TNEF/RTF format with 'winmail.dat' attachment
   825                     // Do not allow TNEF/RTF format with 'winmail.dat' attachment
   828                     MapiHelper.SetProperty(newItem, MapiProperty.PidLidUseTnef, false);
   826                     MapiHelper.SetProperty(newItem, MapiProperty.PidLidUseTnef, false);
   829 
   827 
   830                     // If ForceUnencrypted property is set, add it to mail item
   828                     // If ForceUnencrypted property is set, add it to mail item (only if message is to be processed)
   831                     bool save = false;
   829                     if (processMessage && 
   832                     if (message.ForceUnencrypted)
   830                         message.ForceUnencrypted)
   833                     {
   831                     {
   834                         newItem.SetPEPProperty(MailItemExtensions.PEPProperty.ForceUnencrypted, true);
   832                         newItem.SetPEPProperty(MailItemExtensions.PEPProperty.ForceUnencrypted, true);
   835                         save = true;
       
   836                     }
       
   837 
       
   838                     // Set KeyImport header if necessary
       
   839                     if (setKeyImportHeader)
       
   840                     {
       
   841                         newItem.SetPEPProperty(MailItemExtensions.PEPProperty.KeyImport, message.KeyImport);
       
   842                         save = true;
       
   843                     }
       
   844 
       
   845                     // Save if necessary
       
   846                     if (save)
       
   847                     {
       
   848                         try
       
   849                         {
       
   850                             newItem.Save();
       
   851                         }
       
   852                         catch (Exception ex)
       
   853                         {
       
   854                             Log.Error("CreateAndSendMessage: Error saving new item. " + ex.ToString());
       
   855                         }
       
   856                     }
   833                     }
   857 
   834 
   858                     /* Send
   835                     /* Send
   859                      * 
   836                      * 
   860                      * Note: For ActiveSync accounts, the DeleteAfterSubmit property is ignored.
   837                      * Note: For ActiveSync accounts, the DeleteAfterSubmit property is ignored.
  3337                     if (processingState == MailItemExtensions.ProcessingState.Processed)
  3314                     if (processingState == MailItemExtensions.ProcessingState.Processed)
  3338                     {
  3315                     {
  3339                         Log.Verbose("Application_ItemSend: Message already processed. Sending directly...");
  3316                         Log.Verbose("Application_ItemSend: Message already processed. Sending directly...");
  3340                         return;
  3317                         return;
  3341                     }
  3318                     }
       
  3319                     else if (processingState == MailItemExtensions.ProcessingState.ProcessedAvoidWinmailDat)
       
  3320                     {
       
  3321                         Log.Verbose("Application_ItemSend: Message already processed. Preventing Winmail.dat and sending directly...");
       
  3322                         omi.AvoidWinmailDatAttachment();
       
  3323                         return;
       
  3324                     }
  3342 
  3325 
  3343                     // Check for special cases
  3326                     // Check for special cases
  3344                     bool processMessage = true;
  3327                     bool processMessage = true;
  3345 
  3328 
  3346                     // If S/MIME is enabled, add pEp header and do not process
  3329                     // If S/MIME is enabled, add pEp header and do not process