]> git.donarmstrong.com Git - roundcube.git/blobdiff - program/include/rcube_vcard.php
Depends on php5-intl
[roundcube.git] / program / include / rcube_vcard.php
index 31797666ba1ee98016d611ded7a4386ab6a9b1bf..f574eed14a0d155ebb475aeecc9766ea4073a7a6 100644 (file)
@@ -5,7 +5,7 @@
  | program/include/rcube_vcard.php                                       |
  |                                                                       |
  | This file is part of the RoundCube Webmail client                     |
- | Copyright (C) 2008, RoundCube Dev. - Switzerland                      |
+ | Copyright (C) 2008-2009, RoundCube Dev. - Switzerland                 |
  | Licensed under the GNU GPL                                            |
  |                                                                       |
  | PURPOSE:                                                              |
@@ -226,10 +226,14 @@ class rcube_vcard
     return $vcard;
   }
 
+  private static function rfc2425_fold_callback($matches)
+  {
+    return ":\n  ".rtrim(chunk_split($matches[1], 72, "\n  "));
+  }
 
   private static function rfc2425_fold($val)
   {
-    return preg_replace('/:([^\n]{72,})/e', '":\n  ".rtrim(chunk_split("\\1", 72, "\n  "))', $val) . "\n";
+    return preg_replace_callback('/:([^\n]{72,})/', array('self', 'rfc2425_fold_callback'), $val) . "\n";
   }
 
 
@@ -259,15 +263,16 @@ class rcube_vcard
           $line[1] .= ';' . (strpos($prop, '=') ? $prop : 'TYPE='.$prop);
       }
 
-      if (!preg_match('/^(BEGIN|END)$/', $line[1]) && preg_match_all('/([^\\;]+);?/', $line[1], $regs2)) {
-        $entry = array('');
-        $field = $regs2[1][0];
+      if (!preg_match('/^(BEGIN|END)$/i', $line[1]) && preg_match_all('/([^\\;]+);?/', $line[1], $regs2)) {
+        $entry = array();
+        $field = strtoupper($regs2[1][0]);
 
         foreach($regs2[1] as $attrid => $attr) {
           if ((list($key, $value) = explode('=', $attr)) && $value) {
+           $value = trim($value);
             if ($key == 'ENCODING') {
-              # add next line(s) to value string if QP line end detected
-              while ($value == 'QUOTED-PRINTABLE' && ereg('=$', $lines[$i]))
+              // add next line(s) to value string if QP line end detected
+              while ($value == 'QUOTED-PRINTABLE' && preg_match('/=$/', $lines[$i]))
                   $line[2] .= "\n" . $lines[++$i];
               
               $line[2] = self::decode_value($line[2], $value);
@@ -276,17 +281,16 @@ class rcube_vcard
               $entry[strtolower($key)] = array_merge((array)$entry[strtolower($key)], (array)self::vcard_unquote($value, ','));
           }
           else if ($attrid > 0) {
-            $entry[$key] = true;  # true means attr without =value
+            $entry[$key] = true;  // true means attr without =value
           }
         }
 
-        $entry[0] = self::vcard_unquote($line[2]);
+        $entry = array_merge($entry, (array)self::vcard_unquote($line[2]));
         $data[$field][] = count($entry) > 1 ? $entry : $entry[0];
       }
     }
 
     unset($data['VERSION']);
-
     return $data;
   }
 
@@ -356,7 +360,7 @@ class rcube_vcard
             if (is_int($attrname))
               $value[] = $attrvalues;
             elseif ($attrvalues === true)
-              $attr .= ";$attrname";    # true means just tag, not tag=value, as in PHOTO;BASE64:...
+              $attr .= ";$attrname";    // true means just tag, not tag=value, as in PHOTO;BASE64:...
             else {
               foreach((array)$attrvalues as $attrvalue)
                 $attr .= ";$attrname=" . self::vcard_quote($attrvalue, ',');