Skip to content
Jennifer Programming Language

vcard API reference

Build and parse vCard (RFC 6350, vCard 4.0): a Card of contact fields encoded to a VCARD and parsed back. The contacts counterpart to ical - it shares the same content-line codec (TEXT escaping, 75-char line folding) through the included ical_vcard_shared.inc.j. Pure Jennifer over strings / lists; both binaries.

A Card carries a formatted name (FN), a full structured name (N: family / given / additional / prefixes / suffixes), a nickname, organisation / title, any number of emails / phones / addresses (each with an optional TYPE like work / home), a birthday, a photo URI, categories, a URL, and a note. encode writes FN and VERSION:4.0 and omits empty fields; parse reads one or many vCard 2.1 / 3.0 / 4.0 VCARDs, including the TYPE parameter on emails / phones / addresses, and throws a VcardError for malformed input. Text values are escaped / unescaped and long lines folded, so parse(encode(card)) round-trips.

Import with import "vcard.j" as vcard;. See the vcard guide for prose and examples.

Contents

NameWhat it is
addAddressA copy of the card with a postal address appended.
addCategoryA copy of the card with a category (CATEGORIES tag) appended.
addEmailA copy of the card with an email appended.
addEmailTypedA copy of the card with a TYPEd email appended (e.g.
addPhoneA copy of the card with a phone number appended.
addPhoneTypedA copy of the card with a TYPEd phone number appended (e.g.
addressA postal address.
addressTypedA postal address with a TYPE (e.g.
cardA card with just its formatted name (FN).
encodeRender a single card to vCard 4.0 text (a VCARD, CRLF-terminated).
encodeAllRender many cards to one vCard text (concatenated VCARDs).
parseParse vCard text into a list of Cards (one entry per VCARD).
withBdayA copy of the card with its birthday (BDAY) set.
withFullNameA copy of the card with its full structured name (N) set: family, given, additional (middle) name(s), and...
withNameA copy of the card with its structured name (N family / given) set.
withNicknameA copy of the card with its nickname (NICKNAME) set.
withNoteA copy of the card with its note set.
withOrgA copy of the card with its organisation and title set.
withPhotoA copy of the card with its photo (PHOTO) URI set.
withUrlA copy of the card with its URL set.
Addressstruct: A postal address (ADR).
Cardstruct: A contact card.
Typedstruct: A value with an optional TYPE parameter (e.g.
VcardErrorstruct: Malformed vCard text.

Functions

addAddress

jennifer
vcard.addAddress(c as Card, a as Address)

A copy of the card with a postal address appended.

c
the card
a
the address
Returns Card
a fresh card with the address added

addCategory

jennifer
vcard.addCategory(c as Card, category as string)

A copy of the card with a category (CATEGORIES tag) appended.

c
the card
category
the category tag
Returns Card
a fresh card with the category added

addEmail

jennifer
vcard.addEmail(c as Card, email as string)

A copy of the card with an email appended.

c
the card
email
the email address
Returns Card
a fresh card with the email added

addEmailTyped

jennifer
vcard.addEmailTyped(c as Card, email as string, type as string)

A copy of the card with a TYPEd email appended (e.g. type "work" / "home").

c
the card
email
the email address
type
the TYPE (e.g. "work" / "home"; "" for none)
Returns Card
a fresh card with the email added

addPhone

jennifer
vcard.addPhone(c as Card, phone as string)

A copy of the card with a phone number appended.

c
the card
phone
the phone number
Returns Card
a fresh card with the phone added

addPhoneTyped

jennifer
vcard.addPhoneTyped(c as Card, phone as string, type as string)

A copy of the card with a TYPEd phone number appended (e.g. type "cell").

c
the card
phone
the phone number
type
the TYPE (e.g. "work" / "home" / "cell"; "" for none)
Returns Card
a fresh card with the phone added

address

jennifer
vcard.address(
    street as string,
    locality as string,
    region as string,
    postalCode as string,
    country as string)

A postal address.

street
the street address
locality
the city / locality
region
the state / province / region
postalCode
the postal / ZIP code
country
the country name
Returns Address
the address

addressTyped

jennifer
vcard.addressTyped(
    street as string,
    locality as string,
    region as string,
    postalCode as string,
    country as string,
    type as string)

A postal address with a TYPE (e.g. "work" / "home").

street
the street address
locality
the city / locality
region
the state / province / region
postalCode
the postal / ZIP code
country
the country name
type
the TYPE ("work" / "home"; "" for none)
Returns Address
the address

card

jennifer
vcard.card(formattedName as string)

A card with just its formatted name (FN). Other fields are empty until set.

formattedName
the display name
Returns Card
the card

encode

jennifer
vcard.encode(c as Card)

Render a single card to vCard 4.0 text (a VCARD, CRLF-terminated). Empty optional fields are omitted.

c
the card to encode
Returns string
the vCard text

encodeAll

jennifer
vcard.encodeAll(cards as list of Card)

Render many cards to one vCard text (concatenated VCARDs).

cards
the cards to encode
Returns string
the vCard text

parse

jennifer
vcard.parse(text as string)

Parse vCard text into a list of Cards (one entry per VCARD). Accepts vCard 2.1, 3.0 and 4.0: unfolds folded lines, strips property group prefixes (item1.EMAIL reads as EMAIL), decodes 2.1 quoted-printable values (with their CHARSET), reads the TYPE parameter on EMAIL / TEL / ADR into Typed.type (other ;KEY=VALUE parameters are ignored), reads the structured N / ADR values, and unescapes text values.

text
the vCard text
Returns list of Card
the parsed cards (empty when the text is blank)
Throws VcardError
kind "vcard" for malformed input: text outside a BEGIN:VCARD ... END:VCARD, a card without END:VCARD, a nested BEGIN, a line without a :, an unknown VERSION, a 3.0 / 4.0 card without FN, or a bad quoted-printable value

withBday

jennifer
vcard.withBday(c as Card, bday as string)

A copy of the card with its birthday (BDAY) set. The value is stored verbatim (a YYYYMMDD date, or a partial date like --0315).

c
the card
bday
the birthday value
Returns Card
a fresh card with the birthday set

withFullName

jennifer
vcard.withFullName(
    c as Card,
    family as string,
    given as string,
    additional as string,
    prefixes as string,
    suffixes as string)

A copy of the card with its full structured name (N) set: family, given, additional (middle) name(s), and honorific prefixes / suffixes.

c
the card
family
the family (last) name
given
the given (first) name
additional
the additional (middle) name(s)
prefixes
the honorific prefixes (e.g. "Dr.")
suffixes
the honorific suffixes (e.g. "Jr.", "PhD")
Returns Card
a fresh card with the full name set

withName

jennifer
vcard.withName(c as Card, family as string, given as string)

A copy of the card with its structured name (N family / given) set. The additional (middle) name and honorific prefixes / suffixes are left empty; use withFullName to set all five components.

c
the card
family
the family (last) name
given
the given (first) name
Returns Card
a fresh card with the name set

withNickname

jennifer
vcard.withNickname(c as Card, nickname as string)

A copy of the card with its nickname (NICKNAME) set.

c
the card
nickname
the nickname
Returns Card
a fresh card with the nickname set

withNote

jennifer
vcard.withNote(c as Card, note as string)

A copy of the card with its note set.

c
the card
note
the note text
Returns Card
a fresh card with the note set

withOrg

jennifer
vcard.withOrg(c as Card, organization as string, title as string)

A copy of the card with its organisation and title set.

c
the card
organization
the organisation name
title
the job title
Returns Card
a fresh card with the org / title set

withPhoto

jennifer
vcard.withPhoto(c as Card, photo as string)

A copy of the card with its photo (PHOTO) URI set.

c
the card
photo
the photo URI
Returns Card
a fresh card with the photo set

withUrl

jennifer
vcard.withUrl(c as Card, url as string)

A copy of the card with its URL set.

c
the card
url
the URL
Returns Card
a fresh card with the URL set

Structs

Address

A postal address (ADR). The RFC's PO-box and extended components are not modelled; the five common fields are, plus an optional TYPE.

jennifer
def struct Address {
    street as string,
    locality as string,
    region as string,
    postalCode as string,
    country as string,
    type as string
};
street
the street address
locality
the city / locality
region
the state / province / region
postalCode
the postal / ZIP code
country
the country name
type
the TYPE parameter ("work" / "home" / ...; "" if none)

Card

A contact card.

jennifer
def struct Card {
    formattedName as string,
    family as string,
    given as string,
    additional as string,
    prefixes as string,
    suffixes as string,
    nickname as string,
    organization as string,
    title as string,
    emails as list of Typed,
    phones as list of Typed,
    addresses as list of Address,
    url as string,
    bday as string,
    photo as string,
    categories as list of string,
    note as string
};
formattedName
the FN display name (required by vCard 4.0)
family
the N family (last) name
given
the N given (first) name
additional
the N additional (middle) name(s)
prefixes
the N honorific prefixes (e.g. "Dr.")
suffixes
the N honorific suffixes (e.g. "Jr.", "PhD")
nickname
the NICKNAME ("" when unset)
organization
the ORG organisation ("" when unset)
title
the TITLE job title ("" when unset)
emails
the EMAIL addresses (each with an optional TYPE)
phones
the TEL phone numbers (each with an optional TYPE)
addresses
the ADR postal addresses
url
the URL ("" when unset)
bday
the BDAY birthday ("" when unset; a YYYYMMDD or partial date)
photo
the PHOTO URI ("" when unset)
categories
the CATEGORIES tags
note
the NOTE free-text note ("" when unset)

Typed

A value with an optional TYPE parameter (e.g. an email or phone marked work / home). type is "" when unspecified.

jennifer
def struct Typed {
    value as string,
    type as string
};
value
the property value (the email / phone number)
type
the TYPE parameter ("work" / "home" / "cell" / ...; "" if none)

VcardError

Malformed vCard text. Every error of kind "vcard" is one, so its fields are safe to read once the kind matches.

jennifer
def struct VcardError {
    kind as string,
    message as string,
    line as int
};
kind
always "vcard"
message
what is wrong, prefixed line N:
line
the 1-based physical line of parse's input the fault is on (a folded line counts from its first physical line)