OUT-151: Only create partial PEPMessage with recipients and direction for outgoing rating
authorThomas
Mon, 12 Feb 2018 16:40:36 +0100
changeset 1999dfab19314f7d
parent 1996 4a8c0f84a4fa
child 2002 c7124d30cf44
child 2003 c0dfc0f23c17
child 2008 fa305b491940
OUT-151: Only create partial PEPMessage with recipients and direction for outgoing rating
CryptableMailItem.cs
Log.cs
MsgProcessor.cs
PEPMessage.cs
     1.1 --- a/CryptableMailItem.cs	Fri Feb 09 10:15:36 2018 +0100
     1.2 +++ b/CryptableMailItem.cs	Mon Feb 12 16:40:36 2018 +0100
     1.3 @@ -128,7 +128,6 @@
     1.4          // The mirror of the internal mail item stored as PEPMessage.
     1.5          public PEPMessage   Mirror          { get; set; } = null;
     1.6  
     1.7 -
     1.8          /**************************************************************
     1.9           * 
    1.10           * Constructors/Destructors
     2.1 --- a/Log.cs	Fri Feb 09 10:15:36 2018 +0100
     2.2 +++ b/Log.cs	Mon Feb 12 16:40:36 2018 +0100
     2.3 @@ -239,7 +239,6 @@
     2.4              return;
     2.5          }
     2.6  
     2.7 -
     2.8          /// <summary>
     2.9          /// Rotates the log by saving a copy of the current log file to an archived file 
    2.10          /// and deleting older archived logs if necessary.
     3.1 --- a/MsgProcessor.cs	Fri Feb 09 10:15:36 2018 +0100
     3.2 +++ b/MsgProcessor.cs	Mon Feb 12 16:40:36 2018 +0100
     3.3 @@ -821,7 +821,9 @@
     3.4                          {
     3.5                              _msg = message.ToCOMType();
     3.6                              _msg.Dir = pEpMsgDirection.pEpDirOutgoing;
     3.7 +                            Log.Verbose("GetOutgoingRating: Calling PEPEngine.OutgoingMessageRating.");
     3.8                              engineRating = ThisAddIn.PEPEngine.OutgoingMessageRating(ref _msg);
     3.9 +                            Log.Verbose("GetOutgoingRating: PEPEngine.OutgoingMessageRating done.");
    3.10                          }
    3.11                          catch (COMException ex)
    3.12                          {
     4.1 --- a/PEPMessage.cs	Fri Feb 09 10:15:36 2018 +0100
     4.2 +++ b/PEPMessage.cs	Mon Feb 12 16:40:36 2018 +0100
     4.3 @@ -2300,6 +2300,8 @@
     4.4          /// </summary>
     4.5          /// <param name="omi">The outlook mail item to create the message from.</param>
     4.6          /// <param name="createdMessage">The output newly created message (will never be null).</param>
     4.7 +        /// <param name="onlyRecipientsAndDirection">Whether to only set recipients and direction. Only set to
     4.8 +        /// true in special cases, e.g. if the message is only needed to calculate the outgoing rating.</param>
     4.9          /// <returns>The status of the method.</returns>
    4.10          /// <remarks>In some contexts which call this message, a partial conversion of the
    4.11          /// <see cref="TextMessage"/> is acceptable, non-critical, and better than failure (e. G. displaying
    4.12 @@ -2309,12 +2311,11 @@
    4.13          /// and check the result if appropriate.</remarks>
    4.14          public static Globals.ReturnStatus Create(Outlook.MailItem omi,
    4.15                                                    out PEPMessage createdMessage,
    4.16 -                                                  bool createWithoutContent = false)
    4.17 +                                                  bool onlyRecipientsAndDirection = false)
    4.18          {
    4.19              byte[] rtfBody;
    4.20              string delim;
    4.21              string[] keywords;
    4.22 -            object propValue;
    4.23              DateTime? receivedOn = null;
    4.24              DateTime? sentOn = null;
    4.25              PEPIdentity ident;
    4.26 @@ -2330,10 +2331,6 @@
    4.27              {
    4.28                  Log.Verbose("PEPMessage.Create: Creating new PEPMessage from OMI started, calculating recipients.");
    4.29  
    4.30 -                /* Note: Skip the following properties which are not supported in the MailItem
    4.31 -                 *   • Direction
    4.32 -                 */
    4.33 -
    4.34                  // Calculate recipients
    4.35                  newMessage.Bcc.Clear();
    4.36                  newMessage.Cc.Clear();
    4.37 @@ -2414,93 +2411,64 @@
    4.38                  Log.Verbose("PEPMessage.Create: Recipients calculated, calculating main properties.");
    4.39  
    4.40                  newMessage.Direction = omi.GetIsIncoming() ? pEpMsgDirection.pEpDirIncoming : pEpMsgDirection.pEpDirOutgoing;
    4.41 +                Log.Verbose("PEPMessage.Create: direction calculated.");
    4.42  
    4.43 -                // From
    4.44 -                sts = PEPIdentity.GetFromIdentity(omi, out ident);
    4.45 -                if (sts == Globals.ReturnStatus.Success)
    4.46 +                if (onlyRecipientsAndDirection == false)
    4.47                  {
    4.48 -                    newMessage.From = ident;
    4.49 -                }
    4.50 -                else
    4.51 -                {
    4.52 -                    // Update the status, only the first failure type is recorded
    4.53 -                    if (status == Globals.ReturnStatus.Success)
    4.54 +                    // From
    4.55 +                    sts = PEPIdentity.GetFromIdentity(omi, out ident);
    4.56 +                    if (sts == Globals.ReturnStatus.Success)
    4.57                      {
    4.58 -                        status = sts;
    4.59 +                        newMessage.From = ident;
    4.60                      }
    4.61 +                    else
    4.62 +                    {
    4.63 +                        // Update the status, only the first failure type is recorded
    4.64 +                        if (status == Globals.ReturnStatus.Success)
    4.65 +                        {
    4.66 +                            status = sts;
    4.67 +                        }
    4.68  
    4.69 -                    Log.Error("PEPMessage.Create: Failure creating 'From' identity.");
    4.70 -                }
    4.71 +                        Log.Error("PEPMessage.Create: Failure creating 'From' identity.");
    4.72 +                    }
    4.73 +                    Log.Verbose("PEPMessage.Create: From identity calculated.");
    4.74  
    4.75 -                newMessage.Id = (string)MapiHelper.GetProperty(omi, MapiProperty.PidTagInternetMessageId, "");
    4.76 -                newMessage.ShortMsg = omi.Subject;
    4.77 +                    newMessage.Id = (string)MapiHelper.GetProperty(omi, MapiProperty.PidTagInternetMessageId, "");
    4.78 +                    newMessage.ShortMsg = omi.Subject;
    4.79  
    4.80 -                /* Date & Times
    4.81 -                 * 
    4.82 -                 * Note: The mail item date can be invalid:
    4.83 -                 * For incoming this commonly occurs when creating a mirror -- it's created without a received time.
    4.84 -                 * For outgoing this commonly occurs for unsent mail.
    4.85 -                 * In these cases, the invalid date and time will be returned as 1/1/4501 at 12:00AM
    4.86 -                 * This situation is filtered here and the date is set as null.
    4.87 -                 */
    4.88 -                receivedOn = omi.ReceivedTime;
    4.89 -                if ((receivedOn != null) &&
    4.90 -                    (((DateTime)receivedOn).Year > 4000)) // ~2000 years from now, no issue
    4.91 -                {
    4.92 -                    receivedOn = null;
    4.93 -                }
    4.94 -                newMessage.ReceivedOn = receivedOn;
    4.95 +                    /* Date & Times
    4.96 +                     * 
    4.97 +                     * Note: The mail item date can be invalid:
    4.98 +                     * For incoming this commonly occurs when creating a mirror -- it's created without a received time.
    4.99 +                     * For outgoing this commonly occurs for unsent mail.
   4.100 +                     * In these cases, the invalid date and time will be returned as 1/1/4501 at 12:00AM
   4.101 +                     * This situation is filtered here and the date is set as null.
   4.102 +                     */
   4.103 +                    receivedOn = omi.ReceivedTime;
   4.104 +                    if ((receivedOn != null) &&
   4.105 +                        (((DateTime)receivedOn).Year > 4000)) // ~2000 years from now, no issue
   4.106 +                    {
   4.107 +                        receivedOn = null;
   4.108 +                    }
   4.109 +                    newMessage.ReceivedOn = receivedOn;
   4.110  
   4.111 -                sentOn = omi.SentOn;
   4.112 -                if ((sentOn != null) &&
   4.113 -                    (((DateTime)sentOn).Year > 4000)) // ~2000 years from now, no issue
   4.114 -                {
   4.115 -                    sentOn = null;
   4.116 -                }
   4.117 -                newMessage.SentOn = sentOn;
   4.118 +                    sentOn = omi.SentOn;
   4.119 +                    if ((sentOn != null) &&
   4.120 +                        (((DateTime)sentOn).Year > 4000)) // ~2000 years from now, no issue
   4.121 +                    {
   4.122 +                        sentOn = null;
   4.123 +                    }
   4.124 +                    newMessage.SentOn = sentOn;
   4.125 +                    Log.Verbose("PEPMessage.Create: Dates calculated.");
   4.126  
   4.127 -                // Conversation information
   4.128 -                newMessage.ConversationId = omi.ConversationID;
   4.129 -                newMessage.ConversationIndex = omi.ConversationIndex;
   4.130 -                newMessage.ConversationTopic = omi.ConversationTopic;
   4.131 +                    // Conversation information
   4.132 +                    newMessage.ConversationId = omi.ConversationID;
   4.133 +                    newMessage.ConversationIndex = omi.ConversationIndex;
   4.134 +                    newMessage.ConversationTopic = omi.ConversationTopic;
   4.135  
   4.136 -                // AutoConsume
   4.137 -                omi.GetPEPProperty(MailItemExtensions.PEPProperty.AutoConsume, out propValue);
   4.138 -                newMessage.AutoConsume = propValue as string;
   4.139 +                    Log.Verbose("PEPMessage.Create: Main properties calculated, calculating body and attachments.");
   4.140  
   4.141 -                // EnableProtection
   4.142 -                omi.GetPEPProperty(MailItemExtensions.PEPProperty.EnableProtection, out propValue);
   4.143 -                newMessage.EnableProtection = (bool)propValue;
   4.144 -
   4.145 -                // ForceProtection
   4.146 -                omi.GetPEPProperty(MailItemExtensions.PEPProperty.ForceProtection, out propValue);
   4.147 -                newMessage.ForceProtectionId = propValue as string;
   4.148 -
   4.149 -                // ForceUnencrypted
   4.150 -                omi.GetPEPProperty(MailItemExtensions.PEPProperty.ForceUnencrypted, out propValue);
   4.151 -                newMessage.ForceUnencrypted = propValue as bool? ?? false;
   4.152 -
   4.153 -                // KeyList
   4.154 -                omi.GetPEPProperty(MailItemExtensions.PEPProperty.KeyList, out propValue);
   4.155 -                newMessage.KeyList = propValue as string;
   4.156 -
   4.157 -                // NeverUnsecure
   4.158 -                omi.GetPEPProperty(MailItemExtensions.PEPProperty.NeverUnsecure, out propValue);
   4.159 -                newMessage.NeverUnsecure = (bool)propValue;
   4.160 -
   4.161 -                // PEPProtocolVersion
   4.162 -                omi.GetPEPProperty(MailItemExtensions.PEPProperty.PEPProtocolVersion, out propValue);
   4.163 -                newMessage.PEPProtocolVersion = propValue as string;
   4.164 -
   4.165 -                // Rating
   4.166 -                omi.GetPEPProperty(MailItemExtensions.PEPProperty.Rating, out propValue);
   4.167 -                newMessage.Rating = (pEpRating)propValue;
   4.168 -
   4.169 -                Log.Verbose("PEPMessage.Create: Main properties calculated, calculating body and attachments.");
   4.170 -
   4.171 -                // Calculate text body and attachments
   4.172 -                if (createWithoutContent == false)
   4.173 -                {
   4.174 +                    // Calculate text body and attachments
   4.175                      // Body
   4.176                      if (omi.Body != null)
   4.177                      {
   4.178 @@ -2581,12 +2549,12 @@
   4.179                              Log.Warning("PEPMessage.Create: Unable to set keywords.");
   4.180                          }
   4.181                      }
   4.182 +
   4.183 +                    // Set PEP properties
   4.184 +                    HeaderList headers = omi.GetParsedTransportMessageHeaders();
   4.185 +                    newMessage.SetPEPProperties(omi, newMessage.Direction, newMessage.IsSecure, headers);
   4.186                  }
   4.187  
   4.188 -                // Set PEP properties and IsAttachment property
   4.189 -                HeaderList headers = omi.GetParsedTransportMessageHeaders();
   4.190 -                newMessage.SetPEPProperties(omi, newMessage.Direction, newMessage.IsSecure, headers);
   4.191 -
   4.192                  Log.Verbose("PEPMessage.Create: New PEPMessage created from OMI.");
   4.193              }
   4.194              catch (Exception ex)