Skip to content

Sabre VObject Parser MimeDir

Evert Pot edited this page Sep 1, 2014 · 5 revisions

Sabre\VObject\Parser\MimeDir

MimeDir parser.

This class parses iCalendar/vCard files and returns an array.

The array is identical to the format jCard/jCal use.

Constants

OPTION_FORGIVING

const OPTION_FORGIVING = 1

OPTION_IGNORE_INVALID_LINES

const OPTION_IGNORE_INVALID_LINES = 2

Properties

$input

protected resource $input

The input stream.

  • Visibility: protected

$root

protected \Sabre\VObject\Component $root

Root component

  • Visibility: protected

$lineBuffer

protected null $lineBuffer

We need to look ahead 1 line every time to see if we need to 'unfold' the next line.

If that was not the case, we store it here.

  • Visibility: protected

$lineIndex

protected mixed $lineIndex

The real current line number.

  • Visibility: protected

$startLine

protected integer $startLine

In the case of unfolded lines, this property holds the line number for the start of the line.

  • Visibility: protected

$rawLine

protected string $rawLine

Contains a 'raw' representation of the current line.

  • Visibility: protected

$options

protected integer $options

Bitmask of parser options

  • Visibility: protected

Methods

parse

array Sabre\VObject\Parser\Parser::parse(mixed $input, integer|null $options)

This method starts the parsing process.

If the input was not supplied during construction, it's possible to pass it here instead.

If either input or options are not supplied, the defaults will be used.

Arguments

  • $input mixed
  • $options integer|null

setInput

void Sabre\VObject\Parser\Parser::setInput(mixed $input)

Sets the input data

Arguments

  • $input mixed

parseDocument

void Sabre\VObject\Parser\MimeDir::parseDocument()

Parses an entire document.

  • Visibility: protected

parseLine

\Sabre\VObject\Parser\Node Sabre\VObject\Parser\MimeDir::parseLine(string $line)

Parses a line, and if it hits a component, it will also attempt to parse the entire component

  • Visibility: protected

Arguments

  • $line string - <p>Unfolded line</p>

readLine

string Sabre\VObject\Parser\MimeDir::readLine()

Reads a single line from the buffer.

This method strips any newlines and also takes care of unfolding.

  • Visibility: protected

readProperty

void Sabre\VObject\Parser\MimeDir::readProperty($line)

Reads a property or component from a line.

  • Visibility: protected

Arguments

  • $line mixed

unescapeValue

string|array<mixed,string> Sabre\VObject\Parser\MimeDir::unescapeValue(string $input, string $delimiter)

Unescapes a property value.

vCard 2.1 says:

  • Semi-colons must be escaped in some property values, specifically ADR, ORG and N.
  • Semi-colons must be escaped in parameter values, because semi-colons are also use to separate values.
  • No mention of escaping backslashes with another backslash.
  • newlines are not escaped either, instead QUOTED-PRINTABLE is used to span values over more than 1 line.

vCard 3.0 says:

  • (rfc2425) Backslashes, newlines (\n or \N) and comma's must be escaped, all time time.
  • Comma's are used for delimeters in multiple values
  • (rfc2426) Adds to to this that the semi-colon MUST also be escaped, as in some properties semi-colon is used for separators.
  • Properties using semi-colons: N, ADR, GEO, ORG
  • Both ADR and N's individual parts may be broken up further with a comma.
  • Properties using commas: NICKNAME, CATEGORIES

vCard 4.0 (rfc6350) says:

  • Commas must be escaped.
  • Semi-colons may be escaped, an unescaped semi-colon may be a delimiter, depending on the property.
  • Backslashes must be escaped
  • Newlines must be escaped as either \N or \n.
  • Some compound properties may contain multiple parts themselves, so a comma within a semi-colon delimited property may also be unescaped to denote multiple parts within the compound property.
  • Text-properties using semi-colons: N, ADR, ORG, CLIENTPIDMAP.
  • Text-properties using commas: NICKNAME, RELATED, CATEGORIES, PID.

Even though the spec says that commas must always be escaped, the example for GEO in Section 6.5.2 seems to violate this.

iCalendar 2.0 (rfc5545) says:

  • Commas or semi-colons may be used as delimiters, depending on the property.
  • Commas, semi-colons, backslashes, newline (\N or \n) are always escaped, unless they are delimiters.
  • Colons shall not be escaped.
  • Commas can be considered the 'default delimiter' and is described as the delimiter in cases where the order of the multiple values is insignificant.
  • Semi-colons are described as the delimiter for 'structured values'. They are specifically used in Semi-colons are used as a delimiter in REQUEST-STATUS, RRULE, GEO and EXRULE. EXRULE is deprecated however.

Now for the parameters

If delimiter is not set (null) this method will just return a string. If it's a comma or a semi-colon the string will be split on those characters, and always return an array.

  • Visibility: public
  • This method is static.

Arguments

  • $input string
  • $delimiter string

unescapeParam

void Sabre\VObject\Parser\MimeDir::unescapeParam(string $input)

Unescapes a parameter value.

vCard 2.1:

  • Does not mention a mechanism for this. In addition, double quotes are never used to wrap values.
  • This means that parameters can simply not contain colons or semi-colons.

vCard 3.0 (rfc2425, rfc2426):

  • Parameters may be surrounded by double quotes.
  • If this is not the case, semi-colon, colon and comma may simply not occur (the comma used for multiple parameter values though).
  • If it is surrounded by double-quotes, it may simply not contain double-quotes.
  • This means that a parameter can in no case encode double-quotes, or newlines.

vCard 4.0 (rfc6350)

  • Behavior seems to be identical to vCard 3.0

iCalendar 2.0 (rfc5545)

  • Behavior seems to be identical to vCard 3.0

Parameter escaping mechanism (rfc6868) :

  • This rfc describes a new way to escape parameter values.

  • New-line is encoded as ^n

  • ^ is encoded as ^^.

  • " is encoded as ^'

  • Visibility: private

Arguments

  • $input string

extractQuotedPrintableValue

string Sabre\VObject\Parser\MimeDir::extractQuotedPrintableValue()

Gets the full quoted printable value.

We need a special method for this, because newlines have both a meaning in vCards, and in QuotedPrintable.

This method does not do any decoding.

  • Visibility: private

__construct

void Sabre\VObject\Parser\Parser::__construct(mixed $input, integer $options)

Creates the parser.

Optionally, it's possible to parse the input stream here.

Arguments

  • $input mixed
  • $options integer - <p>Any parser options (OPTION constants).</p>
Clone this wiki locally