#2579 Subject header line folding adds extra spaces

Compose (426)
Peter B

Whenever I send a mail with really long subject, Squirrelmail fails at the Subject header folding, and inserts extra spaces.

Example: I send the mail with subject: "this is a really really very long subject line to make a good example of what my problem is"

What squirrelmail sends out is this: (I replaced the spaces with underscore at the line break so that it is more visible, that there are a plenty of extra spaces added.)

Subject: this is a really really very long subject line to make a good_
_____example of what my problem is

According to RFC 2822, folding and unfolding should add and remove only the CRLF, and not the whitespaces.

I have the problem with 1.4.9a and 1.4.10a. (It's a production environment, I can't test other versions, unfortunately.) Others on the SQ mailing list confirmed the same error in version 1.4.13.

The extra spaces are NOT visible in SquirrelMail itself, just in other mail readers (Thunderbird e.g.), or in the message source itself.


  • Peter B

    Peter B - 2008-04-25

    Logged In: YES
    Originator: YES

    I located the error, it is in class/deliver/Deliver.class.php, in the foldLine function. As I don't understand every aspect of the code, I better not try to patch it myself, but I describe what I found:

    The foldLine function splits any line into pieces shorter than a given length, and the concatenates them with $fold_string, which is

    $fold_string = "\r\n " . $pre; // line 719

    The line where the pieces are concatenated:

    $line = implode($fold_string,$aFoldLine); // line 794

    $pre is a parameter, which is four spaces at every invocation of foldLine in Deliver.class.php.

    However this is wrong, as only "\r\n" should be inserted into the folded lines. (Meaning, that if there is no whitespace in a header, then it cannot be folded, as a folded line should be started with a whitespace.)

    The inserted spaces are not a problem where the header is just informative, and not visible for the basic users (Received: headers for example), but annoying with Subject: for example, where other clients doesn't remove the extra spaces. (Complying with the RFC.)

    The line numbers are from svn branches/SM-1_4-STABLE r13048.

    Hope it helps to fix for someone how knows the code better :)

  • Paul Lesniewski

    Paul Lesniewski - 2009-04-03

    Thank you very much for your report. I have just added a small patch that will help this problem to an extent (you will probably only notice ONE extra space instead of multiple extras).

    The real fix is to make a bigger change that has so far only been made in our development tree (that you run a production site does not stop you from installing another version in a parallel directory). You can try out version 1.5.2SVN snapshots with this fix and help assure us that it is solid and ready to be used in our stable branch.

    However, if you'd like to try an advanced copy of what that new code will look like in 1.4.x, you can use the class/deliver/Deliver.class.php file that I have attached to this tracker. It is branched from 1.4.18SVN.

  • Paul Lesniewski

    Paul Lesniewski - 2009-04-03

    Backport of foldLine fix from DEVEL to STABLE

  • Paul Lesniewski

    Paul Lesniewski - 2009-04-03

    Whether you try the small fix I just made in 1.4.18SVN, try the attached file in 1.4.x, or try 1.5.2SVN, PLEASE PLEASE PLEASE GIVE FEEDBACK.

  • Peter B

    Peter B - 2009-04-03


    Thanks for your reply!
    I currently won't be able to test the development version, but I could take a look at the Deliver.class.php you attached here. My current version is 1.4.15, from debian lenny, I copied the attached file there, replacing the original. The result is exactly what you predicted, that there is now only 1 extra space, which is much nicer, that it was before :)

    However, testing with the subject line I used in the original description and checking the message source with Thunderbird, I noticed that the Subject header is not folded at all, and thus it is longer than it is supposed to be. (There is something in the RFC on advised and mandatory header length constraints.) Then I checked again with the original Deliver.class.php, and saw that it didn't fold the subject either, just added the many spaces. Which might be caused by a debian patch though.

    Thanks again,

  • Paul Lesniewski

    Paul Lesniewski - 2009-04-04

    First, let's be clear that all of your testing is on a system now using the new version of Deliver.class.php from this tracker? AND you are testing with all NEW messages, not some sent before (which will still be broken)?

    Using the new file from this tracker should not create even one extra space - it should preserve your subject perfectly (at least in most MUAs). If not, please give an example of your subject and indicate what, if any, language you have SM set to.

    The hard line length limit is 998 characters; are you sure it's too long? If it's longer than the usual expected 78 characters, that's usually not a problem and indicates that you don't have any spaces in your subject. If I'm wrong, then you need to show the headers you are working with.

  • ryacketta

    ryacketta - 2010-06-22


    Does this change work for 1.4.19 and 1.4.20?

    Have copied the new file into the functions folder, restarted httpd and still see the broken line for Content-Type as well as the binary output of the docx file within the message body window.

    Here is a screen shot of the message source (top half) and message body (bottom) half from T-Bird on osx. The same holds true for using T-Bird under windows.


    On the plus side, the Content-Type line is correct and word is opened when the attachment is opened.


  • ryacketta

    ryacketta - 2010-06-22

    See no way to edit my post, so I'll post an update here.

    The folder I copied the new file to was SM/class/deliver and not SM/functions.

    The file was sent from SM and opened in T-Bird under OSX and Windows with the same results seen in the image.


  • Paul Lesniewski

    Paul Lesniewski - 2010-06-22

    The screen shot you show does not show any broken headers. They are in fact wrapped correctly. You don't technically need the copy of Deliver.class.php -- 1.4.19 should be OK the way it is.

    The problem you are seeing may not be related to this particular tracker issue at all. Your problem is that binary data from an attachment shows as the message body? You might want to open a new tracker for it and attach to it the full message source so we can reproduce the issue.

  • ryacketta

    ryacketta - 2010-06-23

    Yes one of or problems is the binary data from a docx file is displayed in the message body, also have the issue where we double click the attachment in T-Bird and it is opened in notepad. This appears to due to the fact that the Content-Type data appears to be on another line.

    If I send a docx from T-Bird to SM everything works as excepted, in reverse SM is fine bu T-Bird shows the symptoms in the screen shot.

    I'll gladly open another tracker


  • Paul Lesniewski

    Paul Lesniewski - 2010-06-23

    If you think that Thunderbird is choking due to a bad Content-Type header, please provide the actual message source. If that's the problem, this tracker issue might be the right place to discuss. However, from your screen-shot and knowing how SquirrelMail's headers are built, I do not believe there is any problem with that header. You might want to ask the Thunderbird community why it is choking on that header. (Note that multi-line headers are perfectly valid. If I were to venture a guess, Thunderbird is not first concatenating the full header and instead sees nothing after "Content-Type:" on the first line and baulks. But I'd think Thunderbird would be smarter than that, so the issue might be something completely different.)

  • Paul Lesniewski

    Paul Lesniewski - 2010-06-24

    The replacement copy of Deliver.class.php has fallen out of date. I have attached a new patch that should work with 1.4.19 (or so) and up.

  • Paul Lesniewski

    Paul Lesniewski - 2010-06-25

    After more thought, I believe yackettarj's issue is a small bug in SquirrelMail, which should be fixed by the application of the patch on this tracker.

  • Paul Lesniewski

    Paul Lesniewski - 2010-06-25
    • status: open --> closed-fixed

Log in to post a comment.