Fixed Mail template subjects with line breaks can break email

Sim

Well-known member
Affected version
2.1.10
If you create a mail template with a complex subject line which uses conditionals it can be easy to inadvertently introduce invalid characters such as line breaks and tabs into the email subject.

Some mail transports will not accept emails that have line breaks in subject lines.

It would make things more robust if non-valid characters (eg line breaks, tabs, etc) were stripped from the mail subject automatically.

Example:

HTML:
<mail:subject>
    <xf:if is="$testMode">{{ phrase('test_mode') }}</xf:if>
    {{ phrase('subject_line', {
        'board': $xf.options.boardTitle
    }) }}
</mail:subject>

... this will not send on some mail transports due to a new line and a tab character in the middle of the subject string.

We could try and get everything onto a single line - but the more complex the subject line is - the more unreadable it becomes.
 
To be specific - I was experiencing errors when sending via SparkPost - when I investigated, I traced it back to the change in subject line where an encoded line break + tab was introduced into the subject line and subsequently rejected by the SparkPost API.

I was able to work around it in my template - but it really should be avoided by stripping any invalid characters when we render the mail:subject tag.
 
invalid characters such as line breaks and tabs into the email subject.
These are valid, according to RFC5322.
Although, I don't disagree with xF best practice likely to be better to strip them.

encoded line break + tab was introduced into the subject line and subsequently rejected by the SparkPost API.
As per above, more a bug with SparkPost API if they're rejecting valid characters.
 
As per above, more a bug with SparkPost API if they're rejecting valid characters.

It may actually be the Swiftmail library encoding the characters which is causing the issues - I haven't tried sending a raw transmission to the SparkPost API to see if it chokes on newline or tab characters.
 
Thank you for reporting this issue, it has now been resolved. We are aiming to include any changes that have been made in a future XF release (2.2.0 RC2).

Change log:
Standardize spacing within email subjects for more consistent rendering
There may be a delay before changes are rolled out to the XenForo Community.
 
Back
Top Bottom