From: stekkel Date: Sun, 26 Nov 2006 21:29:46 +0000 (+0000) Subject: Bodystructure parsing fix X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=5d214084d2345f139149511911b647ed7fff2a88;p=squirrelmail.git Bodystructure parsing fix git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@11964 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- diff --git a/class/mime/Message.class.php b/class/mime/Message.class.php index 1c483001..68beb9db 100644 --- a/class/mime/Message.class.php +++ b/class/mime/Message.class.php @@ -658,14 +658,25 @@ class Message { } /** + * function parseQuote + * + * This extract the string value from a quoted string. After the end-quote + * character is found it returns the string. The offset $i when calling + * this function points to the first double quote. At the end it points to + * The ending quote. This function takes care of escaped double quotes. + * "some \"string\"" + * ^ ^ + * initial $i end position $i + * * @param string $read - * @param integer $i - * @return string - * @todo document me + * @param integer $i offset in $read + * @return string string inbetween the double quotes + * @author Marc Groot Koerkamp */ function parseQuote($read, &$i) { $s = ''; $iPos = ++$i; + $iPosStart = $iPos; while (true) { $iPos = strpos($read,'"',$iPos); if (!$iPos) break; @@ -673,6 +684,38 @@ class Message { $s = substr($read,$i,($iPos-$i)); $i = $iPos; break; + } else if ($iPos > 1 && $read{$iPos -1} == '\\' && $read{$iPos-2} == '\\') { + // This is an unique situation where the fast detection of the string + // fails. If the quote string ends with \\ then we need to iterate + // through the entire string to make sure we detect the unexcaped + // double quotes correctly. + $s = ''; + $bEscaped = false; + $k = 0; + for ($j=$iPosStart,$iCnt=strlen($read);$j<$iCnt;++$j) { + $cChar = $read{$j}; + switch ($cChar) { + case '\\': + $bEscaped = !$bEscaped; + $s .= $cChar; + break; + case '"': + if ($bEscaped) { + $s .= $cChar; + $bEscaped = false; + } else { + $i = $j; + break 3; + } + break; + default: + if ($bEscaped) { + $bEscaped = false; + } + $s .= $cChar; + break; + } + } } ++$iPos; if ($iPos > strlen($read)) {