Here we go again, another try to fix folding of headerlines with encoded
authorstekkel <stekkel@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Wed, 28 May 2003 22:08:07 +0000 (22:08 +0000)
committerstekkel <stekkel@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Wed, 28 May 2003 22:08:07 +0000 (22:08 +0000)
addresses

git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@4947 7612ce4b-ef26-0410-bec9-ea0150e637f0

class/deliver/Deliver.class.php

index abd24c09b4fb27ca53794cbfe1c57506d6ba2be9..3de308f1166b3c3606db91ddfa3d4338cb7d06e4 100644 (file)
@@ -369,7 +369,6 @@ class Deliver {
             default: $hdr_s .= $this->foldLine($header[$i], 78, str_pad('',4)); break;
             }
         }
-
         $header = $hdr_s;
         $header .= $rn; /* One blank line to separate header and body */
         $raw_length += strlen($header);
@@ -390,15 +389,20 @@ class Deliver {
             while (strlen($line) > $length) {
                 $fold = false;
                 /* handle encoded parts */
-                if (preg_match('/(=\?([^?]*)\?(Q|B)\?([^?]*)\?=)(.*)/Ui',$line,$regs)) {
+                if (preg_match('/(=\?([^?]*)\?(Q|B)\?([^?]*)\?=)(\s+|.*)/Ui',$line,$regs)) {
                     $fold_tmp = $regs[1];
+                    if (!trim($regs[5])) {
+                        $fold_tmp .= $regs[5];
+                    }
                     $iPosEnc = strpos($line,$fold_tmp);
                     $iLengthEnc = strlen($fold_tmp);
                     $iPosEncEnd = $iPosEnc+$iLengthEnc;
                     if ($iPosEnc < $length && (($iPosEncEnd) > $length)) {
                         $fold = true;
                         /* fold just before the start of the encoded string */
-                        $aFoldLine[] = substr($line,0,$iPosEnc);
+                        if ($iPosEnc) {
+                            $aFoldLine[] = substr($line,0,$iPosEnc);
+                        }
                         $line = substr($line,$iPosEnc);
                         if (!$bFirstFold) {
                             $bFirstFold = true;
@@ -416,8 +420,8 @@ class Deliver {
                         $sLineRem = substr($line,$iPosEncEnd,$length - $iPosEncEnd);
                         if (preg_match('/^(=\?([^?]*)\?(Q|B)\?([^?]*)\?=)(.*)/Ui',$sLineRem) || !preg_match('/[=,;\s]/',$sLineRem)) {
                             /*impossible to fold clean in the next part -> fold after the enc string */
-                            $aFoldLine[] = substr($line,0,$iPosEncEnd+1);
-                            $line = substr($line,$iPosEncEnd+1);
+                            $aFoldLine[] = substr($line,0,$iPosEncEnd);
+                            $line = substr($line,$iPosEncEnd);
                             $fold = true;
                             if (!$bFirstFold) {
                                 $bFirstFold = true;
@@ -456,7 +460,6 @@ class Deliver {
             }
             $line = implode($fold_string,$aFoldLine);
         }
-        
         return $line."\r\n";
     }