1 SquirrelMail Addressbook Internals
2 ==================================
4 This document describes how the SquirrelMail address book works. It is
5 primarily intended for developers.
11 The address book is written using PHP classes, with one class,
12 AddressBook, that use one or more "backend" classes to access
13 different address books.
15 All operations, such as search, lookup, add etc., are performed by
16 calling the appropriate methods from the AddressBook object. The
17 operation will then be distributed by calling the correct method in
18 the appropriate backend(s).
20 To initialize the address book, the function addressbook_init() from
21 functions/addressbook.php is called. This function will create an
22 AddressBook object, add one backend for a personal address book (file
23 based storage), and add the LDAP backends defined in the $ldap_server
24 configuration directive (if any).
26 An addressbook can also be initialized like this if you want to:
28 $abook = new AddressBook;
30 // Add one file based backend (personal address book)
31 $abook->add_backend("local_file", Array("filename" => $filename,
34 $abook->add_backend("ldap_server", <array with parameters>);
36 $res = $abook->search("John Doe");
38 echo $res[0]["name"] . " " . $res[0]["email"];
42 2. The AddressBook class
43 ------------------------
45 This class acts as the glue for the address book. The following public
48 add_backend(NAME, PARAMETERS)
50 NAME - The name of the backend to add. A file with a
51 class abook_NAME must be included before this can
54 PARAMETERS - A mixed variable that is passed on to
55 the backend class constructor. See each backend
58 This method will return a backend ID number (not usable at the
59 moment), or false if it failed.
64 QUERY - Something to search for. At the moment, only
65 a string is allowed here, but advanced expressions
66 will be supported through an array of parameters.
68 BNUM - Optional backend number to search.
70 This method will return an array of result arrays (see below), an
71 empty array if nothing was found, or false if the search failed.
74 s_search(QUERY, [BNUM])
76 The same as search(), but the result array is sorted by backend and
77 fullname before it is returned.
80 lookup(NICKNAME, [BNUM])
82 NICKNAME - Return the user identified by NICKNAME in
85 BNUM - ID of the backend to look in (optional).
87 This method will return one result array (see below), an empty
88 array if nothing was found, or false if the search failed. The
89 lookup is only performed in "local" type backends.
94 This method will return an array of result arrays (see below) for
95 all addresses in the addressbook, or false if it failed. Only
96 addresses in "local" type backends are returned.
101 USERDATA - An array with user data. Must contain the following
102 keys: nickname, firstname, lastname, email, label
103 See below for information about the keys.
105 BNUM - ID of the backend, as returned by add_backend, to add this
108 This method will return the backend ID of the backend where data
109 was added, or false if it failed.
112 remove(NICKNAME, BNUM)
114 NICKNAME - Delete the user identified by NICKNAME in the
115 addressbook or, if NICKNAME is an array, all users indentified by
116 nthe nicknames in the array.
118 BNUM - ID of the backend, as returned by add_backend, to remove
121 This method will retrun true if the user(s) was removed, or false
125 modify(NICKNAME, USERDATA, BNUM)
127 NICKNAME - Update the user identified by NICKNAME in the
130 USERDATA - Array with user data. The exisiting data for the user
131 will be replaced with this.
133 BNUM - ID of the backend, as returned by add_backend, to update
136 This method will retrun true if the user was modified, or false if
140 If one of the above methods fail, an error message is available in the
141 AddressBook->error variable. Feel free to ignore it.
144 For the result of a search, lookup or list_addr, one or more result
145 arrays are used. These arrays contain the following keys:
147 nickname: Unique identifier for this name in this backend. Only
148 usable for the local_file backend, and possibly LDAP.
149 name: Person's full name.
150 email: Person's e-mail address.
151 backend: Backend ID where this was found
152 source: Name of the backend where this was found
154 In addition, the following keys may exist for some backends:
156 label: Additional information about the person
157 firstname: Person's first name
158 lastname: Person's last name
161 3. The backend classes
162 ----------------------
166 Ask pallo@squirrelmail.org if you have any questions on how to build
167 new address book backends.