[MGNLMAIL-47] MailTemplate configured parameters replaced by context parameters Created: 12/Oct/09  Updated: 16/Jan/15  Resolved: 02/Jan/15

Status: Closed
Project: Magnolia Mail Module
Component/s: Backend, Templates
Affects Version/s: None
Fix Version/s: 5.1.4, 5.2.2

Type: Bug Priority: Major
Reporter: Marco Collovati Assignee: Robert Šiška
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: File MgnlMailFactory.diff    
Template:
Patch included:
Yes
Acceptance criteria:
Empty
Task DoD:
[ ]* Doc/release notes changes? Comment present?
[ ]* Downstream builds green?
[ ]* Solution information and context easily available?
[ ]* Tests
[ ]* FixVersion filled and not yet released
[ ]  Architecture Decision Record (ADR)
Bug DoR:
[ ]* Steps to reproduce, expected, and actual results filled
[ ]* Affected version filled

 Description   

Maybe there is a bug in mail module working with parameters.

If you define a template with some parameters in mail module configuration and then you send an email replacing those parameters you lost the original values until you reload mail module.

The problem depends on the method getTemplate(String templateName) in MgnlMailFactory; BeanUtils.cloneBean(...) creates a shallow clone of the original MailTemplate object, so if we modify the parameters map in the cloned bean we are effectively working on the original Map.
I think the same happens with attachmentes

To reproduce

  • Create simple freemarker template

    Param1: ${param1!'Not defined'}
    Param2: ${param2!'Not defined'}
    Param3: ${param3!'Not defined'}

  • Configure the template under /modules/mail/config/templatesConfiguration

    myTemplate

    • parameters
      • param1 => Param1
      • param2 => Param2
      • param3 => Param3
    • from => ...
    • subject => ...
    • templateFile => path of the new template
    • type => freemarker
  • Use Tools -> Mail to send a test email using the new template myTemplate, without setting parameters
  • Send another mail setting the parameter param1 (param1=My test parameter)
  • Send another mail wihtout parameters

The first and the second email are correct. In the third email param1 has value "My test parameter" insted of "Param1"

A simple patch is attached


Generated at Mon Feb 12 06:03:06 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.