Whitespace breaking multipart emails

Operating System & Version
CentOS 7.9.2009
cPanel & WHM Version
96

Krydos

Well-Known Member
Jun 2, 2012
59
9
58
cPanel Access Level
Root Administrator
I'm using cPanel/WHM 96, CentOS 7.9.2009, PHP 8.0.7, Apache 2.4, and Exim 4.94.2.

When I send an email using the PHP mail() function in some code I wrote myself it send perfect multipart text/html emails that render correctly. When my Invision Community software sends an email it shows up as html code and the multipart boundaries aren't recognized. With the help of a nice guy over on serverfault he confirmed that the spaces I found at the start of the email headers would cause this.

Here is what my correct email headers look like:
Code:
MIME-Version: 1.0
From: "Example" <[email protected]>
List-Unsubscribe: <mailto:[email protected]>, <https://www.example.com/unsubscribe/?c=3d9795e2646d156972cdf58655c758bd
Content-type: multipart/alternative;boundary=helio60db72e0c0005
Message-Id: <[email protected]>
Date: Tue, 29 Jun 2021 19:22:08 +0000
X-AntiAbuse: This header was added to track abuse, please include it with any abuse report
Here's what the Invision Community emails look like. Note the single space in front of the From, Date, Auto-Submitted, and Content-Type headers:
Code:
MIME-Version: 1.0
 From: =?UTF-8?B?SGVsaW9OZXQ=?= <[email protected]>
 Date: Tue, 29 Jun 2021 19:04:36 +0000
 Auto-Submitted: auto-generated
 Content-Type: multipart/alternative; boundary="--==_mimepart_3d7970817fa277e018f1936f5865d582"; charset=UTF-8
 Content-Transfer-Encoding: 8bit
Message-Id: <[email protected]>
The serverfault guy said that a space at the front of a line like that is called folding whitespace and it is interpreted to a continuation of the line above rather than a new header line.

So, now that we know what the problem is, does anyone have any ideas of how to fix this?

I already contacted Invision and they've never seen anything like this on any of their customers. I was looking at this How to Customize the Exim System Filter File | cPanel & WHM Documentation Would it be possible to write a filter that watches for this whitespace and removes it? It's really strange to me that the same php version and the same user and the same everything with my code produces perfect emails, but the Invision php code does this. Obviously, everything else being equal, my first reaction was to ask Invision, but after several hours of going back and forth they insist there is nothing wrong with their code and something is broken on my server. Anyone have any ideas? Thanks!
 
Last edited by a moderator:

cPRex

Jurassic Moderator
Staff member
Oct 19, 2014
14,307
2,238
363
cPanel Access Level
Root Administrator
Hey there! It sounds like the homework you've done would show 100% the issue is with the software. I'm not sure how they could deny that with what you've shown.

There are some details in the Exim docs about spaces with line endings, but I didn't find much for extra spaces at the beginning of a line. See section 2 here:


The best way to workaround this would be for them to fix the application. I'm sure there is a custom way to capture the message and fix the headers before it gets sent, but that would be some very custom work and I don't have any ideas on how to implement that. It wouldn't be something that is available in cPanel tools, but you're correct that you'd likely need to explore the custom filter options.
 

Krydos

Well-Known Member
Jun 2, 2012
59
9
58
cPanel Access Level
Root Administrator
Thanks cPRex! Invision just keeps saying that their software sends emails just fine for thousands of other customers so it's got to be something wrong with my server. I'm obviously hesitant to try to fix their code for them because even if I managed to fix it it would probably just get overwritten each time I upgraded. The custom exim filters are a bit of a stretch. It would be much better to fix this at the source rather than writing some dirty hack to try to work around it.

Also, it's kind of funny that a moderator edited my post and removed the single spaces at the beginning of the headers...
 

Krydos

Well-Known Member
Jun 2, 2012
59
9
58
cPanel Access Level
Root Administrator
Thanks cPRex for the reassurance that the issue was with Invision's code. I spent way too much time digging through their code over the last few days, and I'm proud to announce that I fixed their code! I changed one occurrence of PHP_EOL to "\r\n" and now it works. Since Invision is so adamant that their code is perfect I guess I'll just have to make this edit every time I do a software upgrade. I'm so relieved to have this fixed though. It was driving me nuts. Just wanted to give this thread some closure in case anyone searches and finds it.