Some restructuring and comments OUT-453
authorThomas
Wed, 23 May 2018 15:33:56 +0200
branchOUT-453
changeset 2210505c19ee49d3
parent 2209 bebcde071bec
child 2211 7d2c2dd47c17
Some restructuring and comments
PEPAttachment.cs
PEPMessage.cs
     1.1 --- a/PEPAttachment.cs	Wed May 23 11:01:49 2018 +0200
     1.2 +++ b/PEPAttachment.cs	Wed May 23 15:33:56 2018 +0200
     1.3 @@ -42,7 +42,7 @@
     1.4          private string _FileName;
     1.5          private string _MimeType;
     1.6          private byte[] _Tag;
     1.7 -        private bool   _isInline;
     1.8 +
     1.9          private static object                       mutexCache              = new object();
    1.10          private static Dictionary<string, Icon>     iconCache               = new Dictionary<string, Icon>();
    1.11  
    1.12 @@ -140,13 +140,6 @@
    1.13           * 
    1.14           *************************************************************/
    1.15  
    1.16 -
    1.17 -        /// <summary>
    1.18 -        /// Gets if attachment is inline
    1.19 -        /// </summary>
    1.20 -        public bool IsInline { get { return this._isInline; } }
    1.21 -
    1.22 -
    1.23          /// <summary>
    1.24          /// Gets or sets the unique ID (within message) of the attachment.
    1.25          /// This matches a corresponding "cid:" URI schema reference in the HTML body of the Message object.
    1.26 @@ -756,8 +749,12 @@
    1.27          /// <param name="attachments">The Outlook attachments list to add this pEp attachments's data to.</param>
    1.28          /// <param name="defaultFileName">The default file name to use for the attachment if this filename is null 
    1.29          /// or whitespace.</param>
    1.30 +        /// <param name="setContentId">Whether to set the content id in the Outlook attachment. In some cases, where
    1.31 +        /// the attachment has a content id although it is no inline attachment, it can be necessary to not set the
    1.32 +        /// content id in order to guarantee the attachment's visibility in the UI.</param>
    1.33          public void AddTo(Outlook.Attachments attachments,
    1.34 -                          string defaultFileName = "attachment")
    1.35 +                          string defaultFileName = "attachment",
    1.36 +                          bool setContentId = true)
    1.37          {
    1.38              string tempFileName;
    1.39              string tempDir;
    1.40 @@ -829,8 +826,9 @@
    1.41                      MapiHelper.SetProperty(newAttachment, MapiProperty.PidTagAttachTag, this._Tag);
    1.42                  }
    1.43  
    1.44 -                // Set the content ID if attachment is inline
    1.45 -                if (string.IsNullOrWhiteSpace(this._ContentId) == false && _isInline == true)
    1.46 +                // Set the content ID
    1.47 +                if ((setContentId) &&
    1.48 +                    (string.IsNullOrWhiteSpace(this._ContentId) == false))
    1.49                  {
    1.50                      MapiHelper.SetProperty(newAttachment, MapiProperty.PidTagAttachContentId, this._ContentId);
    1.51                  }
    1.52 @@ -1052,27 +1050,5 @@
    1.53  
    1.54              return (data);
    1.55          }
    1.56 -
    1.57 -        /// <summary>
    1.58 -        /// Sets Inline field depending on ContentId presence in mail HTML body
    1.59 -        /// </summary>
    1.60 -        /// <param name="html"></param>
    1.61 -        public void SetInline(string html)
    1.62 -        {
    1.63 -            if(string.IsNullOrEmpty(this._ContentId) || string.IsNullOrEmpty(html))
    1.64 -            {
    1.65 -                this._isInline = false;
    1.66 -                return;
    1.67 -            }
    1.68 -
    1.69 -            if (html.Contains(this._ContentId))
    1.70 -            {
    1.71 -                this._isInline = true;
    1.72 -            }
    1.73 -            else
    1.74 -            {
    1.75 -                this._isInline = false;
    1.76 -            }
    1.77 -        }
    1.78      }
    1.79  }
     2.1 --- a/PEPMessage.cs	Wed May 23 11:01:49 2018 +0200
     2.2 +++ b/PEPMessage.cs	Wed May 23 15:33:56 2018 +0200
     2.3 @@ -1876,9 +1876,6 @@
     2.4                      }
     2.5                  }
     2.6  
     2.7 -                // Sets Inline field in all attachments depending on ContentId presence in mail HTML body 
     2.8 -                _Attachments.ForEach(a => a.SetInline(_LongMsgFormattedHtml));
     2.9 -
    2.10                  if (isPGPMIMEMsg)
    2.11                  {
    2.12                      PEPAttachment pgpMIME = this.ConvertToPGPMIMEAttachment();
    2.13 @@ -1918,7 +1915,15 @@
    2.14                      {
    2.15                          try
    2.16                          {
    2.17 -                            this._Attachments[i].AddTo(attachments, ("attachment" + i.ToString()));
    2.18 +                            /* OUT-453: In some cases, attachments have a content id although
    2.19 +                             * they are not inline attachments. In this case, setting the content
    2.20 +                             * id in the Outlook attachment can lead to it not being visible in the UI.
    2.21 +                             * Therefore, we only set the content id if the attachment really is inline.
    2.22 +                             */
    2.23 +                            string contentId = this._Attachments[i]?.ContentId;
    2.24 +                            bool setContentId = ((string.IsNullOrEmpty(contentId) == false) &&
    2.25 +                                                 (this._LongMsgFormattedHtml?.Contains(contentId) == true));
    2.26 +                            this._Attachments[i].AddTo(attachments, ("attachment" + i.ToString()), setContentId);
    2.27                          }
    2.28                          catch (Exception ex)
    2.29                          {