MessageTokenProvider HtmlEncodes the subject

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
12 years ago
In 2.0 (not sure if this has been fixed by now) the subject is HtmlEncoded as well as all the tokens are encoded.
The problem is that the subject isn't sent as Html, it's sent as clear text (at least I think this is always true).

An idea might be to remove the HtmlEncode from the MessageTokenProvieder and then just do this in the Tokenizer:


        public string Replace(string template, IEnumerable<Token> tokens, bool htmlEncode)
        {
            if (string.IsNullOrWhiteSpace(template))
                throw new ArgumentNullException("template");

            if (tokens == null)
                throw new ArgumentNullException("tokens");

            foreach (var token in tokens)
            {
                string tokenValue = token.Value;
                if(htmlEncode)
                       tokenValue = HttpUtility.HtmlEncode(tokenValue);
                template = Replace(template, String.Format(@"%{0}%", token.Key),  tokenValue);
            }
            return template;

        }


And then in WorkflowMessageService in SendNotification

private int SendNotification(MessageTemplate messageTemplate,
            EmailAccount emailAccount, int languageId, IEnumerable<Token> tokens,
            string toEmailAddress, string toName)
        {
            //retrieve localized message template data
            var bcc = messageTemplate.GetLocalized((mt) => mt.BccEmailAddresses, languageId);
            var subject = messageTemplate.GetLocalized((mt) => mt.Subject, languageId);
            var body = messageTemplate.GetLocalized((mt) => mt.Body, languageId);

            //Replace subject and body tokens
            var subjectReplaced = _tokenizer.Replace(subject, tokens, false);
            var bodyReplaced = _tokenizer.Replace(body, tokens, true);
            
            var email = new QueuedEmail()
            {
                Priority = 5,
                From = emailAccount.Email,
                FromName = emailAccount.DisplayName,
                To = toEmailAddress,
                ToName = toName,
                CC = string.Empty,
                Bcc = bcc,
                Subject = subjectReplaced,
                Body = bodyReplaced,
                CreatedOnUtc = DateTime.UtcNow,
                EmailAccountId = emailAccount.Id
            };

            _queuedEmailService.InsertQueuedEmail(email);
            return email.Id;
        }
12 years ago
Thanks for info! I'll create a work item for this task
12 years ago
a.m. wrote:
Thanks for info! I'll create a work item for this task


Regarding your comment on that the default message templates do not contain any properties which can cause any issues. Consider a storename with åäö in it. That would make  the subject contain:
&#229;&#228;&#246;
12 years ago
You're absolutely right. Thanks!
12 years ago
a.m. wrote:
You're absolutely right. Thanks!

Great, love the way you guys handle bug reports :)
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.