29d87c1e76a7d2157020079760fa3ddd67f14543
[squirrelmail.git] / doc / addressbook.txt
1 SquirrelMail Addressbook Internals
2 ==================================
3
4 This document describe how the SquirrelMail address book works. It is
5 primarily intended for developers.
6
7
8 1. The Basics
9 -------------
10
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.
14
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).
19
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).
25
26 An addressbook can also be initialized like this if you want to:
27
28 $abook = new AddressBook;
29
30 // Add one file based backend (personal address book)
31 $abook->add_backend("local_file", Array("filename" => $filename,
32 "create" => true));
33
34 $abook->add_backend("ldap_server", <array with parameters>);
35
36 $res = $abook->search("John Doe");
37
38 echo $res[0]["name"] . " " . $res[0]["email"];
39
40
41
42 2. The AddressBook class
43 ------------------------
44
45 This class acts as the glue for the address book. The following public
46 methods are provided:
47
48 add_backend(NAME, PARAMETERS)
49
50 NAME - The name of the backend to add. A file with a
51 class abook_NAME must be included before this can
52 be done.
53
54 PARAMETERS - A mixed variable that is passed on to
55 the backend class constructor. See each backend
56 for docs.
57
58 This method will return a backend ID number (not usable at the
59 moment), or false if it failed.
60
61
62 search(QUERY, [BTYPE])
63
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.
67
68 BTYPE - Optional backend type to search. Either "local"
69 or "remote".
70
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.
73
74
75 s_search(QUERY, [BTYPE])
76
77 The same as search(), but the result array is sorted by backend and
78 fullname before it is returned.
79
80
81 lookup(NICKNAME)
82
83 NICKNAME - Return the user identified by NICKNAME in
84 the addressbook.
85
86 This method will return one result array (see below), an empty
87 array if nothing was found, or false if the search failed. The
88 lookup is only performed in "local" type backends.
89
90
91 list_addr()
92
93 This method will return an array of result arrays (see below) for
94 all addresses in the addressbook, or false if it failed. Only
95 addresses in "local" type backends are returned.
96
97
98 add(USERDATA, BNUM)
99
100 USERDATA - An array with user data. Must contain the following
101 keys: nickname, firstname, lastname, email, label
102 See below for information about the keys.
103
104 BNUM - ID of the backend, as returned by add_backend, to add this
105 data to.
106
107 This method will return the backend ID of the backend where data
108 was added, or false if it failed.
109
110
111
112 If one of the above methods fail, an error message is available in the
113 AddressBook->error variable. Feel free to ignore it.
114
115
116 For the result of a search, lookup or list_addr, one or more result
117 arrays are used. These arrays contain the following keys:
118
119 nickname: Unique identifier for this name in this backend. Onlu
120 usable for the local_file backend, and possibly LDAP.
121 name: Person's full name.
122 email: Person's e-mail address.
123 backend: Backend ID where this was found
124 source: Name of the backend where this was found
125
126 In addition, the following keys may exist for some backends:
127
128 label: Additional information about the person
129 firstname: Person's first name
130 lastname: Person's last name
131
132
133 3. The backend classes
134 ----------------------
135
136 ... more later ...