Exemple #1
0
        private TypedMailTemplate PrepareTemplate(string culture, bool renderText)
        {
            TypedMailTemplate template = null;

            if (renderText)
            {
                if (templatePlain == null)
                {
                    templatePlain = TypedMailTemplate.FromName(TypedMailTemplate.GetNameFromMailType(MailType) + "Plain");
                    templatePlain.Initialize(culture.Substring(3), Organization.Identity, this, (renderText ? "Plain" : ""));
                    templatePlain.PreparePlaceholders();
                }
                else
                {   //reuse the template, just reset the html to the saved version before replacements
                    templatePlain.Template.ResetContent();
                }
                template = templatePlain;
            }
            else
            {
                if (templateHtml == null)
                {
                    templateHtml = TypedMailTemplate.FromName(TypedMailTemplate.GetNameFromMailType(MailType));
                    templateHtml.Initialize(culture.Substring(3), Organization.Identity, this, (renderText ? "Plain" : ""));
                    templateHtml.PreparePlaceholders();
                }
                else
                {   //reuse the template, just reset the html to the saved version before replacements
                    templateHtml.Template.ResetContent();
                }
                template = templateHtml;
            }

            return(template);
        }
Exemple #2
0
        /// <summary>
        /// Renders the mail for a specific recipient
        ///
        /// </summary>
        /// <param name="recipient">The person to render for.</param>
        /// <param name="recipient">The culture to render for.</param>
        /// <param name="renderText">True if "Plain" template should be used (if available)</param>
        /// <returns>MailTemplate with proper replacements done</returns>
        ///
        public MailTemplate Render(IEmailPerson recipient, string culture, bool renderText)
        {
            lock (lockTemplates)
            {
                //Locking is needed since this is used in a multithreading scenario and the template is cached for efficiency

                TypedMailTemplate template = PrepareTemplate(culture, renderText); // Setup template and load serialized replacements
                template.FillIndividualPlaceholders(recipient);                    // Add recipient data
                template.InsertAllPlaceHoldersToTemplate();                        // Make all replacements
                this.Title = template.Template.TemplateTitleText;                  // Get the resulting title
                template.Template.TemplateBody = template.Template.TemplateBody;   // Force it to save Html
                return(new MailTemplate(template.Template));
            }
        }
        public void PreparePlaceholders()
        {
            TypedMailTemplate template    = this;
            Regex             reForumType = new Regex(@"(\[h.\])|(\[b\])|(\[i\])|(\[i\])|(\[blockquote\])|(\[br\])|(\[\/a\])",
                                                      RegexOptions.IgnoreCase);
            Regex reHtmlType = new Regex(@"(</[a-z1-4]+>)|(<[^>]+?/>)", RegexOptions.IgnoreCase);

            foreach (PlaceHolder ph in template.Placeholders.Values)
            {
                if (reHtmlType.IsMatch(ph.value))
                {
                    //contains HTML, try to strip dangerous features
                    try
                    {
                        HtmlDocument tempDoc = new HtmlDocument();
                        tempDoc.LoadHtml(ph.value);
                        HtmlNodeCollection scriptNodes = tempDoc.DocumentNode.SelectNodes("//script");
                        if (scriptNodes != null)
                        {
                            foreach (HtmlNode n in scriptNodes)
                            {
                                n.InnerHtml = "";
                            }
                        }
                        HtmlNodeCollection iframeNodes = tempDoc.DocumentNode.SelectNodes("//iframe");
                        if (iframeNodes != null)
                        {
                            foreach (HtmlNode n in iframeNodes)
                            {
                                n.SetAttributeValue("src", "");
                            }
                        }
                        HtmlNodeCollection onhandlers =
                            tempDoc.DocumentNode.SelectNodes("//*[starts-with(local-name(@*),'on')]");
                        if (onhandlers != null)
                        {
                            foreach (HtmlNode n in onhandlers)
                            {
                                foreach (HtmlAttribute att in n.Attributes)
                                {
                                    if (att.Name.ToLower().StartsWith("on"))
                                    {
                                        att.Value = "";
                                    }
                                }
                            }
                        }
                        ph.value = tempDoc.DocumentNode.InnerHtml;
                    }
                    catch
                    {
                    }
                }

                if (reForumType.IsMatch(ph.value))
                {
                    //Is Forum type formatting
                    ph.value = ConvertForumToHtml(ph.value);
                }
                if (!reHtmlType.IsMatch(ph.value))
                {
                    ph.value = ConvertPlainToHtml(ph.value);
                }
            }
        }
Exemple #4
0
 public void SendNotice (TypedMailTemplate mailtempl, int organizationId, bool asOfficer)
 {
     OutboundMail mail = mailtempl.CreateFunctionalOutboundMail(
             asOfficer ? MailAuthorType.PirateWeb : MailAuthorType.Service,
             OutboundMail.PriorityNormal, Organization.FromIdentity(organizationId),
             Geography.Root, DateTime.Now);
     mail.AddRecipient(this, asOfficer);
     mail.SetRecipientCount(1);
     mail.SetResolved();
     mail.SetReadyForPickup();
 }
Exemple #5
0
 public void SendNotice (TypedMailTemplate mailtempl, int organizationId)
 {
     SendNotice(mailtempl, organizationId, false);
 }
Exemple #6
0
 public void SendOfficerNotice (TypedMailTemplate mailtempl, int organizationId)
 {
     SendNotice(mailtempl, organizationId, true);
 }