[MGNLMAIL-40] When using ${type} and ${contentType} in the Form component E-Mail text, these values get overwritten. Created: 06/Nov/13  Updated: 24/Mar/22

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

Type: Improvement Priority: Neutral
Reporter: Christian Balaguer Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: maintenance
Remaining Estimate: 0d
Time Spent: 1h
Original Estimate: Not Specified

Template:
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)
Release notes required:
Yes
Documentation update required:
Yes
Date of First Response:

 Description   

To reproduce:

  1. create new form component
  2. add two textfields, one with the fieldname "type" and the other with the fieldname "contentType"
  3. add ${ type } and ${ contentType } to the email text in the form component dialog
  4. send the form
  5. in the mail text the values of those fields have been overwritten with "freemarker" and "html" or "text" depending on the mail type you configured

The problem lies in the method info.magnolia.module.mail.MgnlMailFactory#getEmailFromType

        Map<String, Object> newParams = new HashMap<String, Object>();
        newParams.putAll(params);
        if(!StringUtils.isEmpty(type)) {
            newParams.put(MailTemplate.MAIL_TYPE, type);
        }
        if(!StringUtils.isEmpty(contentType)) {
            newParams.put(MailTemplate.MAIL_CONTENT_TYPE, contentType);
        }
        return getEmail(newParams, attachments);

Here the parameters are overwritten, with the put() method.

The contentType param may not be that big of a problem, but recently one of our customers named one of its form fields "type" and was surprised to always get "freemarker" as value in the email text.


Improvement expectation:
Separate email built-in parameters with other params such as Form processor params so that customers won't have to mind about this issue.



 Comments   
Comment by Tobias Mattsson [ 04/Dec/13 ]

Moved to MGNLMAIL, the original affects version was 4.5.11.

Comment by Viet Nguyen [ 03/Aug/18 ]

We'll update our documentation regarding using of 'type' and 'contentType' in email template. Let's consider them as our provided 'context' objects which should not be used by end users.

Comment by Viet Nguyen [ 09/Aug/18 ]

All params will be 'merged' with MailTemplate.setValues(Map<String, Object>, List<MailAttachment>)
--> So all below named properties will be overriden by later values:

contentType,from,subject,to,mailTo,cc,type,parameters,attachments,body,html,templateFile,replyTo,bcc,username,password

This is Mail module current implementation, we can consider an improvement to support overlapping of parameter names resolution, for convenience, we'll directly change this ticket into an improvement ticket and update our documentation accordingly.

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