alecpl
2011-04-22 99fc468d40ec342c05be2aec3a0adb6b2d2820fb
- Fix quoting special characters, small optimizations


1 files modified
60 ■■■■ changed files
program/include/rcube_vcard.php 60 ●●●● patch | view | raw | blame | history
program/include/rcube_vcard.php
@@ -497,14 +497,16 @@
   */
  private static function vcard_decode($vcard)
  {
    // Perform RFC2425 line unfolding
    // Perform RFC2425 line unfolding and split lines
    $vcard = preg_replace(array("/\r/", "/\n\s+/"), '', $vcard);
    $lines = preg_split('/\r?\n/', $vcard);
    $lines = explode("\n", $vcard);
    $data = array();
    
    for ($i=0; $i < count($lines); $i++) {
      if (!preg_match('/^([^\\:]*):(.+)$/', $lines[$i], $line))
      if (!preg_match('/^([^:]+):(.+)$/', $lines[$i], $line))
        continue;
      if (preg_match('/^(BEGIN|END)$/i', $line[1]))
          continue;
      // convert 2.1-style "EMAIL;internet;home:" to 3.0-style "EMAIL;TYPE=internet;TYPE=home:"
@@ -514,7 +516,7 @@
          $line[1] .= ';' . (strpos($prop, '=') ? $prop : 'TYPE='.$prop);
      }
      if (!preg_match('/^(BEGIN|END)$/i', $line[1]) && preg_match_all('/([^\\;]+);?/', $line[1], $regs2)) {
      if (preg_match_all('/([^\\;]+);?/', $line[1], $regs2)) {
        $entry = array();
        $field = strtoupper($regs2[1][0]);
@@ -543,28 +545,6 @@
    unset($data['VERSION']);
    return $data;
  }
  /**
   * Split quoted string
   *
   * @param string vCard string to split
   * @param string Separator char/string
   * @return array List with splitted values
   */
  private static function vcard_unquote($s, $sep = ';')
  {
    // break string into parts separated by $sep, but leave escaped $sep alone
    if (count($parts = explode($sep, strtr($s, array("\\$sep" => "\007")))) > 1) {
      foreach($parts as $s) {
        $result[] = self::vcard_unquote(strtr($s, array("\007" => "\\$sep")), $sep);
      }
      return $result;
    }
    else {
      return strtr($s, array("\r" => '', '\\\\' => '\\', '\n' => "\n", '\,' => ',', '\;' => ';', '\:' => ':'));
    }
  }
@@ -648,7 +628,29 @@
      return(implode($sep, (array)$r));
    }
    else {
      return strtr($s, array('\\' => '\\\\', "\r" => '', "\n" => '\n', ';' => '\;', ':' => '\:'));
      return strtr($s, array('\\' => '\\\\', "\r" => '', "\n" => '\n', ',' => '\,', ';' => '\;'));
    }
  }
  /**
   * Split quoted string
   *
   * @param string vCard string to split
   * @param string Separator char/string
   * @return array List with splitted values
   */
  private static function vcard_unquote($s, $sep = ';')
  {
    // break string into parts separated by $sep, but leave escaped $sep alone
    if (count($parts = explode($sep, strtr($s, array("\\$sep" => "\007")))) > 1) {
      foreach($parts as $s) {
        $result[] = self::vcard_unquote(strtr($s, array("\007" => "\\$sep")), $sep);
      }
      return $result;
    }
    else {
      return strtr($s, array("\r" => '', '\\\\' => '\\', '\n' => "\n", '\N' => "\n", '\,' => ',', '\;' => ';'));
    }
  }
@@ -700,5 +702,3 @@
  }
}