For the record
stripEmptyLines() is defined in include/class.format.php. In version 1.6 RC5 it reads
function stripEmptyLines ( $string) {
//return preg_replace("/(^*|+)*+/", "\n", $string);
return preg_replace('/\s\s+/',"\n",$string);
}
@peter: It's rather apparent, that this removes much more than multiple empty lines. \s matches "any whitespace character".
@eagle00789: Your code features a typo (which also explains why it failed for scottro). A is missing:
Replace
preg_replace("/\n{3,}", "\n\n", $string);
with
preg_replace("/\n{3,}/", "\n\n", $string);
@scottro: Note that stripEmptyLines() is not just used in include/class.mailfetch.php. So, changing the function itself might be more convenient than removing all occurrences.
Personally, I think that squeezing multiple empty lines is worth considering.
Additionally, it might be an idea to remove empty lines at the start and end of a message. I haven't tested the following much but adding something like this to eagle's code should do
$string = preg_replace("/^\s*/", "", $string);
$string = preg_replace("/\s\s*$/", "\n", $string);
I tried to do it with a single preg_replace but failed :-/
The full code snippet then would be
// see http://osticket.com/forums/showthread.php?t=2522
function stripEmptyLines ( $string) {
//Make sure we are using the same linebreak style thru the entire text
$string = str_replace(array("\r\n", "\r"), array("\n", "\n"), $string);
//Remove whitespace at start and end of message
$string = preg_replace("/^\s*/", "", $string);
$string = preg_replace("/\s\s*$/", "\n", $string);
//Replace 3 or more linebreaks by 2
return preg_replace("/\n{3,}/", "\n\n", $string);
}
HTH.