Jump to content

Issue Information

  • #000653

  • 0 - None Assigned

  • New


  • -

Issue Confirmations

  • Yes (0)No (0)

text part of emails can return line too long error

Posted by wdepot on 16 November 2013 - 23:31

Every now and then while sending an email using osCommerce we get the message bounced back to us with an error message like this:

failed after I sent the message.
Remote host said: 500 Line too long

After checking the internet I noticed that the maximum length per line defined for email messages is supposed to be 76 characters. Though most email servers seem to ignore this limitation obviously there are a few that don't.

After looking at the email class I see that is uses the mime class to actually set up the emails. Looking in the mime.php class files I found the following lines (around line 188 of the file) used when setting up the text portion of an email:

case '7bit':
return $data;

Obviously this does no length checking at all. I would suggest that both catalog and admin side mime.php class files should actually read like this instead:

case '7bit':
return wordwrap($data, 76, $this->lf, true);

That way emails will always be sent with lines no longer than the 76 characters they are supposed to have and no more bounced emails will occur due to lines that are too long.

Hi Kevin,

the wordwrap is not utf-8 safety function. I think we should do an mb_wordwrap() function for it.

Could you do a send test with these characters?


Multibyte split by 76 are not the same as ascii split. 76 are really 153 ascii characters

I used this function in mime class:
* wordwrap for utf8 encoded strings
* @param string $str
* @param integer $len
* @param string $what
* @return string
* @author Milian Wolff <mail@milianw.de>
function utf8_wordwrap($str, $width, $break, $cut = false) {
    if (!$cut) {
	    $regexp = '#^(?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){'.$width.',}\b#U';
    } else {
	    $regexp = '#^(?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){'.$width.'}#';
    if (function_exists('mb_strlen')) {
	    $str_len = mb_strlen($str,'UTF-8');
    } else {
	    $str_len = preg_match_all('/[\x00-\x7F\xC0-\xFD]/', $str, $var_empty);
    $while_what = ceil($str_len / $width);
    $i = 1;
    $return = '';
    while ($i < $while_what) {
	    preg_match($regexp, $str,$matches);
	    $string = $matches[0];
	    $return .= $string.$break;
	    $str = substr($str, strlen($string));
    return $return.$str;

in mime:
   case '7bit':
return $this->utf8_wordwrap($data, 76, $this->lf, true);

Thanks for the report