Merge with default sync
authorThomas
Tue, 05 Mar 2019 14:45:53 +0100
branchsync
changeset 2594b4351ec5c330
parent 2577 f5b55f5a3184
parent 2593 c266c7e55440
child 2610 09fde2338362
Merge with default
PEPIdentity.cs
ThisAddIn.cs
     1.1 --- a/Extensions/MailItemExtensions.cs	Fri Feb 22 17:01:56 2019 +0100
     1.2 +++ b/Extensions/MailItemExtensions.cs	Tue Mar 05 14:45:53 2019 +0100
     1.3 @@ -52,7 +52,8 @@
     1.4          {
     1.5              Undefined,
     1.6              ProcessInBackground,
     1.7 -            Processed
     1.8 +            Processed,
     1.9 +            ProcessedAvoidWinmailDat
    1.10          }
    1.11  
    1.12          // Default values for pEp properties.
    1.13 @@ -340,6 +341,8 @@
    1.14              omi?.DeleteUserProperty(CryptableMailItem.USER_PROPERTY_KEY_ENABLE_PROTECTION);
    1.15              omi?.DeleteUserProperty(CryptableMailItem.USER_PROPERTY_KEY_IS_ORIGINALLY_ENCRYPTED);
    1.16              omi?.DeleteUserProperty(CryptableMailItem.USER_PROPERTY_KEY_ORIGINAL_RATING);
    1.17 +            omi?.DeleteUserProperty(MailItemExtensions.USER_PROPERTY_KEY_ORIG_ENTRY_ID);
    1.18 +            omi?.DeleteUserProperty(MailItemExtensions.USER_PROPERTY_KEY_PROCESSING_STATE);
    1.19  
    1.20              // Do not allow TNEF/RTF format with 'winmail.dat' attachment
    1.21              MapiHelper.SetProperty(omi, MapiProperty.PidLidUseTnef, false);
    1.22 @@ -2036,10 +2039,13 @@
    1.23                      // Avoid creation of 'winmail.dat' attachment if needed
    1.24                      if (processedMessage.IsSecure == false)
    1.25                      {
    1.26 -                        omi.AvoidWinmailDatAttachment();
    1.27 +                        omi.SetProcessingState(MailItemExtensions.ProcessingState.ProcessedAvoidWinmailDat);
    1.28                      }
    1.29 -
    1.30 -                    omi.SetProcessingState(MailItemExtensions.ProcessingState.Processed);
    1.31 +                    else
    1.32 +                    {
    1.33 +                        omi.SetProcessingState(MailItemExtensions.ProcessingState.Processed);
    1.34 +                    }
    1.35 +
    1.36                      omi.Send();
    1.37                  }
    1.38                  catch (Exception ex)
     2.1 --- a/PEPIdentity.cs	Fri Feb 22 17:01:56 2019 +0100
     2.2 +++ b/PEPIdentity.cs	Tue Mar 05 14:45:53 2019 +0100
     2.3 @@ -950,7 +950,7 @@
     2.4                  catch (Exception ex)
     2.5                  {
     2.6                      identity = null;
     2.7 -                    Log.Error("GetOwnIdentity: Error determining getting own identity. " + ex.ToString());
     2.8 +                    Log.Error("GetOwnIdentity: Error determining own identity. " + ex.ToString());
     2.9                  }
    2.10              }
    2.11              else
    2.12 @@ -1999,7 +1999,7 @@
    2.13              // A resolved recipient has an address entry. This should be the common case. If an address entry can be retrieved,
    2.14              // run through the full Create() method. If no address entry is available, create a new pEp identity from the recipient.
    2.15              if ((addressEntry != null) &&
    2.16 -                (Create(addressEntry, out newIdent, addContact) == Globals.ReturnStatus.Success))
    2.17 +                (PEPIdentity.Create(addressEntry, out newIdent, addContact) == Globals.ReturnStatus.Success))
    2.18              {
    2.19                  status = Globals.ReturnStatus.Success;
    2.20              }
    2.21 @@ -2086,8 +2086,6 @@
    2.22              Outlook.ExchangeDistributionList exchDL = null;
    2.23              Outlook.AddressEntries exchDLMembers = null;
    2.24              Outlook.ExchangeUser exchUser = null;
    2.25 -            Globals.ReturnStatus sts;
    2.26 -            Globals.ReturnStatus status = Globals.ReturnStatus.Success;
    2.27  
    2.28              ///////////////////////////////////////////////////////////
    2.29              // Pre-process
    2.30 @@ -2164,8 +2162,14 @@
    2.31  
    2.32                              if (currentMember != null)
    2.33                              {
    2.34 -                                sts = PEPIdentity.Create(currentMember, out PEPIdentity member, addContact);
    2.35 -                                newIdent.Members.Add(member);
    2.36 +                                if (PEPIdentity.Create(currentMember, out PEPIdentity member, addContact) == Globals.ReturnStatus.Success)
    2.37 +                                {
    2.38 +                                    newIdent.Members.Add(member);
    2.39 +                                }
    2.40 +                                else
    2.41 +                                {
    2.42 +                                    Log.Error("PEPIdentity.Create: Error creating member from contact list.");
    2.43 +                                }
    2.44  
    2.45                                  currentMember = null;
    2.46                              }
    2.47 @@ -2429,7 +2433,7 @@
    2.48              contact = null;
    2.49  
    2.50              identity = newIdent;
    2.51 -            return (status);
    2.52 +            return (identityCreated ? Globals.ReturnStatus.Success : Globals.ReturnStatus.Failure);
    2.53          }
    2.54  
    2.55          /// <summary>
     3.1 --- a/PEPMessage.cs	Fri Feb 22 17:01:56 2019 +0100
     3.2 +++ b/PEPMessage.cs	Tue Mar 05 14:45:53 2019 +0100
     3.3 @@ -49,6 +49,8 @@
     3.4          public const string PEP_HIDDEN_SYNC_MESSAGE_BODY                 = "This message is part of p≡p's concept to synchronize. \n\nYou can safely ignore it. It will be deleted automatically.";
     3.5          public const string PEP_HIDDEN_SYNC_MESSAGE_SUBJECT              = "p≡p synchronization message - please ignore";
     3.6  
     3.7 +        public const string PEPTUNNEL_MAIL_ADDRESS         = "@peptunnel.com";
     3.8 +
     3.9          private static readonly object                      mutexMirror           = new object();
    3.10          private static readonly Dictionary<string, string>  mirrorCache           = new Dictionary<string, string>();
    3.11  
    3.12 @@ -76,6 +78,7 @@
    3.13          private string              _PEPProtocolVersion;
    3.14          private pEpRating           _Rating;
    3.15          private DateTime?           _ReceivedOn;
    3.16 +        private List<PEPIdentity>   _ReplyTo;
    3.17          private DateTime?           _SentOn;
    3.18          private string              _ShortMsg;
    3.19          private List<PEPIdentity>   _To;
    3.20 @@ -465,67 +468,6 @@
    3.21          }
    3.22  
    3.23          /// <summary>
    3.24 -        /// Gets the outgoing rating of this message.
    3.25 -        /// <param name="ignoreOptions">Ignore user settings like ForceProtection or
    3.26 -        /// ForceUnencrypted and return always calculated engine rating.</param>
    3.27 -        /// </summary>
    3.28 -        public pEpRating GetOutgoingRating(bool ignoreOptions = false,
    3.29 -                                           bool previewOnly = false)
    3.30 -        {
    3.31 -            pEpRating rating = pEpRating.pEpRatingUndefined;
    3.32 -
    3.33 -#if READER_RELEASE_MODE
    3.34 -            // If reader mode, always unencrypted
    3.35 -            rating = pEpRating.pEpRatingUnencrypted;
    3.36 -#else
    3.37 -            // If message has BCC recipients, always return unencrypted
    3.38 -            if (this.Bcc?.Count > 0)
    3.39 -            {
    3.40 -                return pEpRating.pEpRatingUnencrypted;
    3.41 -            }
    3.42 -
    3.43 -            if (ignoreOptions == false)
    3.44 -            {
    3.45 -                /* If message is forcefully unencrypted, return Unencrypted.
    3.46 -                 * If message is forcefully encrypted, return Reliable.
    3.47 -                 */
    3.48 -                if (this.ForceUnencrypted)
    3.49 -                {
    3.50 -                    return pEpRating.pEpRatingUnencrypted;
    3.51 -                }
    3.52 -                else if (string.IsNullOrEmpty(this.ForceProtectionId) == false)
    3.53 -                {
    3.54 -                    return pEpRating.pEpRatingReliable;
    3.55 -                }
    3.56 -            }
    3.57 -
    3.58 -            // If we have no rating at this point, calculate it
    3.59 -            PEPMessage workingMessage = this.Copy(true);
    3.60 -            workingMessage.FlattenAllRecipientIdentities();
    3.61 -            workingMessage.Direction = pEpMsgDirection.pEpDirOutgoing;
    3.62 -
    3.63 -            try
    3.64 -            {
    3.65 -                if (previewOnly)
    3.66 -                {
    3.67 -                    rating = ThisAddIn.PEPEngine.OutgoingMessageRatingPreview(workingMessage.ToCOMType());
    3.68 -                }
    3.69 -                else
    3.70 -                {
    3.71 -                    rating = ThisAddIn.PEPEngine.OutgoingMessageRating(workingMessage.ToCOMType());
    3.72 -                }
    3.73 -            }
    3.74 -            catch (Exception ex)
    3.75 -            {
    3.76 -                rating = pEpRating.pEpRatingUndefined;
    3.77 -                Log.Error("GetOutgoingRating: Error getting outgoing rating from engine. " + ex.ToString());
    3.78 -            }
    3.79 -
    3.80 -#endif
    3.81 -            return rating;
    3.82 -        }
    3.83 -
    3.84 -        /// <summary>
    3.85          /// Gets or sets the pEp protocol (or 'format') version of this message.
    3.86          /// This is not to be confused with pEp engine version which can be different.
    3.87          /// This is commonly set after decryption.
    3.88 @@ -581,6 +523,16 @@
    3.89          }
    3.90  
    3.91          /// <summary>
    3.92 +        /// Gets the list of identities in the Reply-To field.
    3.93 +        ///          MailItem : Corresponds to property 'ReplyRecipients' 
    3.94 +        ///       TextMessage : Corresponds to property 'ReplyTo'
    3.95 +        /// </summary>
    3.96 +        public List<PEPIdentity> ReplyTo
    3.97 +        {
    3.98 +            get { return (this._ReplyTo); }
    3.99 +        }
   3.100 +
   3.101 +        /// <summary>
   3.102          /// Gets or sets the date and time when the message was sent.
   3.103          ///          MailItem : Corresponds to property 'SentOn'
   3.104          /// CryptableMailItem : not supported
   3.105 @@ -678,8 +630,68 @@
   3.106          /// <param name="propertyName">The name of the property that changed.</param>
   3.107          private void RaisePropertyChangedEvent(string propertyName)
   3.108          {
   3.109 -            this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
   3.110 -            return;
   3.111 +            this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));           
   3.112 +        }
   3.113 +
   3.114 +        /// <summary>
   3.115 +        /// Gets the outgoing rating of this message.
   3.116 +        /// <param name="ignoreOptions">Ignore user settings like ForceProtection or
   3.117 +        /// ForceUnencrypted and return always calculated engine rating.</param>
   3.118 +        /// </summary>
   3.119 +        public pEpRating GetOutgoingRating(bool ignoreOptions = false,
   3.120 +                                           bool previewOnly = false)
   3.121 +        {
   3.122 +            pEpRating rating = pEpRating.pEpRatingUndefined;
   3.123 +
   3.124 +#if READER_RELEASE_MODE
   3.125 +            // If reader mode, always unencrypted
   3.126 +            rating = pEpRating.pEpRatingUnencrypted;
   3.127 +#else
   3.128 +            // If message has BCC recipients, always return unencrypted
   3.129 +            if (this.Bcc?.Count > 0)
   3.130 +            {
   3.131 +                return pEpRating.pEpRatingUnencrypted;
   3.132 +            }
   3.133 +
   3.134 +            if (ignoreOptions == false)
   3.135 +            {
   3.136 +                /* If message is forcefully unencrypted, return Unencrypted.
   3.137 +                 * If message is forcefully encrypted, return Reliable.
   3.138 +                 */
   3.139 +                if (this.ForceUnencrypted)
   3.140 +                {
   3.141 +                    return pEpRating.pEpRatingUnencrypted;
   3.142 +                }
   3.143 +                else if (string.IsNullOrEmpty(this.ForceProtectionId) == false)
   3.144 +                {
   3.145 +                    return pEpRating.pEpRatingReliable;
   3.146 +                }
   3.147 +            }
   3.148 +
   3.149 +            // If we have no rating at this point, calculate it
   3.150 +            PEPMessage workingMessage = this.Copy(true);
   3.151 +            workingMessage.FlattenAllRecipientIdentities();
   3.152 +            workingMessage.Direction = pEpMsgDirection.pEpDirOutgoing;
   3.153 +
   3.154 +            try
   3.155 +            {
   3.156 +                if (previewOnly)
   3.157 +                {
   3.158 +                    rating = ThisAddIn.PEPEngine.OutgoingMessageRatingPreview(workingMessage.ToCOMType());
   3.159 +                }
   3.160 +                else
   3.161 +                {
   3.162 +                    rating = ThisAddIn.PEPEngine.OutgoingMessageRating(workingMessage.ToCOMType());
   3.163 +                }
   3.164 +            }
   3.165 +            catch (Exception ex)
   3.166 +            {
   3.167 +                rating = pEpRating.pEpRatingUndefined;
   3.168 +                Log.Error("GetOutgoingRating: Error getting outgoing rating from engine. " + ex.ToString());
   3.169 +            }
   3.170 +
   3.171 +#endif
   3.172 +            return rating;
   3.173          }
   3.174  
   3.175          /// <summary>
   3.176 @@ -700,6 +712,7 @@
   3.177              List<pEpIdentity> bcc = new List<pEpIdentity>();
   3.178              List<pEpIdentity> cc = new List<pEpIdentity>();
   3.179              List<pEpIdentity> to = new List<pEpIdentity>();
   3.180 +            List<pEpIdentity> replyTo = new List<pEpIdentity>();
   3.181              List<StringPair> optionalFields = new List<StringPair>();
   3.182              StringPair field;
   3.183              TextMessage result = new TextMessage();
   3.184 @@ -830,6 +843,12 @@
   3.185                  recvSec = (long)span.TotalSeconds;
   3.186              }
   3.187  
   3.188 +            // Convert ReplyTo
   3.189 +            for (int i = 0; i < this._ReplyTo.Count; i++)
   3.190 +            {
   3.191 +                replyTo.Add(this.ReplyTo[i].ToCOMType());
   3.192 +            }
   3.193 +
   3.194              // SentOn
   3.195              sentSec = -1;
   3.196              if (this._SentOn != null)
   3.197 @@ -877,6 +896,7 @@
   3.198              result.LongMsgFormatted = this._LongMsgFormattedHtml;
   3.199              result.OptFields = optionalFields.ToArray();
   3.200              result.Recv = ((recvSec >= 0) ? recvSec : result.Recv);
   3.201 +            result.ReplyTo = replyTo.ToArray();
   3.202              result.Sent = ((sentSec >= 0) ? sentSec : result.Sent);
   3.203              result.ShortMsg = this._ShortMsg;
   3.204              result.To = to.ToArray();
   3.205 @@ -1002,6 +1022,24 @@
   3.206                  message.MessageId = pEpMessage.Id;
   3.207              }
   3.208  
   3.209 +            // ReplyTo
   3.210 +            for (int i = 0; i < pEpMessage.ReplyTo?.Count; i++)
   3.211 +            {
   3.212 +                try
   3.213 +                {
   3.214 +                    if (InternetAddress.TryParse(pEpMessage.ReplyTo[i].Address, out InternetAddress address))
   3.215 +                    {
   3.216 +                        address.Name = pEpMessage.ReplyTo[i].UserName;
   3.217 +                        message.ReplyTo.Add(address);
   3.218 +                    }
   3.219 +                }
   3.220 +                catch (Exception ex)
   3.221 +                {
   3.222 +                    status = Globals.ReturnStatus.Failure;
   3.223 +                    Log.Error("ToMIMEMessage: Error parsing ReplyTo identity. " + ex.ToString());
   3.224 +                }
   3.225 +            }
   3.226 +
   3.227              // Subject
   3.228              if (string.IsNullOrEmpty(pEpMessage.ShortMsg) == false)
   3.229              {
   3.230 @@ -1197,6 +1235,7 @@
   3.231                  Comparisons.Equals(this.PEPProtocolVersion, obj.PEPProtocolVersion) &&
   3.232                  Comparisons.Equals(this.Rating, obj.Rating) &&
   3.233                  Comparisons.Equals(this.ReceivedOn, obj.ReceivedOn) &&
   3.234 +                Comparisons.Equals(this.ReplyTo, obj.ReplyTo) &&
   3.235                  Comparisons.Equals(this.SentOn, obj.SentOn) &&
   3.236                  Comparisons.Equals(this.ShortMsg, obj.ShortMsg) &&
   3.237                  Comparisons.Equals(this.To, obj.To))
   3.238 @@ -1333,6 +1372,13 @@
   3.239                  copy.ReceivedOn = null;
   3.240              }
   3.241  
   3.242 +            // ReplyTo
   3.243 +            copy.ReplyTo.Clear();
   3.244 +            for (int i = 0; i < this._ReplyTo.Count; i++)
   3.245 +            {
   3.246 +                copy.ReplyTo.Add(this._ReplyTo[i].Copy());
   3.247 +            }
   3.248 +
   3.249              // SentOn
   3.250              if (this._SentOn != null)
   3.251              {
   3.252 @@ -1384,6 +1430,7 @@
   3.253              this._PEPProtocolVersion = null;
   3.254              this._Rating = pEpRating.pEpRatingUndefined;
   3.255              this._ReceivedOn = null;
   3.256 +            this._ReplyTo = new List<PEPIdentity>();
   3.257              this._SentOn = null;
   3.258              this._ShortMsg = null;
   3.259              this._To = new List<PEPIdentity>();
   3.260 @@ -1411,6 +1458,7 @@
   3.261              this.RaisePropertyChangedEvent(nameof(this.PEPProtocolVersion));
   3.262              this.RaisePropertyChangedEvent(nameof(this.Rating));
   3.263              this.RaisePropertyChangedEvent(nameof(this.ReceivedOn));
   3.264 +            this.RaisePropertyChangedEvent(nameof(this.ReplyTo));
   3.265              this.RaisePropertyChangedEvent(nameof(this.SentOn));
   3.266              this.RaisePropertyChangedEvent(nameof(this.ShortMsg));
   3.267              this.RaisePropertyChangedEvent(nameof(this.To));
   3.268 @@ -1640,7 +1688,7 @@
   3.269                              // Marshal.ReleaseComObject(newRecipient);
   3.270                              newRecipient = null;
   3.271                          }
   3.272 -                    }
   3.273 +                    }                    
   3.274                  }
   3.275  
   3.276                  /* Add the pEp From identity as its own recipient. This will be removed later.
   3.277 @@ -1801,6 +1849,29 @@
   3.278                          recipients.ResolveAll();
   3.279                      }
   3.280                      catch { }
   3.281 +                }                
   3.282 +
   3.283 +                // ReplyTo recipients
   3.284 +                recipients = omi.ReplyRecipients;
   3.285 +                while (recipients?.Count > 0)
   3.286 +                {
   3.287 +                    recipients.Remove(1);
   3.288 +                }
   3.289 +
   3.290 +                for (int i = 0; i < this._ReplyTo.Count; i++)
   3.291 +                {
   3.292 +                    if (string.IsNullOrWhiteSpace(this._ReplyTo[i].Address) == false)
   3.293 +                    {
   3.294 +                        // Add by address
   3.295 +                        newRecipient = recipients.Add(this._ReplyTo[i].Address);
   3.296 +                        newRecipient = null;
   3.297 +                    }
   3.298 +                    else if (string.IsNullOrWhiteSpace(this._ReplyTo[i].UserName) == false)
   3.299 +                    {
   3.300 +                        // Add by user name (required for distribution lists)
   3.301 +                        newRecipient = recipients.Add(this._ReplyTo[i].UserName);
   3.302 +                        newRecipient = null;
   3.303 +                    }
   3.304                  }
   3.305  
   3.306                  // Gather properties to set via MAPI
   3.307 @@ -1948,7 +2019,6 @@
   3.308                  {
   3.309                      // Note: ignore return status
   3.310                      propertiesToSet.AddPEPMessageProperty(nameof(PEPMessage.KeyList), this._KeyList);
   3.311 -                    propertiesToSet.AddPEPMessageProperty(nameof(PEPMessage.KeyImport), this._KeyImport);
   3.312  
   3.313                      // Only store rating once and never change it
   3.314                      if (omi.GetPEPProperty(MailItemExtensions.PEPProperty.Rating, out object storedRating) &&
   3.315 @@ -1961,6 +2031,7 @@
   3.316                  // Note: ignore return status
   3.317                  propertiesToSet.AddPEPMessageProperty(nameof(PEPMessage.AutoConsume), this._AutoConsume);
   3.318                  propertiesToSet.AddPEPMessageProperty(nameof(PEPMessage.ForceProtectionId), this._ForceProtectionId);
   3.319 +                propertiesToSet.AddPEPMessageProperty(nameof(PEPMessage.KeyImport), this._KeyImport);
   3.320                  propertiesToSet.AddPEPMessageProperty(nameof(PEPMessage.NeverUnsecure), this._NeverUnsecure);
   3.321                  propertiesToSet.AddPEPMessageProperty(nameof(PEPMessage.PEPProtocolVersion), this._PEPProtocolVersion);
   3.322  
   3.323 @@ -2375,6 +2446,16 @@
   3.324                      newMessage.ReceivedOn = null;
   3.325                  }
   3.326  
   3.327 +                // ReplyTo
   3.328 +                newMessage.ReplyTo.Clear();
   3.329 +                if (msg.ReplyTo != null)
   3.330 +                {
   3.331 +                    for (int i = 0; i < msg.ReplyTo.Length; i++)
   3.332 +                    {
   3.333 +                        newMessage.ReplyTo.Add(new PEPIdentity((pEpIdentity)msg.ReplyTo.GetValue(i)));
   3.334 +                    }
   3.335 +                }
   3.336 +
   3.337                  // SentOn
   3.338                  if (msg.Sent > 0)
   3.339                  {
   3.340 @@ -2528,6 +2609,28 @@
   3.341  
   3.342                      recipient = null;
   3.343                  }
   3.344 +
   3.345 +                recipients = omi.ReplyRecipients;
   3.346 +                for (int i = 1; i <= recipients.Count; i++)
   3.347 +                {
   3.348 +                    recipient = recipients[i];
   3.349 +                    sts = PEPIdentity.Create(recipient, out PEPIdentity ident);
   3.350 +                    if (sts == Globals.ReturnStatus.Success)
   3.351 +                    {
   3.352 +                        newMessage.ReplyTo.Add(ident);
   3.353 +                    }
   3.354 +                    else
   3.355 +                    {
   3.356 +                        // Update the status, only the first failure type is recorded
   3.357 +                        if (status == Globals.ReturnStatus.Success)
   3.358 +                        {
   3.359 +                            status = sts;
   3.360 +                        }
   3.361 +
   3.362 +                        Log.Error("PEPMessage.Create: Failure creating 'ReplyTo' identity.");
   3.363 +                    }
   3.364 +                }
   3.365 +
   3.366                  Log.Verbose("PEPMessage.Create: Recipients calculated, calculating main properties.");
   3.367  
   3.368                  if (onlyRecipientsAndDirection == false)
   3.369 @@ -2743,6 +2846,22 @@
   3.370                      else
   3.371                      {
   3.372                          newMessage.KeyImport = transportHeaders?.FirstOrDefault(a => (a.Field == PEPMessage.PR_PEP_KEY_IMPORT_NAME || a.Field == PEPMessage.PR_PEP_KEY_IMPORT_NAME_OLD))?.Value?.Trim();
   3.373 +
   3.374 +                        // Check backup solution with ReplyTo tunnel if needed
   3.375 +                        if (string.IsNullOrEmpty(newMessage.KeyImport) &&
   3.376 +                            (newMessage.ReplyTo?.Count > 0))
   3.377 +                        {
   3.378 +                            for (int i = 0; i < newMessage.ReplyTo.Count; i++)
   3.379 +                            {
   3.380 +                                string address = newMessage.ReplyTo[i].Address?.Trim();
   3.381 +                                if (address?.EndsWith(PEPMessage.PEPTUNNEL_MAIL_ADDRESS) == true)
   3.382 +                                {
   3.383 +                                    string keyImportFpr = address.Split('@')?.GetValue(0) as string;
   3.384 +                                    newMessage.KeyImport = keyImportFpr.ToUpperInvariant();
   3.385 +                                    break;
   3.386 +                                }
   3.387 +                            }
   3.388 +                        }
   3.389                      }
   3.390  
   3.391                      // Key list
     4.1 --- a/Properties/AssemblyInfo.cs	Fri Feb 22 17:01:56 2019 +0100
     4.2 +++ b/Properties/AssemblyInfo.cs	Tue Mar 05 14:45:53 2019 +0100
     4.3 @@ -46,5 +46,5 @@
     4.4  // You can specify all the values or you can default the Build and Revision Numbers 
     4.5  // by using the '*' as shown below:
     4.6  // [assembly: AssemblyVersion("1.0.*")]
     4.7 -[assembly: AssemblyVersion("1.0.208.0")]
     4.8 -[assembly: AssemblyFileVersion("1.0.208.0")]
     4.9 +[assembly: AssemblyVersion("1.0.209.0")]
    4.10 +[assembly: AssemblyFileVersion("1.0.209.0")]
     5.1 --- a/ThisAddIn.cs	Fri Feb 22 17:01:56 2019 +0100
     5.2 +++ b/ThisAddIn.cs	Tue Mar 05 14:45:53 2019 +0100
     5.3 @@ -790,12 +790,10 @@
     5.4          /// <param name="validateSendingAccount">Validates that the SendingAccount matches the From identity of the given message.
     5.5          /// This can catch situations (and throw exceptions) where the default account would be used instead.</param>
     5.6          /// <param name="processMessage">Whether or not to process this message through the pEp engine.</param>
     5.7 -        /// <param name="setKeyImportHeader">Whether or not to process this message through the pEp engine.</param>
     5.8          internal void CreateAndSendMessage(PEPMessage message,
     5.9                                             bool deleteAfterSend,
    5.10                                             bool validateSendingAccount,
    5.11 -                                           bool processMessage = false,
    5.12 -                                           bool setKeyImportHeader = false)
    5.13 +                                           bool processMessage = false)
    5.14          {
    5.15              Outlook.MailItem newItem;
    5.16              Globals.ReturnStatus sts;
    5.17 @@ -827,32 +825,11 @@
    5.18                      // Do not allow TNEF/RTF format with 'winmail.dat' attachment
    5.19                      MapiHelper.SetProperty(newItem, MapiProperty.PidLidUseTnef, false);
    5.20  
    5.21 -                    // If ForceUnencrypted property is set, add it to mail item
    5.22 -                    bool save = false;
    5.23 -                    if (message.ForceUnencrypted)
    5.24 +                    // If ForceUnencrypted property is set, add it to mail item (only if message is to be processed)
    5.25 +                    if (processMessage && 
    5.26 +                        message.ForceUnencrypted)
    5.27                      {
    5.28                          newItem.SetPEPProperty(MailItemExtensions.PEPProperty.ForceUnencrypted, true);
    5.29 -                        save = true;
    5.30 -                    }
    5.31 -
    5.32 -                    // Set KeyImport header if necessary
    5.33 -                    if (setKeyImportHeader)
    5.34 -                    {
    5.35 -                        newItem.SetPEPProperty(MailItemExtensions.PEPProperty.KeyImport, message.KeyImport);
    5.36 -                        save = true;
    5.37 -                    }
    5.38 -
    5.39 -                    // Save if necessary
    5.40 -                    if (save)
    5.41 -                    {
    5.42 -                        try
    5.43 -                        {
    5.44 -                            newItem.Save();
    5.45 -                        }
    5.46 -                        catch (Exception ex)
    5.47 -                        {
    5.48 -                            Log.Error("CreateAndSendMessage: Error saving new item. " + ex.ToString());
    5.49 -                        }
    5.50                      }
    5.51  
    5.52                      /* Send
    5.53 @@ -3339,6 +3316,12 @@
    5.54                          Log.Verbose("Application_ItemSend: Message already processed. Sending directly...");
    5.55                          return;
    5.56                      }
    5.57 +                    else if (processingState == MailItemExtensions.ProcessingState.ProcessedAvoidWinmailDat)
    5.58 +                    {
    5.59 +                        Log.Verbose("Application_ItemSend: Message already processed. Preventing Winmail.dat and sending directly...");
    5.60 +                        omi.AvoidWinmailDatAttachment();
    5.61 +                        return;
    5.62 +                    }
    5.63  
    5.64                      // Check for special cases
    5.65                      bool processMessage = true;
     6.1 --- a/UI/KeySyncWizard.xaml.cs	Fri Feb 22 17:01:56 2019 +0100
     6.2 +++ b/UI/KeySyncWizard.xaml.cs	Tue Mar 05 14:45:53 2019 +0100
     6.3 @@ -1559,7 +1559,6 @@
     6.4                          }
     6.5  
     6.6                          // Create basic message
     6.7 -                        bool processMessage = true;
     6.8                          PEPMessage message = new PEPMessage
     6.9                          {
    6.10                              From = this.Myself,
    6.11 @@ -1572,6 +1571,10 @@
    6.12                          };
    6.13                          message.To.Add(this.Partner);
    6.14  
    6.15 +                        // Tunnel the fingerprint also through the Reply-To field in the following format: <fingerprint>@peptunnel.com
    6.16 +                        string keyImportAddress = string.Concat(message.KeyImport, PEPMessage.PEPTUNNEL_MAIL_ADDRESS);
    6.17 +                        message.ReplyTo.Add(new PEPIdentity(keyImportAddress));
    6.18 +
    6.19                          Log.Verbose("SendSyncMessage: Basic message successfully created.");
    6.20  
    6.21                          // If message type isn't InitialMessage, encrypt it accordingly
    6.22 @@ -1581,7 +1584,16 @@
    6.23                          {
    6.24                              case MessageTypes.InitialMessage:
    6.25                                  {
    6.26 -                                    Log.Verbose("SendSyncMessage: Initial message. Won't encrypt.");
    6.27 +                                    if (msgProcessor.Encrypt(message, out msg, null, pEpEncryptFlags.pEpEncryptFlagDefault, pEpEncFormat.pEpEncNone))
    6.28 +                                    {
    6.29 +                                        Log.Verbose("SendSyncMessage: Initial message successfully created.");
    6.30 +                                        message = msg;
    6.31 +                                    }
    6.32 +                                    else
    6.33 +                                    {
    6.34 +                                        Log.Error("SendSyncMessage: Error creating initial message.");
    6.35 +                                        message = null;
    6.36 +                                    }
    6.37                                  }
    6.38                                  break;
    6.39                              case MessageTypes.PublicKeyMessage:
    6.40 @@ -1591,7 +1603,6 @@
    6.41                                      {
    6.42                                          Log.Verbose("SendSyncMessage: Public key message successfully created.");
    6.43                                          message = msg;
    6.44 -                                        processMessage = false;
    6.45                                      }
    6.46                                      else
    6.47                                      {
    6.48 @@ -1607,7 +1618,6 @@
    6.49                                      {
    6.50                                          Log.Verbose("SendSyncMessage: Private key message successfully created.");
    6.51                                          message = msg;
    6.52 -                                        processMessage = false;
    6.53                                      }
    6.54                                      else
    6.55                                      {
    6.56 @@ -1646,8 +1656,8 @@
    6.57                                  }
    6.58                              }
    6.59  
    6.60 -                            // Send message
    6.61 -                            Globals.ThisAddIn.CreateAndSendMessage(message, true, true, processMessage, true);
    6.62 +                            // Send message (do not process as it's already processed at this point)
    6.63 +                            Globals.ThisAddIn.CreateAndSendMessage(message, true, true, false);
    6.64  
    6.65                              // Log that message has been sent
    6.66                              this.sentMessages?.Add(messageType);
     7.1 --- a/pEpForOutlook.csproj	Fri Feb 22 17:01:56 2019 +0100
     7.2 +++ b/pEpForOutlook.csproj	Tue Mar 05 14:45:53 2019 +0100
     7.3 @@ -44,7 +44,7 @@
     7.4      <PublishUrl>publish\</PublishUrl>
     7.5      <InstallUrl>https://pep-project.org/</InstallUrl>
     7.6      <TargetCulture>en</TargetCulture>
     7.7 -    <ApplicationVersion>1.0.208.0</ApplicationVersion>
     7.8 +    <ApplicationVersion>1.0.209.0</ApplicationVersion>
     7.9      <AutoIncrementApplicationRevision>true</AutoIncrementApplicationRevision>
    7.10      <UpdateEnabled>true</UpdateEnabled>
    7.11      <UpdateInterval>0</UpdateInterval>