Changeset 4657 in subversion


Ignore:
Timestamp:
Apr 15, 2011 11:26:16 AM (2 years ago)
Author:
thomasb
Message:

Fix vcard folding at 75 chars; don't fold vcards for internal storage

Location:
trunk/roundcubemail/program
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/roundcubemail/program/include/rcube_contacts.php

    r4584 r4657  
    552552            } 
    553553        } 
    554         $out['vcard'] = $vcard->export(); 
     554        $out['vcard'] = $vcard->export(false); 
    555555 
    556556        foreach ($this->table_cols as $col) { 
  • trunk/roundcubemail/program/include/rcube_vcard.php

    r4656 r4657  
    207207   * Convert the data structure into a vcard 3.0 string 
    208208   */ 
    209   public function export() 
    210   { 
    211     return self::rfc2425_fold(self::vcard_encode($this->raw)); 
     209  public function export($folded = true) 
     210  { 
     211    $vcard = self::vcard_encode($this->raw); 
     212    return $folded ? self::rfc2425_fold($vcard) : $vcard; 
    212213  } 
    213214   
     
    466467  private static function rfc2425_fold_callback($matches) 
    467468  { 
    468     // use mb string function if available 
    469     if (function_exists('mb_ereg_replace')) { 
    470       return ":\n " . mb_ereg_replace('(.{70})', "\\1\n ", $matches[1]); 
    471     } 
    472      
    473469    // chunk_split string and avoid lines breaking multibyte characters 
    474     $c = 66; 
    475     $out = ":\n " . substr($matches[1], 0, $c); 
     470    $c = 71; 
     471    $out .= substr($matches[1], 0, $c); 
    476472    for ($n = $c; $c < strlen($matches[1]); $c++) { 
    477       // break if length > 70 or mutlibyte character starts after position 66 
    478       if ($n > 70 || ($n > 66 && ord($matches[1][$c]) >> 6 == 3)) { 
    479         $out .= "\n "; 
     473      // break if length > 75 or mutlibyte character starts after position 71 
     474      if ($n > 75 || ($n > 71 && ord($matches[1][$c]) >> 6 == 3)) { 
     475        $out .= "\n  "; 
    480476        $n = 0; 
    481477      } 
     
    487483  } 
    488484 
    489   private static function rfc2425_fold($val) 
    490   { 
    491     return preg_replace_callback('/:([^\n]{72,})/', array('self', 'rfc2425_fold_callback'), $val) . "\n"; 
     485  public static function rfc2425_fold($val) 
     486  { 
     487    return preg_replace_callback('/([^\n]{72,})/', array('self', 'rfc2425_fold_callback'), $val); 
    492488  } 
    493489 
  • trunk/roundcubemail/program/steps/addressbook/export.inc

    r4501 r4657  
    3333  // we already have a vcard record 
    3434  if ($row['vcard']) { 
    35     echo $row['vcard'] . "\n"; 
     35    echo rcube_vcard::rfc2425_fold($row['vcard']) . "\n"; 
    3636  } 
    3737  // copy values into vcard object 
     
    4747    } 
    4848 
    49     echo $vcard->export() . "\n"; 
     49    echo $vcard->export(true) . "\n"; 
    5050  } 
    5151} 
Note: See TracChangeset for help on using the changeset viewer.