예제 #1
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);
        }
예제 #2
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));
        }
예제 #3
0
        private static string EmbedHeadScriptsAndStyles(string html, EndUserLicense userLicense)
        {
            string fixPositionScript        = ReadResourceFile(IOPath.Combine(SIConstants.DEFAULT_RESOURCE_FOLDER, "MailHtml/FixPositionScript.txt"));
            string restrictImagesWidthStyle = ReadResourceFile(IOPath.Combine(SIConstants.DEFAULT_RESOURCE_FOLDER, "MailHtml/RestrictImagesWidth.txt"));
            string preventTextResize        = ReadResourceFile(IOPath.Combine(SIConstants.DEFAULT_RESOURCE_FOLDER, "MailHtml/PreventTextResize.txt"));
            string preventTextCopy          = ReadResourceFile(IOPath.Combine(SIConstants.DEFAULT_RESOURCE_FOLDER, "MailHtml/PreventTextCopy.txt"));

            string headStartTag = Regex.Match(html, HTML_HEAD_START_TAG).Value;

            string styles = preventTextResize + restrictImagesWidthStyle;

            if (userLicense._Rights.Extract == false)
            {
                styles += preventTextCopy;
            }

            string modifiedHtml = html.Replace(headStartTag, headStartTag + styles + fixPositionScript);

            return(modifiedHtml);
        }
예제 #4
0
        public static string GeneratePermissionsHtml(string htmlContent, EndUserLicense eul)
        {
            List <string> permissions = new List <string>();

            if (eul._Rights.Extract)
            {
                permissions.Add("Extract");
            }
            if (eul._Rights.Forward)
            {
                permissions.Add("Forward");
            }
            if (eul._Rights.Reply)
            {
                permissions.Add("Reply");
            }
            if (eul._Rights.ReplyAll)
            {
                permissions.Add("Reply All");
            }
            if (eul._Rights.Print)
            {
                permissions.Add("Print");
            }

            string permissionList = "";

            foreach (string permission in permissions)
            {
                permissionList += "<li>" + permission + "</li>";
            }

            return(htmlContent
                   .Replace("[TEMPLATE_NAME]", eul.TemplateName)
                   .Replace("[DESCRIPTION]", eul.Description)
                   .Replace("[ISSUED_TO]", eul.IssuedTo)
                   .Replace("[OWNER]", eul.Owner)
                   .Replace("[RMS_RIGHTS]", permissionList));
        }
예제 #5
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));
        }