More formatting OUT-78
authorThomas
Thu, 14 Mar 2019 16:15:35 +0100
branchOUT-78
changeset 26000df6cdea7e12
parent 2599 4a54e3221729
child 2601 173103ca3542
More formatting
PEPMessage.cs
Wrappers/MailItemWrapper.cs
Wrappers/WindowBaseWrapper.cs
     1.1 --- a/PEPMessage.cs	Thu Mar 14 15:36:43 2019 +0100
     1.2 +++ b/PEPMessage.cs	Thu Mar 14 16:15:35 2019 +0100
     1.3 @@ -336,6 +336,14 @@
     1.4          }
     1.5  
     1.6          /// <summary>
     1.7 +        /// Gets whether this message is forcefully protected.
     1.8 +        /// </summary>
     1.9 +        public bool IsForcefullyProtected
    1.10 +        {
    1.11 +            get => (string.IsNullOrEmpty(this.ForceProtectionId) == false);
    1.12 +        }
    1.13 +
    1.14 +        /// <summary>
    1.15          /// Gets whether this message is considered secure.
    1.16          /// This will forward the call to the static method of the same purpose.
    1.17          /// </summary>
     2.1 --- a/Wrappers/MailItemWrapper.cs	Thu Mar 14 15:36:43 2019 +0100
     2.2 +++ b/Wrappers/MailItemWrapper.cs	Thu Mar 14 16:15:35 2019 +0100
     2.3 @@ -114,14 +114,17 @@
     2.4          private static Dictionary<string, string>           decryptionList          = new Dictionary<string, string>();
     2.5  
     2.6          // Property fields of the wrapped item
     2.7 +        private Outlook.OlAccountType?                      _AccountType            = null;
     2.8          private Outlook.OlDownloadState?                    _DownloadState          = null;
     2.9          private bool?                                       _IsDraft                = null;
    2.10          private bool?                                       _IsForcefullyProtected  = null;
    2.11          private bool?                                       _IsIncoming             = null;
    2.12          private bool?                                       _IsInSecureStore        = null;
    2.13 +        private bool?                                       _IsInSentFolder         = null;
    2.14          private bool?                                       _IsMirror               = null;
    2.15          private bool?                                       _IsOriginallyEncrypted  = null;
    2.16          private bool?                                       _IsSecure               = null;
    2.17 +        private bool?                                       _IsSubmitted            = null;
    2.18  
    2.19          /// <summary>
    2.20          /// Stores the message id of an attached mail item if it is loaded into the preview.
    2.21 @@ -716,7 +719,6 @@
    2.22              }
    2.23  #endif
    2.24              this.Write?.Invoke(ref cancel);
    2.25 -            return;
    2.26          }
    2.27  
    2.28          /**************************************************************
    2.29 @@ -726,6 +728,14 @@
    2.30           *************************************************************/
    2.31  
    2.32          /// <summary>
    2.33 +        /// Gets the type of the account where the mail item is located in.
    2.34 +        /// </summary>
    2.35 +        public Outlook.OlAccountType AccountType
    2.36 +        {
    2.37 +            get => this._AccountType ?? ((Outlook.OlAccountType)(this._AccountType = this.wrappedMailItem.GetAccountType()));
    2.38 +        }
    2.39 +
    2.40 +        /// <summary>
    2.41          /// Returns a constant that belongs to the OlDownloadState enumeration indicating the download state of the item.
    2.42          /// This forwards the call to the internal mail item.
    2.43          /// See: https://msdn.microsoft.com/en-us/library/office/ff866978.aspx
    2.44 @@ -752,6 +762,14 @@
    2.45          }
    2.46  
    2.47          /// <summary>
    2.48 +        /// Gets whether the mail item is forcefully protected.
    2.49 +        /// </summary>
    2.50 +        public bool IsForcefullyProtected
    2.51 +        {
    2.52 +            get => this._IsForcefullyProtected ?? ((bool)(this._IsForcefullyProtected = this.wrappedMailItem.GetIsForcefullyProtected()));
    2.53 +        }
    2.54 +
    2.55 +        /// <summary>
    2.56          /// Gets whether the mail item is marked as incoming (received mail, not sent).
    2.57          /// </summary>
    2.58          public bool IsIncoming
    2.59 @@ -760,6 +778,30 @@
    2.60          }
    2.61  
    2.62          /// <summary>
    2.63 +        /// Gets whether the mail item is in a secure store (untrusted server).
    2.64 +        /// </summary>
    2.65 +        public bool IsInSecureStore
    2.66 +        {
    2.67 +            get => this._IsInSecureStore ?? ((bool)(this._IsInSecureStore = this.wrappedMailItem.GetIsInSecureStore()));
    2.68 +        }
    2.69 +        
    2.70 +        /// <summary>
    2.71 +        /// Gets whether the mail item is in the Sent folder.
    2.72 +        /// </summary>
    2.73 +        public bool IsInSentFolder
    2.74 +        {
    2.75 +            get => this._IsInSentFolder ?? ((bool)(this._IsInSentFolder = this.wrappedMailItem.GetIsInSentFolder()));
    2.76 +        }
    2.77 +
    2.78 +        /// <summary>
    2.79 +        /// Gets whether the mail item is a mirror item.
    2.80 +        /// </summary>
    2.81 +        public bool IsMirror
    2.82 +        {
    2.83 +            get => this._IsMirror ?? ((bool)(this._IsMirror = this.wrappedMailItem.GetIsMirror()));
    2.84 +        }
    2.85 +
    2.86 +        /// <summary>
    2.87          /// Gets whether the wrapped mail item was marked as being originally encrypted.
    2.88          /// This should have been set by calling SetIsOriginallyEncryptedByCache() during the 
    2.89          /// EncryptedConversationCacheUpdated event.
    2.90 @@ -780,14 +822,6 @@
    2.91          }
    2.92  
    2.93          /// <summary>
    2.94 -        /// Gets whether the mail item is in a secure store (untrusted server).
    2.95 -        /// </summary>
    2.96 -        public bool IsInSecureStore
    2.97 -        {
    2.98 -            get => this._IsInSecureStore ?? ((bool)(this._IsInSecureStore = this.wrappedMailItem.GetIsInSecureStore()));
    2.99 -        }
   2.100 -
   2.101 -        /// <summary>
   2.102          /// Gets whether the mail item is secure (encrypted).
   2.103          /// </summary>
   2.104          public bool IsSecure
   2.105 @@ -804,19 +838,41 @@
   2.106          }
   2.107  
   2.108          /// <summary>
   2.109 -        /// Gets whether the mail item is a mirror item.
   2.110 +        /// Gets whether the mail item has been submitted.
   2.111          /// </summary>
   2.112 -        public bool IsMirror
   2.113 +        public bool IsSubmitted
   2.114          {
   2.115 -            get => this._IsMirror ?? ((bool)(this._IsMirror = this.wrappedMailItem.GetIsMirror()));
   2.116 +            get => this._IsSubmitted ?? ((bool)(this._IsSubmitted = this.wrappedMailItem.GetIsSubmitted()));
   2.117          }
   2.118  
   2.119          /// <summary>
   2.120 -        /// Gets whether the mail item is forcefully protected.
   2.121 +        /// Gets the status after the last message processing.
   2.122 +        /// This should be used to determine if a failure occured.
   2.123 +        /// Success is the default if no processing has been completed.
   2.124          /// </summary>
   2.125 -        public bool IsForcefullyProtected
   2.126 +        public Globals.ReturnStatus LastProcessedStatus
   2.127          {
   2.128 -            get => this._IsForcefullyProtected ?? ((bool)(this._IsForcefullyProtected = this.wrappedMailItem.GetIsForcefullyProtected()));
   2.129 +            get { return (this._LastProcessedStatus); }
   2.130 +        }
   2.131 +
   2.132 +        /// <summary>
   2.133 +        /// Gets the personal identity using the internal mail item.
   2.134 +        /// Warning: This can return null.
   2.135 +        /// </summary>
   2.136 +        public PEPIdentity Myself
   2.137 +        {
   2.138 +            get
   2.139 +            {
   2.140 +                lock (mutexMailItem)
   2.141 +                {
   2.142 +                    if (PEPIdentity.GetOwnIdentity(this.wrappedMailItem, out PEPIdentity ident) != Globals.ReturnStatus.Success)
   2.143 +                    {
   2.144 +                        ident = null;
   2.145 +                    }
   2.146 +
   2.147 +                    return ident;
   2.148 +                }
   2.149 +            }
   2.150          }
   2.151  
   2.152          /// <summary>
   2.153 @@ -851,41 +907,6 @@
   2.154              }
   2.155          }
   2.156  
   2.157 -        /// <summary>
   2.158 -        /// Gets the status after the last message processing.
   2.159 -        /// This should be used to determine if a failure occured.
   2.160 -        /// Success is the default if no processing has been completed.
   2.161 -        /// </summary>
   2.162 -        public Globals.ReturnStatus LastProcessedStatus
   2.163 -        {
   2.164 -            get { return (this._LastProcessedStatus); }
   2.165 -        }
   2.166 -
   2.167 -        /// <summary>
   2.168 -        /// Gets the personal identity using the internal mail item.
   2.169 -        /// Warning: This can return null.
   2.170 -        /// </summary>
   2.171 -        public PEPIdentity Myself
   2.172 -        {
   2.173 -            get
   2.174 -            {
   2.175 -                PEPIdentity ident = null;
   2.176 -                Globals.ReturnStatus sts;
   2.177 -
   2.178 -                lock (mutexMailItem)
   2.179 -                {
   2.180 -                    sts = PEPIdentity.GetOwnIdentity(this.wrappedMailItem, out ident);
   2.181 -                }
   2.182 -
   2.183 -                if (sts != Globals.ReturnStatus.Success)
   2.184 -                {
   2.185 -                    ident = null;
   2.186 -                }
   2.187 -
   2.188 -                return (ident);
   2.189 -            }
   2.190 -        }
   2.191 -
   2.192          /**************************************************************
   2.193           * 
   2.194           * Decryption
   2.195 @@ -905,10 +926,8 @@
   2.196  
   2.197              lock (mutexMailItem)
   2.198              {
   2.199 -                bool isDraft;
   2.200                  bool isPEPInternal = false;
   2.201                  bool isSecurelyStored = false;
   2.202 -                bool isSubmitted;
   2.203                  bool fullCalculation = true;
   2.204                  bool preProcessingPropertySet = false;
   2.205                  bool saveInternalMailItem = false;
   2.206 @@ -930,14 +949,9 @@
   2.207                  }
   2.208                  catch { }
   2.209  
   2.210 -                // Detect if the mail item is a draft
   2.211 -                isDraft = this.wrappedMailItem.GetIsDraft();
   2.212 -                isSubmitted = this.wrappedMailItem.GetIsSubmitted();
   2.213 -                Outlook.OlAccountType accountType = this.wrappedMailItem.GetAccountType();
   2.214 -
   2.215                  // Do not processes deleted messages on IMAP
   2.216                  if ((fullCalculation) &&
   2.217 -                    (accountType == Outlook.OlAccountType.olImap) &&
   2.218 +                    (this.AccountType == Outlook.OlAccountType.olImap) &&
   2.219                      (MapiHelper.GetProperty(this.wrappedMailItem, MapiProperty.PidLidImapMarkedForDeletion, "0").ToString() == "1"))
   2.220                  {
   2.221                      Log.Verbose("ProcessAndGetRating: Deleted IMAP message detected, skipping processing");
   2.222 @@ -946,8 +960,8 @@
   2.223                  }
   2.224  
   2.225                  // Check if the mail item is a mirror and use stored rating
   2.226 -                if ((fullCalculation) &&
   2.227 -                    (this.wrappedMailItem.GetIsMirror()))
   2.228 +                if (fullCalculation &&
   2.229 +                    this.IsMirror)
   2.230                  {
   2.231                      // Get UI rating from mirror
   2.232                      try
   2.233 @@ -979,8 +993,8 @@
   2.234                   * Note: It's important that the message is not submitted (since it could already be encrypted).
   2.235                   */
   2.236                  if ((fullCalculation) &&
   2.237 -                    (isDraft) &&
   2.238 -                    (isSubmitted == false))
   2.239 +                    (this.IsDraft) &&
   2.240 +                    (this.IsSubmitted == false))
   2.241                  {
   2.242                      Log.Verbose("ProcessAndGetRating: Draft detected, using outgoing rating.");
   2.243  
   2.244 @@ -989,7 +1003,7 @@
   2.245                  }
   2.246  
   2.247                  // Check if untrusted server and search for mirror. Use mirror rating if available
   2.248 -                isSecurelyStored = (this.wrappedMailItem.GetIsSecurelyStored() || this.IsSecureAttachedMail);
   2.249 +                isSecurelyStored = (this.IsSecurelyStored || this.IsSecureAttachedMail);
   2.250                  if (fullCalculation &&
   2.251                      isSecurelyStored)
   2.252                  {
   2.253 @@ -1037,7 +1051,7 @@
   2.254                               * messages, as saving with ActiveSync accounts tends to fail and then leads to "Save message?" dialogs
   2.255                               * popping up during shutdown of Outlook. (see OUT-216).
   2.256                               */
   2.257 -                            if (accountType != Outlook.OlAccountType.olEas)
   2.258 +                            if (this.AccountType != Outlook.OlAccountType.olEas)
   2.259                              {
   2.260                                  Globals.ThisAddIn.CreatePEPCategories();
   2.261  
   2.262 @@ -1061,7 +1075,7 @@
   2.263                       */
   2.264                      if ((isPEPInternal == false) &&
   2.265                           ((Globals.OutlookVersion == Globals.Version.Outlook2010) &&
   2.266 -                          (this.wrappedMailItem.GetIsInSecureStore() || this.wrappedMailItem.GetNeverUnsecure())))
   2.267 +                          (this.IsInSecureStore || this.NeverUnsecure)))
   2.268                      {
   2.269                          try
   2.270                          {
   2.271 @@ -1121,9 +1135,9 @@
   2.272                      // Process
   2.273                      status = msgProcessor.ProcessMessage(ref message,
   2.274                                                           sts1,
   2.275 -                                                         this.wrappedMailItem.GetIsInSecureStore(),
   2.276 -                                                         this.wrappedMailItem.GetIsInSentFolder(),
   2.277 -                                                         isDraft,
   2.278 +                                                         this.IsInSecureStore,
   2.279 +                                                         this.IsInSentFolder,
   2.280 +                                                         this.IsDraft,
   2.281                                                           out mirror,
   2.282                                                           out PEPMessage processedMessage,
   2.283                                                           out pEpRating processedRating,
   2.284 @@ -1197,7 +1211,7 @@
   2.285                                      }
   2.286  
   2.287                                      // If needed, set SmartNoAttach MAPI property to hide the attachments icon
   2.288 -                                    if ((accountType != Outlook.OlAccountType.olImap) &&
   2.289 +                                    if ((this.AccountType != Outlook.OlAccountType.olImap) &&
   2.290                                          (processedMessage.Attachments?.Count == 0) &&
   2.291                                          (this.wrappedMailItem.Attachments?.Count > 0))
   2.292                                      {
   2.293 @@ -1234,7 +1248,7 @@
   2.294                                   * an FPP message) we can get here. In this case, we need to set the
   2.295                                   * rating manually to reliable or higher (reevaluate).
   2.296                                   */
   2.297 -                                if ((string.IsNullOrEmpty(message.ForceProtectionId) == false) &&
   2.298 +                                if ((message.IsForcefullyProtected) &&
   2.299                                      (message.Rating == pEpRating.pEpRatingUndefined))
   2.300                                  {
   2.301                                      message.Rating = processedRating;
   2.302 @@ -1258,8 +1272,9 @@
   2.303                          }
   2.304                          else
   2.305                          {
   2.306 -                            this.wrappedMailItem.UnRead = (this.wrappedMailItem.GetIsInSentFolder() == false);
   2.307 +                            this.wrappedMailItem.UnRead = (this.IsInSentFolder == false);
   2.308                          }
   2.309 +
   2.310                          saveInternalMailItem = true;
   2.311                      }
   2.312  
   2.313 @@ -1514,7 +1529,6 @@
   2.314          private void Processor_DoWork(object sender, DoWorkEventArgs e)
   2.315          {
   2.316              e.Result = this.ProcessAndGetRating(e.Argument as string);
   2.317 -            return;
   2.318          }
   2.319  
   2.320          /// <summary>
   2.321 @@ -1611,8 +1625,6 @@
   2.322              {
   2.323                  this.mirrorLocator.RunWorkerAsync(messageId);
   2.324              }
   2.325 -
   2.326 -            return;
   2.327          }
   2.328  
   2.329          /// <summary>
   2.330 @@ -1671,7 +1683,6 @@
   2.331          private void MirrorLocator_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
   2.332          {
   2.333              this.GetMirrorCompleted?.Invoke(this, new GetMirrorCompletedEventArgs(e.Result == null ? null : (PEPMessage)e.Result));
   2.334 -            return;
   2.335          }
   2.336  
   2.337          /**************************************************************
   2.338 @@ -1688,7 +1699,6 @@
   2.339          {
   2.340              this.Dispose(true);
   2.341              // Note: GC.SuppressFinalize(this); is not called because that just seems bad
   2.342 -            return;
   2.343          }
   2.344  
   2.345          /// <summary>
   2.346 @@ -1704,8 +1714,6 @@
   2.347                  // Marshal.ReleaseComObject(this.internalMailItem);
   2.348                  this.wrappedMailItem = null;
   2.349              }
   2.350 -
   2.351 -            return;
   2.352          }
   2.353  
   2.354          /// <summary>
   2.355 @@ -1769,8 +1777,6 @@
   2.356                      Log.Error("ResolveAllRecipients: exception " + ex.ToString());
   2.357                  }
   2.358              }
   2.359 -
   2.360 -            return;
   2.361          }
   2.362  
   2.363          /// <summary>
   2.364 @@ -1883,8 +1889,6 @@
   2.365                      Log.Error("ConnectInternalMailItemEvents: Error occured. " + ex.ToString());
   2.366                  }
   2.367              }
   2.368 -
   2.369 -            return;
   2.370          }
   2.371  
   2.372          /**************************************************************
   2.373 @@ -1941,7 +1945,7 @@
   2.374          internal class ProcessingResult
   2.375          {
   2.376              public pEpRating Rating { get; set; } = pEpRating.pEpRatingUndefined;
   2.377 -            public Dictionary<MapiProperty.MapiProp, object> PropertiesToSet { get; set; } = new Dictionary<MapiProperty.MapiProp, object>();
   2.378 +            public MAPIProperties PropertiesToSet { get; set; } = new MAPIProperties();
   2.379          }
   2.380      }
   2.381  }
     3.1 --- a/Wrappers/WindowBaseWrapper.cs	Thu Mar 14 15:36:43 2019 +0100
     3.2 +++ b/Wrappers/WindowBaseWrapper.cs	Thu Mar 14 16:15:35 2019 +0100
     3.3 @@ -583,7 +583,7 @@
     3.4                  if (this.isEnabled)
     3.5                  {
     3.6                      // If forcefully protected, run dedicated decryption
     3.7 -                    if (this.CurrentMailItem.GetIsForcefullyProtected())
     3.8 +                    if (this.wrappedMailItem.IsForcefullyProtected)
     3.9                      {
    3.10                          FPPMessage fppMessage = new FPPMessage(this.CurrentMailItem);
    3.11                          if ((fppMessage?.GetMessageType() != null) ||