Ejemplo n.º 1
0
        public static void LoadImagesInHtml(DRMContent data)
        {
            string result = data.HTMLBody;
            List <RpmsgAttachment> notEmbeddedAttachments = new List <RpmsgAttachment>();

            try
            {
                foreach (RpmsgAttachment attachment in data.Attachments)
                {
                    if (attachment.ContentID == null || !result.Contains(attachment.ContentID))
                    {
                        notEmbeddedAttachments.Add(attachment);
                        continue;
                    }
                    string imgPath = IOPath.Combine(IOPath.GetTempPath(), Guid.NewGuid() + attachment.Name);
                    File.WriteAllBytes(imgPath, attachment.Content);

                    result = result.Replace("cid:" + attachment.ContentID, imgPath);
                }

                data.HTMLBody    = result;
                data.Attachments = notEmbeddedAttachments;
            }
            catch (Exception)
            {
                LogUtils.Log("Failed loading inline images for display");
            }
        }
Ejemplo n.º 2
0
        public static string AddHtmlHeaderAndAttachments(DRMContent drmContent, EndUserLicense userLicense)
        {
            string html = EmbedHeadScriptsAndStyles(drmContent.HTMLBody, userLicense);

            html = EmbedAttachments(html, drmContent, userLicense);
            html = AddMailDetailsHeader(html, drmContent, userLicense);
            return(html);
        }
Ejemplo n.º 3
0
        private static string AddMailDetailsHeader(string html, DRMContent drmContent, EndUserLicense userLicense)
        {
            if (userLicense._SIData == null)
            {
                return(html);
            }

            string headerHtml = ReadResourceFile(IOPath.Combine(SIConstants.DEFAULT_RESOURCE_FOLDER, "MailHtml/Header/MailDetailsHeader.txt"));
            string recipients = string.Join(", ", userLicense._SIData.ToNames);

            if (userLicense._SIData.CCNames.Length > 0)
            {
                recipients += ", " + string.Join(", ", userLicense._SIData.CCNames);
            }

            bool noAttachments = drmContent.Attachments.Count == 0;

            string base64AttachmentsIcon = null;

#if __IOS__
            UIImage attachmentsIcon = UIImage.FromFile("MailHtml/Header/attachmentsIcon.png");
            base64AttachmentsIcon = attachmentsIcon.AsPNG().GetBase64EncodedString(NSDataBase64EncodingOptions.None);
#endif

#if __ANDROID__
            Drawable shareIcon = ApplicationContext.Resources.GetDrawable(Resource.Drawable.attachmentsIcon);
            base64AttachmentsIcon = GetBase64EncodedFromDrawable(shareIcon);
#endif

            string attachmentsHtml = noAttachments ? "" : drmContent.Attachments.Count +
                                     "<img src=\"data:image/png;base64," + base64AttachmentsIcon + "\" alt=\"attachmentIcon\" style=\" height:0.9em; margin-top: 0.1em\" />";

            headerHtml = headerHtml
                         .Replace("[MailSubject]", userLicense._SIData.Subject)
                         .Replace("[SenderName]", userLicense._SIData.SenderName)
                         .Replace("[SendTime]", userLicense._SIData.SendTime)
                         .Replace("[RecipientNames]", recipients)
                         .Replace("[AttachmentCount]", attachmentsHtml)
                         .Replace("[SenderInitial]", userLicense._SIData.SenderName.Trim().Substring(0, 1).ToUpper());

            RpmsgClassification primaryClassification = userLicense._SIData.Classifications.Find(cls => cls.Color != null);

            //there is no classification with color
            if (primaryClassification == null && userLicense._SIData.Classifications.Count > 0)
            {
                //take the first dataclass
                primaryClassification = userLicense._SIData.Classifications[0];
            }

            if (primaryClassification != null)
            {
                headerHtml = headerHtml.Replace("<!--[ClassificationIndicator]-->", primaryClassification.GetClassificationHTML());
            }

            string bodyStartTag = Regex.Match(html, HTML_BODY_START_TAG).Value;
            return(html.Replace(bodyStartTag, bodyStartTag + headerHtml));
        }
Ejemplo n.º 4
0
        private static string EmbedAttachments(string html, DRMContent drmContent, EndUserLicense userLicense)
        {
            if (drmContent.Attachments == null)
            {
                return(html);
            }

            string bodyEndTag = Regex.Match(html, HTML_BODY_END_TAG).Value;
            string fixedDiv   = "<div id=\"si_bottomFixed_10BF6356-9C77-4EE2-8A0F-B0F2BEFBC225\" style=\"position:relative; bottom:0px; left:0px\" >";           //the id of the div MUST be the same as the ID in the attachmentFixPositionScript

            html = html.Replace(bodyEndTag, fixedDiv + bodyEndTag);

            foreach (RpmsgAttachment att in drmContent.Attachments)
            {
                string base64AppIcon   = null;
                string base64ShareIcon = null;

#if __IOS__
                UIImage appIcon = GetIconImageFromExtension(att.Extension);
                base64AppIcon = appIcon.AsPNG().GetBase64EncodedString(NSDataBase64EncodingOptions.None);

                UIImage shareIcon = UIImage.FromFile("MailHtml/Attachments/share.png");
                base64ShareIcon = shareIcon.AsPNG().GetBase64EncodedString(NSDataBase64EncodingOptions.None);
#endif

#if __ANDROID__
                Drawable appIcon = ApplicationContext.Resources.GetDrawable(Utils.GetIconIdFromExtension(att.Extension));
                base64AppIcon = GetBase64EncodedFromDrawable(appIcon);

                Drawable shareIcon = ApplicationContext.Resources.GetDrawable(Resource.Drawable.share);
                base64ShareIcon = GetBase64EncodedFromDrawable(shareIcon);
#endif

                html = html.Replace
                       (
                    bodyEndTag,
                    att.GetAttachmentHTML(base64AppIcon, base64ShareIcon) + bodyEndTag
                       );
            }

            return(html.Replace(bodyEndTag, "</div>" + bodyEndTag));
        }
Ejemplo n.º 5
0
        public static DRMContent Parse(byte[] drmContentBytes)
        {
            DRMContent drmContent = new DRMContent();

            using (MemoryStream ms = new MemoryStream(drmContentBytes))
            {
                using (CompoundFile cf = new CompoundFile(ms))
                {
                    byte[] OutlookBodyStreamInfoBytes = cf.RootStorage.GetStream(Stream_OutlookBodyStreamInfo).GetData();
                    Int16  bodyType = BitConverter.ToInt16(OutlookBodyStreamInfoBytes, 0);
                    Int32  codePage = BitConverter.ToInt32(OutlookBodyStreamInfoBytes, 2);

                    try
                    {
                        drmContent.HTMLBodyBytes = cf.RootStorage.GetStream(Stream_BodyPTHTML).GetData();
                    }
                    catch (Exception ex)
                    {
                        throw new InvalidDataException("No message body stream found", ex);
                    }

                    drmContent.HTMLBodyEncoding = AppUtils.GetEncoding(codePage);
                    string htmlBody = drmContent.HTMLBodyEncoding.GetString(drmContent.HTMLBodyBytes);

                    // wrap plain text with HTML tags
                    if (bodyType == 1)
                    {
                        htmlBody = "<html><head></head><body>" + htmlBody + "</body></html>";
                    }

                    drmContent.HTMLBody    = htmlBody;
                    drmContent.Attachments = RpmsgAttachment.CreateAttachmentsFromStorage(cf);
                    AppUtils.LoadImagesInHtml(drmContent);

                    LogUtils.Log("MsgRpmsgDecryptEnd");
                }
            }
            return(drmContent);
        }