Changeset fbe7b71 in github


Ignore:
Timestamp:
Apr 24, 2012 3:26:04 PM (13 months ago)
Author:
alecpl <alec@…>
Branches:
master, HEAD, courier-fix, dev-browser-capabilities, pdo
Children:
76248c7
Parents:
db70b3f
Message:
  • Fix importing vCard photo with ENCODING param specified (#1488432)
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • CHANGELOG

    r19d5973 rfbe7b71  
    22=========================== 
    33 
     4- Fix importing vCard photo with ENCODING param specified (#1488432) 
    45- Add vCard import from multiple files at once (#1488015) 
    56- Roundcube Framework: 
  • program/include/rcube_vcard.php

    r0c25968 rfbe7b71  
    296296        if (strpos($value, 'http:') === 0) { 
    297297            // TODO: fetch file from URL and save it locally? 
    298             $this->raw['PHOTO'][0] = array(0 => $value, 'URL' => true); 
     298            $this->raw['PHOTO'][0] = array(0 => $value, 'url' => true); 
    299299        } 
    300300        else { 
    301             $encoded = !preg_match('![^a-z0-9/=+-]!i', $value); 
    302             $this->raw['PHOTO'][0] = array(0 => $encoded ? $value : base64_encode($value), 'BASE64' => true); 
     301            $this->raw['PHOTO'][0] = array(0 => $value, 'base64' => (bool) preg_match('![^a-z0-9/=+-]!i', $value)); 
    303302        } 
    304303        break; 
     
    553552        $entry = array(); 
    554553        $field = strtoupper($regs2[1][0]); 
     554        $enc   = null; 
    555555 
    556556        foreach($regs2[1] as $attrid => $attr) { 
     
    559559            if ($key == 'ENCODING') { 
    560560              // add next line(s) to value string if QP line end detected 
    561               while ($value == 'QUOTED-PRINTABLE' && preg_match('/=$/', $lines[$i])) 
     561              if ($value == 'QUOTED-PRINTABLE') { 
     562                while (preg_match('/=$/', $lines[$i])) 
    562563                  $line[2] .= "\n" . $lines[++$i]; 
    563  
    564               $line[2] = self::decode_value($line[2], $value); 
     564              } 
     565              $enc = $value; 
    565566            } 
    566             else 
    567               $entry[strtolower($key)] = array_merge((array)$entry[strtolower($key)], (array)self::vcard_unquote($value, ',')); 
     567            else { 
     568              $lc_key = strtolower($key); 
     569              $entry[$lc_key] = array_merge((array)$entry[$lc_key], (array)self::vcard_unquote($value, ',')); 
     570            } 
    568571          } 
    569572          else if ($attrid > 0) { 
    570             $entry[$key] = true;  // true means attr without =value 
     573            $entry[strtolower($key)] = true;  // true means attr without =value 
    571574          } 
    572575        } 
    573576 
    574         $entry = array_merge($entry, (array)self::vcard_unquote($line[2])); 
     577        // decode value 
     578        if ($enc || !empty($entry['base64'])) { 
     579          // save encoding type (#1488432) 
     580          if ($enc == 'B') { 
     581            $entry['encoding'] = 'B'; 
     582            // should we use vCard 3.0 instead? 
     583            // $entry['base64'] = true; 
     584          } 
     585          $line[2] = self::decode_value($line[2], $enc ? $enc : 'base64'); 
     586        } 
     587 
     588        if ($enc != 'B' && empty($entry['base64'])) { 
     589          $line[2] = self::vcard_unquote($line[2]); 
     590        } 
     591 
     592        $entry = array_merge($entry, (array) $line[2]); 
    575593        $data[$field][] = $entry; 
    576594      } 
     
    597615 
    598616      case 'base64': 
     617      case 'b': 
    599618        self::$values_decoded = true; 
    600619        return base64_decode($value); 
     
    628647          $value = array(); 
    629648          foreach($entry as $attrname => $attrvalues) { 
    630             if (is_int($attrname)) 
     649            if (is_int($attrname)) { 
     650              if (!empty($entry['base64']) || $entry['encoding'] == 'B') { 
     651                $attrvalues = base64_encode($attrvalues); 
     652              } 
    631653              $value[] = $attrvalues; 
    632             elseif ($attrvalues === true) 
    633               $attr .= ";$attrname";    // true means just tag, not tag=value, as in PHOTO;BASE64:... 
     654            } 
     655            else if (is_bool($attrvalues)) { 
     656              if ($attrvalues) { 
     657                $attr .= strtoupper(";$attrname");    // true means just tag, not tag=value, as in PHOTO;BASE64:... 
     658              } 
     659            } 
    634660            else { 
    635661              foreach((array)$attrvalues as $attrvalue) 
    636                 $attr .= ";$attrname=" . self::vcard_quote($attrvalue, ','); 
     662                $attr .= strtoupper(";$attrname=") . self::vcard_quote($attrvalue, ','); 
    637663            } 
    638664          } 
  • tests/vcards.php

    r0fbadeb rfbe7b71  
    4545     
    4646    $vcards = rcube_vcard::import($input); 
    47      
     47 
    4848    $this->assertEqual(2, count($vcards), "Detected 2 vcards"); 
    4949    $this->assertEqual("Apple Computer AG", $vcards[0]->displayname, "FN => displayname"); 
Note: See TracChangeset for help on using the changeset viewer.