I'm looking for a part-time remote job.

Hire me

I'm the author of:

Mastering Redmine is a comprehensive guide with tips, tricks and best practices, and an easy-to-learn structure.

Check the book's project or

Buy the book

Social pages of the book:

By buying this book you also donate to Redmine (see this page).

Follow me:

Way to get custom field to not use template rendering when rendered by mailer?

Added by Ted Lilley about 9 years ago

I’ve got a custom string field which I’m using an erb template to render. I’m using the named form, where I convert a field named “Customer Email” into a mailto URL. In the issue view, this works great, since the user can click the customer’s email address and it prepopulates an email to the user by putting a bunch of the issue metadata into the mailto link. Things like the Subject line of the email get formatted with the issue number and other people getting cc’ed.

This all works great until someone updates an issue, at which point the watchers get the standard issue update. The mailer for the issue update get the same rendering for the custom field. In this case, that’s bad, since the mail is in plain text (it’s actually multipart I think, but they see the text), in which case the “Customer Email” field gets the full "<a href>” link and is basically unreadable. I’m trying to figure out how to selectively tell the extension not to render this field when being called by the mailer. Any ideas?

Replies (2)

RE: Way to get custom field to not use template rendering when rendered by mailer? - Added by Ted Lilley about 9 years ago

So it’s not what I thought. After more investigation, I’ve determined that the email rendering path in redmine is unfriendly to html-safe values. What that means is while I can have html in a template for a field value which renders correctly in the issue view in a browser, the same value will not render correctly for email. This is because the email rendering path concatenates the field value with strings which aren’t html-safe. When you use string operations which merge safe and unsafe strings, the resulting string is unsafe.

That’s why the email gets the escaped html for the field value. (<a href ... instead of <a href ...). The problem is that the functions which handle the rendering of field values for email live in the redmine core, not in a plugin. I’d either have to submit a patch to redmine or find a way to override the offending functions in redmine.

The offending redmine code is here: https://gist.github.com/binaryphile/7873836. While my value is correctly returned as html-safe by `show_value(value)`, using interpolation on it in the `email_issue_attributes` method turns it unsafe: `#{value.custom_field.name}: show_value(value)”.

It looks like the `join("\n”)` in `render_email_issue_attributes` also makes it unsafe.

I’m trying to figure it out, thought I’d just post my progress in case anyone else comes across the same issue.


    Terms of use | Privacy policy