Bläddra i källkod

charset encode/decode changes related to email addresses

stekkel 22 år sedan
förälder
incheckning
d66fd1ad2f
1 ändrade filer med 13 tillägg och 12 borttagningar
  1. 13 12
      class/deliver/Deliver.class.php

+ 13 - 12
class/deliver/Deliver.class.php

@@ -226,7 +226,6 @@ class Deliver {
     }    
     }    
 
 
     function prepareRFC822_Header($rfc822_header, $reply_rfc822_header, &$raw_length) {
     function prepareRFC822_Header($rfc822_header, $reply_rfc822_header, &$raw_length) {
-
 	global $domain, $version, $username;
 	global $domain, $version, $username;
 
 
 	/* if server var SERVER_NAME not available, use $domain */
 	/* if server var SERVER_NAME not available, use $domain */
@@ -241,6 +240,7 @@ class Deliver {
 	sqGetGlobalVar('HTTP_X_FORWARDED_FOR', $HTTP_X_FORWARDED_FOR, SQ_SERVER);
 	sqGetGlobalVar('HTTP_X_FORWARDED_FOR', $HTTP_X_FORWARDED_FOR, SQ_SERVER);
 
 
 	$rn = "\r\n";
 	$rn = "\r\n";
+
 	/* This creates an RFC 822 date */
 	/* This creates an RFC 822 date */
 	$date = date('D, j M Y H:i:s ', mktime()) . $this->timezone();
 	$date = date('D, j M Y H:i:s ', mktime()) . $this->timezone();
 	/* Create a message-id */
 	/* Create a message-id */
@@ -342,6 +342,8 @@ class Deliver {
 	for ($i = 0 ; $i < $cnt ; $i++) {
 	for ($i = 0 ; $i < $cnt ; $i++) {
     	    $hdr_s .= $this->foldLine($header[$i], 78, str_pad('',4));
     	    $hdr_s .= $this->foldLine($header[$i], 78, str_pad('',4));
 	}
 	}
+//	$debug = "Debug: <123456789012345678901234567890123456789012345678901234567890123456789>\r\n";
+//	$this->foldLine($debug, 78, str_pad('',4));
 	$header = $hdr_s;
 	$header = $hdr_s;
 	$header .= $rn; /* One blank line to separate header and body */
 	$header .= $rn; /* One blank line to separate header and body */
 	$raw_length += strlen($header);
 	$raw_length += strlen($header);
@@ -362,11 +364,11 @@ class Deliver {
             while (strlen($line) > $length) {
             while (strlen($line) > $length) {
                 $fold = false;
                 $fold = false;
                 /* handle encoded parts */
                 /* handle encoded parts */
-                if (preg_match('/(=\?.+\?.+\?.+\?=)/',$line,$regs)) {
+                if (preg_match('/(=\?([^?]*)\?(Q|B)\?([^?]*)\?=)(.*)/Ui',$line,$regs)) {
                     $fold_tmp = $regs[1];
                     $fold_tmp = $regs[1];
                     $iPosEnc = strpos($line,$fold_tmp);
                     $iPosEnc = strpos($line,$fold_tmp);
                     $iLengthEnc = strlen($fold_tmp);
                     $iLengthEnc = strlen($fold_tmp);
-                    if ($iPosEnc < $length && ($iPosEnc + $iLengthEnc > $length)) {
+                    if ($iPosEnc < $length && (($iPosEnc + $iLengthEnc) > $length)) {
                         $fold = true;
                         $fold = true;
                         /* fold just before the start of the encoded string */
                         /* fold just before the start of the encoded string */
                         $aFoldLine[] = substr($line,0,$iPosEnc);
                         $aFoldLine[] = substr($line,0,$iPosEnc);
@@ -377,18 +379,16 @@ class Deliver {
                         }
                         }
                         if ($iLengthEnc > $length) { /* place the encoded
                         if ($iLengthEnc > $length) { /* place the encoded
                             string on a separate line and do not fold inside it*/
                             string on a separate line and do not fold inside it*/
-                            if ($iLengthEnc < (998 - strlen($fold_string))) { 
-                                $aFoldLine[] = substr($line,0,$iLengthEnc);
-                                $line = substr($line,$iLengthEnc);
-                            } else { /* line is too long, continue with normal folding */
-                                $fold = false;
-                            }
-                        }
+                            /* minimize foldstring */
+                            $fold_string = "\r\n ";
+                            $aFoldLine[] = substr($line,0,$iLengthEnc);
+                            $line = substr($line,$iLengthEnc);
+                        } 
                     } else { /* the encoded string fits into the foldlength */
                     } else { /* the encoded string fits into the foldlength */
                         /*remainder */
                         /*remainder */
                         $iPosEncEnd = $iPosEnc+$iLengthEnc;
                         $iPosEncEnd = $iPosEnc+$iLengthEnc;
                         $sLineRem = substr($line,$iPosEncEnd,$length - $iPosEncEnd);
                         $sLineRem = substr($line,$iPosEncEnd,$length - $iPosEncEnd);
-                        if (!preg_match('/[=,;\s]/',$sLineRem)) {
+                        if (preg_match('/(=\?([^?]*)\?(Q|B)\?([^?]*)\?=)(.*)/Ui',$slineRem) || !preg_match('/[=,;\s]/',$sLineRem)) {
                             /*impossible to fold clean in the next part -> fold after the enc string */
                             /*impossible to fold clean in the next part -> fold after the enc string */
                             $aFoldLine[] = substr($line,0,$iPosEncEnd+1);
                             $aFoldLine[] = substr($line,0,$iPosEncEnd+1);
                             $line = substr($line,$iPosEncEnd+1);
                             $line = substr($line,$iPosEncEnd+1);
@@ -397,7 +397,7 @@ class Deliver {
                                 $bFirstFold = true;
                                 $bFirstFold = true;
                                 $length -= strlen($fold_string);
                                 $length -= strlen($fold_string);
                             }
                             }
-                        }
+                        } 
                     }
                     }
                 }
                 }
                 if (!$fold) {
                 if (!$fold) {
@@ -430,6 +430,7 @@ class Deliver {
             }
             }
             $line = implode($fold_string,$aFoldLine);
             $line = implode($fold_string,$aFoldLine);
         }
         }
+        
         return $line."\r\n";
         return $line."\r\n";
     }
     }