OUT-401: Move OutgoingRating() to MailItemExtensions and do not create contacts during OutgoingRating() OUT-401
authorThomas
Thu, 15 Feb 2018 10:27:00 +0100
branchOUT-401
changeset 2005 d5fa428e94ea
parent 2004 fef678d01f1f
child 2006 f2b0f06a8a5b
OUT-401: Move OutgoingRating() to MailItemExtensions and do not create contacts during OutgoingRating()
CryptableMailItem.cs
Extensions/MailItemExtensions.cs
PEPMessage.cs
--- a/CryptableMailItem.cs	Wed Feb 14 16:42:43 2018 +0100
+++ b/CryptableMailItem.cs	Thu Feb 15 10:27:00 2018 +0100
@@ -1037,26 +1037,10 @@
                         return (pEpRating.pEpRatingUnencrypted);
                     }
 
-                    PEPMessage msg;
-                    MsgProcessor processor = new MsgProcessor();
-                    Globals.ReturnStatus sts;
-
+                    // Else calculate it
                     lock (mutexMailItem)
                     {
-                        sts = PEPMessage.Create(this.internalMailItem, out msg, true);
-                    }
-
-                    if (sts == Globals.ReturnStatus.Success)
-                    {
-                        msg.FlattenAllRecipientIdentities();
-                        msg.Direction = pEpMsgDirection.pEpDirOutgoing;
-
-                        rating = processor.GetOutgoingRating(msg);
-                    }
-                    else
-                    {
-                        // Return undefined if a failure occured creating the message
-                        rating = pEpRating.pEpRatingUndefined;
+                        rating = this.internalMailItem.GetOutgoingRating();
                     }
 #endif
                 }
--- a/Extensions/MailItemExtensions.cs	Wed Feb 14 16:42:43 2018 +0100
+++ b/Extensions/MailItemExtensions.cs	Thu Feb 15 10:27:00 2018 +0100
@@ -2086,7 +2086,7 @@
             try
             {
                 PEPMessage message;
-                if (PEPMessage.Create(omi, out message) == Globals.ReturnStatus.Success)
+                if (PEPMessage.Create(omi, out message, true, false) == Globals.ReturnStatus.Success)
                 {
                     if (message.ForceUnencrypted)
                     {
@@ -2098,6 +2098,8 @@
                     }
                     else
                     {
+                        message.FlattenAllRecipientIdentities();
+                        message.Direction = pEpMsgDirection.pEpDirOutgoing;
                         rating = ThisAddIn.PEPEngine.OutgoingMessageRating(message.ToCOMType());
                     }
                 }
--- a/PEPMessage.cs	Wed Feb 14 16:42:43 2018 +0100
+++ b/PEPMessage.cs	Thu Feb 15 10:27:00 2018 +0100
@@ -2302,6 +2302,8 @@
         /// <param name="createdMessage">The output newly created message (will never be null).</param>
         /// <param name="onlyRecipientsAndDirection">Whether to only set recipients and direction. Only set to
         /// true in special cases, e.g. if the message is only needed to calculate the outgoing rating.</param>
+        /// <param name="createContacts">Whether or not to create contacts from the mail items's recipients during
+        /// processing of the message. Only set to false in special cases like for outgoing rating.</param>
         /// <returns>The status of the method.</returns>
         /// <remarks>In some contexts which call this message, a partial conversion of the
         /// <see cref="TextMessage"/> is acceptable, non-critical, and better than failure (e. G. displaying
@@ -2311,7 +2313,8 @@
         /// and check the result if appropriate.</remarks>
         public static Globals.ReturnStatus Create(Outlook.MailItem omi,
                                                   out PEPMessage createdMessage,
-                                                  bool onlyRecipientsAndDirection = false)
+                                                  bool onlyRecipientsAndDirection = false,
+                                                  bool createContacts = true)
         {
             byte[] rtfBody;
             string delim;
@@ -2367,7 +2370,7 @@
                             }
                         case Outlook.OlMailRecipientType.olCC:
                             {
-                                sts = PEPIdentity.Create(currRecipient, out ident, (newMessage.Direction == pEpMsgDirection.pEpDirOutgoing));
+                                sts = PEPIdentity.Create(currRecipient, out ident, (createContacts && (newMessage.Direction == pEpMsgDirection.pEpDirOutgoing)));
                                 if (sts == Globals.ReturnStatus.Success)
                                 {
                                     newMessage.Cc.Add(ident);
@@ -2387,7 +2390,7 @@
                             }
                         case Outlook.OlMailRecipientType.olTo:
                             {
-                                sts = PEPIdentity.Create(currRecipient, out ident, (newMessage.Direction == pEpMsgDirection.pEpDirOutgoing));
+                                sts = PEPIdentity.Create(currRecipient, out ident, (createContacts && (newMessage.Direction == pEpMsgDirection.pEpDirOutgoing)));
                                 if (sts == Globals.ReturnStatus.Success)
                                 {
                                     newMessage.To.Add(ident);