1 SquirrelMail Addressbook Internals
2 ==================================
4 This document describe 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 (is 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.
62 search(QUERY, [BTYPE])
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 BTYPE - Optional backend type to search. Either "local"
71 This method will return an array of result arrays (see below), an
72 empty array if nothing was found, or false if the search failed.
75 s_search(QUERY, [BTYPE])
77 The same as search(), but the result array is sorted by backend and
78 fullname before it is returned.
81 lookup(NICKNAME, [BNUM])
83 NICKNAME - Return the user identified by NICKNAME in
86 BNUM - ID of the backend to look in (optional).
88 This method will return one result array (see below), an empty
89 array if nothing was found, or false if the search failed. The
90 lookup is only performed in "local" type backends.
95 This method will return an array of result arrays (see below) for
96 all addresses in the addressbook, or false if it failed. Only
97 addresses in "local" type backends are returned.
102 USERDATA - An array with user data. Must contain the following
103 keys: nickname, firstname, lastname, email, label
104 See below for information about the keys.
106 BNUM - ID of the backend, as returned by add_backend, to add this
109 This method will return the backend ID of the backend where data
110 was added, or false if it failed.
113 remove(NICKNAME, BNUM)
115 NICKNAME - Delete the user identified by NICKNAME in the
116 addressbook or, if NICKNAME is an array, all users indentified by
117 nthe nicknames in the array.
119 BNUM - ID of the backend, as returned by add_backend, to remove
122 This method will retrun true if the user(s) was removed, or false
126 modify(NICKNAME, USERDATA, BNUM)
128 NICKNAME - Update the user identified by NICKNAME in the
131 USERDATA - Array with user data. The exisiting data for the user
132 will be replaced with this.
134 BNUM - ID of the backend, as returned by add_backend, to update
137 This method will retrun true if the user was modified, or false if
141 If one of the above methods fail, an error message is available in the
142 AddressBook->error variable. Feel free to ignore it.
145 For the result of a search, lookup or list_addr, one or more result
146 arrays are used. These arrays contain the following keys:
148 nickname: Unique identifier for this name in this backend. Onlu
149 usable for the local_file backend, and possibly LDAP.
150 name: Person's full name.
151 email: Person's e-mail address.
152 backend: Backend ID where this was found
153 source: Name of the backend where this was found
155 In addition, the following keys may exist for some backends:
157 label: Additional information about the person
158 firstname: Person's first name
159 lastname: Person's last name
162 3. The backend classes
163 ----------------------