roundcubemail/program/lib/Roundcube/rcube_vcard.php
public static function import($data)
    {
        $out = array();

        // check if charsets are specified (usually vcard version < 3.0 but this is not reliable)
        if (preg_match('/charset=/i', substr($data, 0, 2048))) {
            $charset = null;
        }
        // detect charset and convert to utf-8
        else if (($charset = self::detect_encoding($data)) && $charset != RCUBE_CHARSET) {
            $data = rcube_charset::convert($data, $charset);
            $data = preg_replace(array('/^[\xFE\xFF]{2}/', '/^\xEF\xBB\xBF/', '/^\x00+/'), '', $data); // also remove BOM
            $charset = RCUBE_CHARSET;
        }

        $vcard_block    = '';
        $in_vcard_block = false;

        foreach (preg_split("/[\r\n]+/", $data) as $line) {
            if ($in_vcard_block && !empty($line)) {
                $vcard_block .= $line . "\n";
            }

            $line = trim($line);

            if (preg_match('/^END:VCARD$/i', $line)) {
                // parse vcard
                $obj = new rcube_vcard($vcard_block, $charset, true, self::$fieldmap);
                // FN and N is required by vCard format (RFC 2426)
                // on import we can be less restrictive, let's addressbook decide
                if (!empty($obj->displayname) || !empty($obj->surname) || !empty($obj->firstname) || !empty($obj->email)) {
                    $out[] = $obj;
                }

                $in_vcard_block = false;
            }
            else if (preg_match('/^BEGIN:VCARD$/i', $line)) {
                $vcard_block    = $line . "\n";
                $in_vcard_block = true;
            }
        }

        return $out;
    }
public static function import($data)
    {
        $out = array();

        // check if charsets are specified (usually vcard version < 3.0 but this is not reliable)
        if (preg_match('/charset=/i', substr($data, 0, 2048))) {
            $charset = null;
        }
        // detect charset and convert to utf-8
        else if (($charset = self::detect_encoding($data)) && $charset != RCUBE_CHARSET) {
            $data = rcube_charset::convert($data, $charset);
            $data = preg_replace(array('/^[\xFE\xFF]{2}/', '/^\xEF\xBB\xBF/', '/^\x00+/'), '', $data); // also remove BOM
            $charset = RCUBE_CHARSET;
        }

        $vcard_block    = '';
        $in_vcard_block = false;

        foreach (preg_split("/[\r\n]+/", $data) as $line) {
            if ($in_vcard_block && !empty($line)) {
                $vcard_block .= $line . "\n";
            }

            $line = trim($line);

            if (preg_match('/^END:VCARD$/i', $line)) {
                // parse vcard
                $obj = new rcube_vcard($vcard_block, $charset, true, self::$fieldmap);
                // FN and N is required by vCard format (RFC 2426)
                // on import we can be less restrictive, let's addressbook decide
                if (!empty($obj->displayname) || !empty($obj->surname) || !empty($obj->firstname) || !empty($obj->email)) {
                    $out[] = $obj;
                }

                $in_vcard_block = false;
            }
            else if (preg_match('/^BEGIN:VCARD$/i', $line)) {
                $vcard_block    = $line . "\n";
                $in_vcard_block = true;
            }
        }

        return $out;
    }
public static function import ( $ data ) { $ out = array ( ) ; // check if charsets are specified (usually vcard version < 3.0 but this is not reliable) if ( preg_match ( '/charset=/i' , substr ( $ data , 0 , 2048 ) ) ) { $ charset = null ; } // detect charset and convert to utf-8 else if ( ( $ charset = self :: detect_encoding ( $ data ) ) && $ charset != RCUBE_CHARSET ) { $ data = rcube_charset :: convert ( $ data , $ charset ) ; $ data = preg_replace ( array ( '/^[\xFE\xFF]{2}/' , '/^\xEF\xBB\xBF/' , '/^\x00+/' ) , '' , $ data ) ; // also remove BOM $ charset = RCUBE_CHARSET ; } $ vcard_block = '' ; $ in_vcard_block = false ; foreach ( preg_split ( "/[\r\n]+/" , $ data ) as $ line ) { if ( $ in_vcard_block && ! empty ( $ line ) ) { $ vcard_block .= $ line . "\n" ; } $ line = trim ( $ line ) ; if ( preg_match ( '/^END:VCARD$/i' , $ line ) ) { // parse vcard $ obj = new rcube_vcard ( $ vcard_block , $ charset , true , self :: $ fieldmap ) ; // FN and N is required by vCard format (RFC 2426) // on import we can be less restrictive, let's addressbook decide if ( ! empty ( $ obj -> displayname ) || ! empty ( $ obj -> surname ) || ! empty ( $ obj -> firstname ) || ! empty ( $ obj -> email ) ) { $ out [ ] = $ obj ; } $ in_vcard_block = false ; } else if ( preg_match ( '/^BEGIN:VCARD$/i' , $ line ) ) { $ vcard_block = $ line . "\n" ; $ in_vcard_block = true ; } } return $ out ; }
Factory method to import a vcard file

@param string vCard file content

@return array List of rcube_vcard objects
Factory method to import a vcard file