contacts API
The addressBooks API, also including the contacts API and mailingLists API namespaces, first appeared in Thunderbird 64.
The Address Books sample extension uses this API.
Permissions
Read and modify your address books and contacts
Functions
list(parentId)
Gets all the contacts in the address book with the id parentId
.
Parameters
parentId
(string)
Return type (Promise)
array of ContactNode
Required permissions
quickSearch([parentId], queryInfo)
Gets all contacts matching queryInfo
in the address book with the id parentId
.
Parameters
[parentId
]
(string, optional)
The id of the address book to search. If not specified, all address books are searched.
Return type (Promise)
array of ContactNode
Required permissions
get(id)
Gets a single contact.
Parameters
id
(string)
Return type (Promise)
Required permissions
create(parentId, [id], properties)
Adds a new contact to the address book with the id parentId
.
Parameters
parentId
(string)
[id
]
(string, optional)
Assigns the contact an id. If an existing contact has this id, an exception is thrown.
Return type (Promise)
string
The ID of the new contact.
Required permissions
update(id, properties)
Edits the properties of a contact. To remove a property, specify it as null.
Required permissions
delete(id)
Removes a contact from the address book. The contact is also removed from any mailing lists it is a member of.
Parameters
id
(string)
Required permissions
Events
onCreated
Fired when a contact is created.
Parameters for onCreated.addListener(listener)
listener(node)
A function that will be called when this event occurs.
Parameters passed to the listener function
Required permissions
onUpdated
Fired when a contact is changed.
Parameters for onUpdated.addListener(listener)
listener(node, changedProperties)
A function that will be called when this event occurs.
Parameters passed to the listener function
Required permissions
onDeleted
Fired when a contact is removed from an address book.
Parameters for onDeleted.addListener(listener)
listener(parentId, id)
A function that will be called when this event occurs.
Parameters passed to the listener function
parentId
(string)
id
(string)
Required permissions
Types
ContactNode
A node representing a contact in an address book.
object
id
(string)
The unique identifier for the node. IDs are unique within the current profile, and they remain valid even after the program is restarted.
Always set to contact.
[parentId
]
(string, optional)
The id
of the parent object.
[readOnly
]
(boolean, optional)
Indicates if the object is read-only.
[remote
]
(boolean, optional)
Indicates if the object came from a remote address book.
ContactProperties
A set of properties for a particular contact. For a complete list of properties that Thunderbird uses, see https://hg.mozilla.org/comm-central/file/tip/mailnews/addrbook/public/nsIAbCard.idl
It is also possible to store custom properties. The custom property name however may only use a-z, A-Z, 1-9 and underscores.
object
PropertyChange
– [Added in TB 83]
A dictionary of changed properties. Keys are the property name that changed, values are an object containing oldValue
and newValue
. Values can be either a string or null.
object
QueryInfo
– [Added in TB 91]
Object defining a query for quickSearch([parentId], queryInfo).
object
[includeLocal
]
(boolean, optional)
Whether to include results from local address books. Defaults to true.
[includeReadOnly
]
(boolean, optional)
Whether to include results from read-only address books. Defaults to true.
[includeReadWrite
]
(boolean, optional)
Whether to include results from read-write address books. Defaults to true.
[includeRemote
]
(boolean, optional)
Whether to include results from remote address books. Defaults to true.
[searchString
]
(string, optional)
One or more space-separated terms to search for.