vcard

package
v1.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 25, 2026 License: Apache-2.0 Imports: 19 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package vcard defines a vCard, a contact, such as a person or an organisation, which is encoded as vCard 4.0, and decoded from vCard 2.1, 3.0 or 4.0, and its photo, which can be embedded in it, as artwork. Reference: https://www.rfc-editor.org/rfc/rfc6350

Index

Constants

View Source
const (
	// OmitYear is the year of a birthday whose year isn't known, which is a
	// leap year, so the 29th of February is a date, as Apple's contacts
	// write it, with X-APPLE-OMIT-YEAR, so a calendar doesn't show an age
	OmitYear = 1604

	// BirthdayCategory is the category of a birthday's event
	BirthdayCategory = "Birthdays"
)
View Source
const ContentType = "text/vcard"

ContentType is the content type of a vCard

View Source
const (
	// MaxLineSize is the longest line which is read, once it's unfolded,
	// which includes a photo of several megabytes, as base64
	MaxLineSize = 16 << 20
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Address

type Address struct {
	Types      []string `json:"types,omitempty"`
	POBox      string   `json:"po_box,omitempty"`
	Extended   string   `json:"extended,omitempty"` // Such as a flat or suite
	Street     string   `json:"street,omitempty"`
	Locality   string   `json:"locality,omitempty"` // Such as a city
	Region     string   `json:"region,omitempty"`   // Such as a state or county
	PostalCode string   `json:"postal_code,omitempty"`
	Country    string   `json:"country,omitempty"`
}

Address is a postal address, with its types, such as home or work, in lower case

func (Address) String

func (a Address) String() string

String returns the parts of an address which aren't empty, separated with commas, such as 1 Main St, London, UK

type Card

type Card struct {
	UID        string         `json:"uid,omitempty"`        // Its unique identifier
	Kind       string         `json:"kind,omitempty"`       // individual, group, org or location, or empty for an individual
	FN         string         `json:"fn,omitempty"`         // Its formatted name, such as Ada Lovelace
	Name       Name           `json:"name,omitzero"`        // The parts of its name
	Nicknames  []string       `json:"nicknames,omitempty"`  // Its nicknames
	Emails     []Value        `json:"emails,omitempty"`     // Its email addresses
	Phones     []Value        `json:"phones,omitempty"`     // Its phone numbers
	URLs       []Value        `json:"urls,omitempty"`       // Its URLs
	Addresses  []Address      `json:"addresses,omitempty"`  // Its addresses
	Orgs       []Organization `json:"orgs,omitempty"`       // The organisations it's part of
	Titles     []string       `json:"titles,omitempty"`     // Its job titles
	Birthday   *Date          `json:"birthday,omitempty"`   // Its birthday
	Notes      []string       `json:"notes,omitempty"`      // Notes about it
	Categories []string       `json:"categories,omitempty"` // Its categories, or tags
	Photo      *Photo         `json:"photo,omitempty"`      // Its photo, embedded or linked
	Rev        time.Time      `json:"rev,omitzero"`         // When it was last changed
}

Card is a contact, such as a person or an organisation

func Decode

func Decode(r io.Reader) ([]*Card, error)

Decode returns the contacts of r, which are vCard 2.1, 3.0 or 4.0

func (*Card) BirthdayCalendar

func (c *Card) BirthdayCalendar() *ical.Calendar

BirthdayCalendar returns the contact's birthday as a calendar, with an all-day event which repeats every year, from the day they were born, or a leap year when it isn't known, and whose UID is their UID and /birthday, so it's the same each time, in the Birthdays category, so it's known to be a birthday, and which doesn't make the day busy. A birthday on the 29th of February is on the last day of February each year. The event's stamp is when the contact was last changed, or the Unix epoch, so the calendar is the same each time it's written, and its image is their photo, when it's embedded. Returns nil when they have no birthday with a month and a day. Reference: https://www.rfc-editor.org/rfc/rfc5545

func (*Card) DisplayName

func (c *Card) DisplayName() string

DisplayName returns the name of the contact, which is its formatted name, or else the parts of its name, or its first email address, or an empty string when it has none of them

func (*Card) MarshalText

func (c *Card) MarshalText() ([]byte, error)

MarshalText returns the contact as vCard 4.0 (see Encoder.Encode)

func (*Card) UnmarshalText

func (c *Card) UnmarshalText(data []byte) error

UnmarshalText sets the contact from the first vCard of the text

type Date

type Date struct {
	Year  int `json:"year,omitempty"`
	Month int `json:"month"`
	Day   int `json:"day"`
}

Date is a date, such as a birthday, whose year is zero when it isn't known

type Decoder

type Decoder struct {
	// contains filtered or unexported fields
}

Decoder reads contacts from vCard 2.1, 3.0 or 4.0, one at a time

func NewDecoder

func NewDecoder(r io.Reader) *Decoder

NewDecoder returns a decoder of contacts from r

func (*Decoder) Decode

func (d *Decoder) Decode() (*Card, error)

Decode returns the next contact, or io.EOF when there are no more. Lines outside a vCard are ignored, and a vCard which isn't ended is returned.

type Encoder

type Encoder struct {
	// contains filtered or unexported fields
}

Encoder writes contacts as vCard 4.0

func NewEncoder

func NewEncoder(w io.Writer) *Encoder

NewEncoder returns an encoder of contacts to w

func (*Encoder) Encode

func (e *Encoder) Encode(c *Card) error

Encode writes the contact as vCard 4.0. Its formatted name, which a vCard must have, is its display name (see Card.DisplayName). Its UID is text, as it may not be a URI, its URLs aren't escaped, as they're URIs, its photo is embedded as a data URI, or linked, and when it was last changed is in UTC. Values which are empty aren't written.

type Name

type Name struct {
	Family string `json:"family,omitempty"` // Lovelace
	Given  string `json:"given,omitempty"`  // Ada
	Middle string `json:"middle,omitempty"` // Augusta
	Prefix string `json:"prefix,omitempty"` // Countess
	Suffix string `json:"suffix,omitempty"` // FRS
}

Name is the parts of a name, any of which can be empty

func (Name) IsZero

func (n Name) IsZero() bool

IsZero returns true when the name has no parts

func (Name) String

func (n Name) String() string

String returns the parts of a name, in the order they're said, such as Countess Ada Augusta Lovelace FRS

type Organization

type Organization struct {
	Name  string   `json:"name,omitempty"`
	Units []string `json:"units,omitempty"`
}

Organization is an organisation, and the units within it, such as a department

func (Organization) String

func (o Organization) String() string

String returns an organisation and its units, separated with commas

type Photo

type Photo struct {
	MediaType string `json:"media_type,omitempty"`
	Data      []byte `json:"data,omitempty"`
	URI       string `json:"uri,omitempty"`
}

Photo is the photo of a contact, which is embedded in its vCard, as its data and its media type, such as image/jpeg, or linked, as a URI

func (*Photo) DataURI

func (p *Photo) DataURI() string

DataURI returns the photo as a data URI, when it's embedded, such as data:image/jpeg;base64,..., or else its URI

func (*Photo) Image

func (p *Photo) Image() image.Image

Image returns the photo, when it's embedded, decoded, or nil when it's a link, or can't be decoded

type Value

type Value struct {
	Value string   `json:"value"`
	Types []string `json:"types,omitempty"`
	Pref  bool     `json:"pref,omitempty"`
}

Value is a value, such as an email address or phone number, with its types, such as home or work, in lower case, and whether it's preferred

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL