Changeset 510ca28 in github


Ignore:
Timestamp:
Sep 4, 2008 7:02:22 AM (5 years ago)
Author:
alecpl <alec@…>
Branches:
master, HEAD, courier-fix, dev-browser-capabilities, pdo, release-0.6, release-0.7, release-0.8
Children:
1518702
Parents:
30276ce
Message:
  • fix for \" and
    sequences in quoted strings
File:
1 edited

Legend:

Unmodified
Added
Removed
  • program/lib/mime.inc

    r1b5deba r510ca28  
    3333$MIME_OTHER = 7; 
    3434 
    35 function iml_ClosingParenPos($str, $start){ 
     35function iml_ClosingParenPos($str, $start) { 
    3636    $level=0; 
    3737    $len = strlen($str); 
    3838    $in_quote = 0; 
    39     for ($i=$start;$i<$len;$i++){ 
    40         if ($str[$i]=="\"") $in_quote = ($in_quote + 1) % 2; 
    41         if (!$in_quote){ 
     39 
     40    for ($i=$start; $i<$len; $i++) { 
     41        if ($str[$i] == '"' && $str[$i-1] != "\\") 
     42                $in_quote = ($in_quote + 1) % 2; 
     43        if (!$in_quote) { 
    4244                if ($str[$i]=="(") $level++; 
    4345                else if (($level > 0) && ($str[$i]==")")) $level--; 
     
    5254    $a = array(); 
    5355    $len = strlen($str); 
    54      
    5556    $in_quote = 0; 
    56     for ($i=0; $i<$len; $i++){ 
    57         if ($str[$i] == "\"") $in_quote = ($in_quote + 1) % 2; 
    58         else if (!$in_quote){ 
    59             if ($str[$i] == " "){ //space means new element 
     57 
     58    for ($i=0; $i<$len; $i++) { 
     59        if ($str[$i] == '"') { 
     60            $in_quote = ($in_quote + 1) % 2; 
     61        } else if (!$in_quote) { 
     62            if ($str[$i] == " ") { //space means new element 
    6063                $id++; 
    6164                while ($str[$i+1] == " ") $i++;  // skip additional spaces 
    62             } else if ($str[$i]=="("){ //new part 
     65            } else if ($str[$i]=="(") { //new part 
    6366                $i++; 
    6467                $endPos = iml_ClosingParenPos($str, $i); 
     
    6871                $a[$id] = iml_ParseBSString($part); //send part string 
    6972                $i = $endPos; 
    70             }else $a[$id].=$str[$i]; //add to current element in array 
    71         }else if ($in_quote){ 
    72             if ($str[$i]=="\\") $i++; //escape backslashes 
    73             else $a[$id].=$str[$i]; //add to current element in array 
     73            } else 
     74                $a[$id].=$str[$i]; //add to current element in array 
     75        } else if ($in_quote) { 
     76            if ($str[$i]=="\\") { 
     77                $i++; //escape backslashes 
     78                if ($str[$i] == '"' || $str[$i] == "\\") 
     79                    $a[$id] .= $str[$i]; 
     80            } else 
     81                $a[$id] .= $str[$i]; //add to current element in array 
    7482        } 
    7583    } 
     
    8290    $line=substr($str, 1, strlen($str) - 2); 
    8391    $line = str_replace(")(", ") (", $line); 
    84          
     92 
    8593        $struct = iml_ParseBSString($line); 
    8694        if ((strcasecmp($struct[0], "message")==0) && (strcasecmp($struct[1], "rfc822")==0)){ 
Note: See TracChangeset for help on using the changeset viewer.