-
Notifications
You must be signed in to change notification settings - Fork 8
/
addressbook.h
403 lines (339 loc) · 9.97 KB
/
addressbook.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
/***************************************************************************
SimpleMail - Copyright (C) 2000 Hynek Schlawack and Sebastian Bauer
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
***************************************************************************/
/**
* @file
*/
#ifndef SM__ADDRESSBOOK_H
#define SM__ADDRESSBOOK_H
#ifndef SM__LISTS_H
#include "lists.h"
#endif
#ifndef SM__CODESETS_H
#include "codesets.h"
#endif
struct mail;
struct address_snail_phone
{
char *title;
char *organization;
char *street;
char *city;
char *zip;
char *state;
char *country;
char *phone1;
char *phone2;
char *mobil;
char *fax;
};
struct addressbook_group
{
struct node node;
utf8 *name;
utf8 *description;
};
struct addressbook_entry_new
{
struct node node;
char *alias;
char *description;
char *realname;
char *notepad;
char *pgpid;
char *homepage;
char *portrait; /* filename to a picture of this person */
struct address_snail_phone priv;
struct address_snail_phone work;
int dob_day; /* day of birth */
int dob_month; /* month of birth */
int dob_year; /* year of birth */
int sex; /* 0 unspecified, 1 female, 2 male */
char **email_array; /* NULL terminated array of emails (use array_xxx() functions) */
char **group_array; /* NULL terminated array of names of groups (use array_xxx() functions) */
};
/* Entry functions */
/**
* Returns the first address book entry.
*/
struct addressbook_entry_new *addressbook_first_entry(void);
/**
* Returns the next address book entry.
*/
struct addressbook_entry_new *addressbook_next_entry(struct addressbook_entry_new *entry);
/**
* Create a duplicate of the given address book entry. The duplicate is not
* added to the list.
*/
struct addressbook_entry_new *addressbook_duplicate_entry_new(struct addressbook_entry_new *entry);
/**
* Free the memory associated with the given address book entry.
*/
void addressbook_free_entry_new(struct addressbook_entry_new *entry);
/**
* Returns the rest of the a partial string with respect to the given entry.
*
* @param entry the entry
* @param part a prefix string that should be completed by some field of the
* entry.
* @param type_ptr will be filled with 0 if the alias has been completed, 1 for the
* real name and all greater than 1 the email.
*
* @return pointer to the remaining characters or NULL if no match was found.
* You must not change the contents of the result!
*/
char *addressbook_get_entry_completing_part(struct addressbook_entry_new *entry, char *part, int *type_ptr);
/**
* Adds an entry into the address book.
*
* @param real name
* @return the reference to the entry that have just been added.
*/
struct addressbook_entry_new *addressbook_add_entry(const char *realname);
/**
* Add a duplicate of the given address book entry.
*
* @param entry the entry to be duplicated
* @return the duplicated entry
*/
struct addressbook_entry_new *addressbook_add_entry_duplicate(struct addressbook_entry_new *entry);
/* Group functions */
/**
* Returns the first address book group.
*/
struct addressbook_group *addressbook_first_group(void);
/**
* Returns the next address book group.
*
* @param grp
* @return
*/
struct addressbook_group *addressbook_next_group(struct addressbook_group *grp);
/**
* Duplicates a given address book group.
*
* @param srcgrp
* @return
*/
struct addressbook_group *addressbook_duplicate_group(struct addressbook_group *srcgrp);
/**
* Free all memory associated to the given address book group.
*
* @param grp
*/
void addressbook_free_group(struct addressbook_group *grp);
/**
* Find an address book group by the given name.
*
* @param name
* @return
*/
struct addressbook_group *addressbook_find_group_by_name(const utf8 *name);
/**
* Add a new address book group with the given name. Duplicates are allowed.
*
* @param name specifies the name of the address book group to be created.
* @return the reference to the newly created address book group.
*/
struct addressbook_group *addressbook_add_group(const utf8 *name);
/**
* Adds a duplicate of the given address book group.
*
* @param group the group to be added.
* @return the reference to the newly created group.
*/
struct addressbook_group *addressbook_add_group_duplicate(struct addressbook_group *group);
/* init and io */
/**
* Initializes the addressbook
*/
int init_addressbook(void);
/**
* Cleanups the addressbook. Oposite of init_addressbook().
*/
void cleanup_addressbook(void);
/**
* Clears the addressbook without cleaning it up completely.
*/
void addressbook_clear(void);
/**
* Load the addressbook. Returns 0 for an error.
*
* @return
*/
int addressbook_load(void);
/**
* Saved the addressbook to the default file
*/
void addressbook_save(void);
/**
* Saves the addressbok to a given file.
*
* @param filename
*/
void addressbook_save_as(char *filename);
/**
* Loads the Addressbook as the xml format
*
* @param filename
* @return
*/
int addressbook_import_sm(char *filename);
/**
* Import addressbook entries from YAM.
*
* @param filename
* @return
*/
int addressbook_import_yam(char *filename);
/**
* Add entries from a specified file. Set append to 1 if the addressbook
* should be appended. filename mybe NULL which means that the default
* filename is used. Returns 1 for success.
* TODO: replace addressbook_load().
*
* @param filename
* @param append
* @return
*/
int addressbook_import_file(char *filename, int append);
/* general */
/**
* This function returns an expanded string consisting of phrases and email
* addresses. It uses the address book for that purpose and performs syntax
* checks (uses some parse functions). If NULL is returned something had failed.
*
* @param unexpand the string to expand, i.e,, a comma separated list of phrases,
* email addresses, or both.
*
* @return the expanded string.
*/
char *addressbook_get_expanded(char *unexpand);
/**
* Finds the first address book entry that contains the given address.
*
* @param email the mail address that is associated to the address book entry
* to be found.
* @return the first address book entry or NULL if no such entry exists.
*/
struct addressbook_entry_new *addressbook_find_entry_by_address(const char *email);
/**
* Finds the first address book entry that has the given alias.
*
* @param alias the alias of the address book entry to be found.
* @return the first address book entry or NULL if no such entry exists.
*/
struct addressbook_entry_new *addressbook_find_entry_by_alias(const char *alias);
/**
* Finds the first address book entry that has the given real name..
*
* @param realname
* @return the first address book entry or NULL if no such entry exists.
*/
struct addressbook_entry_new *addressbook_find_entry_by_realname(const char *realname);
/**
* Returns a string array of all addresses within the addressbook.
* array must be free'd with array_free() when no longer used.
*
* @return
*/
char **addressbook_get_array_of_email_addresses(void);
/**
* Returns a path to the portrait of the given e-mail. The returned string
* is allocated with malloc().
*
* @param email
* @return
*/
char *addressbook_download_portrait(char *email);
/**
* Completes an groupname/alias/realname/e-mail address of the addressbook
*
* @param address
* @return
*/
char *addressbook_complete_address(char *address);
/*****************************************************************************/
typedef enum
{
ACNT_GROUP,
ACNT_ALIAS,
ACNT_REALNAME,
ACNT_EMAIL
} addressbook_completion_node_type;
struct addressbook_completion_list
{
struct list l;
/** Defines if the completion list is complete */
int complete;
};
struct addressbook_completion_node
{
struct node n;
addressbook_completion_node_type type;
/** The complete string */
char *complete;
/** Match mask */
match_mask_t *match_mask;
};
/**
* Completes an groupname/alias/realname/e-mail address of the addressbook
*
* @param address
* @param max defines the maximum number of items that shall be put in the completion list. Use
* 0 to get the maximum.
* @return
*/
struct addressbook_completion_list *addressbook_complete_address_full(char *address, unsigned int max);
/**
* Frees the list returned by addressbook_complete_address_full().
*
* @param cl
*/
void addressbook_completion_list_free(struct addressbook_completion_list *cl);
/**
* Return the first addressbook completion entry of the given list.
*
* @param cl
* @return
*/
static inline struct addressbook_completion_node *addressbook_completion_list_first(struct addressbook_completion_list *cl)
{
return (struct addressbook_completion_node *)list_first(&cl->l);
}
/**
* Return the next addressbook completion entrs of the given node.
*
* @param n
* @return
*/
static inline struct addressbook_completion_node *addressbook_completion_node_next(struct addressbook_completion_node *n)
{
return (struct addressbook_completion_node*)node_next(&n->n);
}
/**
* Duplicate the given completion node.
*
* @param n the node to be duplicated.
* @return the duplicate or NULL. The result must be freed via addressbook_completion_node_free();
*/
struct addressbook_completion_node *addressbook_completion_node_duplicate(struct addressbook_completion_node *n);
/**
* Free the given completion node.
*
* @param n the node to be freed. It needs to be a result of
* addressbook_completion_node_duplicate().
*/
void addressbook_completion_node_free(struct addressbook_completion_node *n);
#endif