1 /*
2  * libEtPan! -- a mail stuff library
3  *
4  * Copyright (C) 2001, 2002 - DINH Viet Hoa
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. Neither the name of the libEtPan! project nor the names of its
16  *    contributors may be used to endorse or promote products derived
17  *    from this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29  * SUCH DAMAGE.
30  */
31 
32 /*
33  * $Id$
34  */
35 
36 #ifndef MAILIMF_TYPES_HELPER
37 
38 #define MAILIMF_TYPES_HELPER
39 
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43 
44 #include "mailimf_types.h"
45 
46 /*
47   IMPORTANT NOTE:
48 
49   All allocation functions will take as argument allocated data
50   and will store these data in the structure they will allocate.
51   Data should be persistant during all the use of the structure
52   and will be freed by the free function of the structure
53 
54   allocation functions will return NULL on failure
55 */
56 
57 /*
58   mailimf_mailbox_list_new_empty creates an empty list of mailboxes
59 */
60 
61 struct mailimf_mailbox_list *
62 mailimf_mailbox_list_new_empty();
63 
64 /*
65   mailimf_mailbox_list_add adds a mailbox to the list of mailboxes
66 
67   @return MAILIMF_NO_ERROR will be returned on success,
68   other code will be returned otherwise
69 */
70 
71 int mailimf_mailbox_list_add(struct mailimf_mailbox_list * mailbox_list,
72 			     struct mailimf_mailbox * mb);
73 
74 /*
75   mailimf_mailbox_list_add_parse parse the given string
76   into a mailimf_mailbox structure and adds it to the list of mailboxes
77 
78   @return MAILIMF_NO_ERROR will be returned on success,
79   other code will be returned otherwise
80 */
81 
82 int mailimf_mailbox_list_add_parse(struct mailimf_mailbox_list * mailbox_list,
83 				   char * mb_str);
84 
85 /*
86   mailimf_mailbox creates a mailimf_mailbox structure with the given
87   arguments and adds it to the list of mailboxes
88 
89   - display_name is the name that will be displayed for this mailbox,
90     for example 'name' in '"name" <mailbox@domain>,
91     should be allocated with malloc()
92 
93   - address is the mailbox, for example 'mailbox@domain'
94     in '"name" <mailbox@domain>, should be allocated with malloc()
95 
96   @return MAILIMF_NO_ERROR will be returned on success,
97   other code will be returned otherwise
98 */
99 
100 int mailimf_mailbox_list_add_mb(struct mailimf_mailbox_list * mailbox_list,
101 				char * display_name, char * address);
102 
103 /*
104   mailimf_address_list_new_empty creates an empty list of addresses
105 */
106 
107 struct mailimf_address_list *
108 mailimf_address_list_new_empty();
109 
110 /*
111   mailimf_address_list_add adds a mailbox to the list of addresses
112 
113   @return MAILIMF_NO_ERROR will be returned on success,
114   other code will be returned otherwise
115 */
116 
117 int mailimf_address_list_add(struct mailimf_address_list * address_list,
118 			     struct mailimf_address * addr);
119 
120 /*
121   mailimf_address_list_add_parse parse the given string
122   into a mailimf_address structure and adds it to the list of addresses
123 
124   @return MAILIMF_NO_ERROR will be returned on success,
125   other code will be returned otherwise
126 */
127 
128 int mailimf_address_list_add_parse(struct mailimf_address_list * address_list,
129 				   char * addr_str);
130 
131 /*
132   mailimf_address_list_add_mb creates a mailbox mailimf_address
133   with the given arguments and adds it to the list of addresses
134 
135   - display_name is the name that will be displayed for this mailbox,
136     for example 'name' in '"name" <mailbox@domain>,
137     should be allocated with malloc()
138 
139   - address is the mailbox, for example 'mailbox@domain'
140     in '"name" <mailbox@domain>, should be allocated with malloc()
141 
142   @return MAILIMF_NO_ERROR will be returned on success,
143   other code will be returned otherwise
144 */
145 
146 int mailimf_address_list_add_mb(struct mailimf_address_list * address_list,
147 				char * display_name, char * address);
148 
149 /*
150   mailimf_resent_fields_add_data adds a set of resent fields in the
151   given mailimf_fields structure.
152 
153   if you don't want a given field in the set to be added in the list
154   of fields, you can give NULL as argument
155 
156   @param resent_msg_id sould be allocated with malloc()
157 
158   @return MAILIMF_NO_ERROR will be returned on success,
159   other code will be returned otherwise
160 */
161 
162 int
163 mailimf_resent_fields_add_data(struct mailimf_fields * fields,
164     struct mailimf_date_time * resent_date,
165     struct mailimf_mailbox_list * resent_from,
166     struct mailimf_mailbox * resent_sender,
167     struct mailimf_address_list * resent_to,
168     struct mailimf_address_list * resent_cc,
169     struct mailimf_address_list * resent_bcc,
170     char * resent_msg_id);
171 
172 /*
173   mailimf_resent_fields_new_with_data_all creates a new mailimf_fields
174   structure with a set of resent fields
175 
176   if you don't want a given field in the set to be added in the list
177   of fields, you can give NULL as argument
178 
179   @param resent_msg_id sould be allocated with malloc()
180 
181   @return MAILIMF_NO_ERROR will be returned on success,
182   other code will be returned otherwise
183 */
184 
185 struct mailimf_fields *
186 mailimf_resent_fields_new_with_data_all(struct mailimf_date_time *
187     resent_date, struct mailimf_mailbox_list * resent_from,
188     struct mailimf_mailbox * resent_sender,
189     struct mailimf_address_list * resent_to,
190     struct mailimf_address_list * resent_cc,
191     struct mailimf_address_list * resent_bcc,
192     char * resent_msg_id);
193 
194 /*
195   mailimf_resent_fields_new_with_data_all creates a new mailimf_fields
196   structure with a set of resent fields.
197   Resent-Date and Resent-Message-ID fields will be generated for you.
198 
199   if you don't want a given field in the set to be added in the list
200   of fields, you can give NULL as argument
201 
202   @return MAILIMF_NO_ERROR will be returned on success,
203   other code will be returned otherwise
204 */
205 
206 struct mailimf_fields *
207 mailimf_resent_fields_new_with_data(struct mailimf_mailbox_list * from,
208     struct mailimf_mailbox * sender,
209     struct mailimf_address_list * to,
210     struct mailimf_address_list * cc,
211     struct mailimf_address_list * bcc);
212 
213 /*
214   this function creates a new mailimf_fields structure with no fields
215 */
216 
217 struct mailimf_fields *
218 mailimf_fields_new_empty(void);
219 
220 
221 /*
222   this function adds a field to the mailimf_fields structure
223 
224   @return MAILIMF_NO_ERROR will be returned on success,
225   other code will be returned otherwise
226 */
227 
228 int mailimf_fields_add(struct mailimf_fields * fields,
229 		       struct mailimf_field * field);
230 
231 
232 /*
233   mailimf_fields_add_data adds a set of fields in the
234   given mailimf_fields structure.
235 
236   if you don't want a given field in the set to be added in the list
237   of fields, you can give NULL as argument
238 
239   @param msg_id sould be allocated with malloc()
240   @param subject should be allocated with malloc()
241   @param in_reply_to each elements of this list should be allocated
242     with malloc()
243   @param references each elements of this list should be allocated
244     with malloc()
245 
246   @return MAILIMF_NO_ERROR will be returned on success,
247   other code will be returned otherwise
248 */
249 
250 int mailimf_fields_add_data(struct mailimf_fields * fields,
251 			    struct mailimf_date_time * date,
252 			    struct mailimf_mailbox_list * from,
253 			    struct mailimf_mailbox * sender,
254 			    struct mailimf_address_list * reply_to,
255 			    struct mailimf_address_list * to,
256 			    struct mailimf_address_list * cc,
257 			    struct mailimf_address_list * bcc,
258 			    char * msg_id,
259 			    clist * in_reply_to,
260 			    clist * references,
261 			    char * subject);
262 
263 /*
264   mailimf_fields_new_with_data_all creates a new mailimf_fields
265   structure with a set of fields
266 
267   if you don't want a given field in the set to be added in the list
268   of fields, you can give NULL as argument
269 
270   @param message_id sould be allocated with malloc()
271   @param subject should be allocated with malloc()
272   @param in_reply_to each elements of this list should be allocated
273     with malloc()
274   @param references each elements of this list should be allocated
275     with malloc()
276 
277   @return MAILIMF_NO_ERROR will be returned on success,
278   other code will be returned otherwise
279 */
280 
281 struct mailimf_fields *
282 mailimf_fields_new_with_data_all(struct mailimf_date_time * date,
283 				 struct mailimf_mailbox_list * from,
284 				 struct mailimf_mailbox * sender,
285 				 struct mailimf_address_list * reply_to,
286 				 struct mailimf_address_list * to,
287 				 struct mailimf_address_list * cc,
288 				 struct mailimf_address_list * bcc,
289 				 char * message_id,
290 				 clist * in_reply_to,
291 				 clist * references,
292 				 char * subject);
293 
294 /*
295   mailimf_fields_new_with_data creates a new mailimf_fields
296   structure with a set of fields
297   Date and Message-ID fields will be generated for you.
298 
299   if you don't want a given field in the set to be added in the list
300   of fields, you can give NULL as argument
301 
302   @param subject should be allocated with malloc()
303   @param in_reply_to each elements of this list should be allocated
304     with malloc()
305   @param references each elements of this list should be allocated
306     with malloc()
307 
308   @return MAILIMF_NO_ERROR will be returned on success,
309   other code will be returned otherwise
310 */
311 
312 struct mailimf_fields *
313 mailimf_fields_new_with_data(struct mailimf_mailbox_list * from,
314 			     struct mailimf_mailbox * sender,
315 			     struct mailimf_address_list * reply_to,
316 			     struct mailimf_address_list * to,
317 			     struct mailimf_address_list * cc,
318 			     struct mailimf_address_list * bcc,
319 			     clist * in_reply_to,
320 			     clist * references,
321 			     char * subject);
322 
323 /*
324   this function returns an allocated message identifier to
325   use in a Message-ID or Resent-Message-ID field
326 */
327 
328 char * mailimf_get_message_id(void);
329 
330 /*
331   this function returns a mailimf_date_time structure to
332   use in a Date or Resent-Date field
333 */
334 
335 struct mailimf_date_time * mailimf_get_current_date(void);
336 
337 
338 /*
339   mailimf_single_fields_init fills a mailimf_single_fields structure
340   with the content of a mailimf_fields structure
341 */
342 
343 void mailimf_single_fields_init(struct mailimf_single_fields * single_fields,
344                                 struct mailimf_fields * fields);
345 
346 /*
347   mailimf_single_fields_new creates a new mailimf_single_fields and
348   fills the structure with mailimf_fields
349 */
350 
351 struct mailimf_single_fields *
352 mailimf_single_fields_new(struct mailimf_fields * fields);
353 
354 void mailimf_single_fields_free(struct mailimf_single_fields *
355                                 single_fields);
356 
357 /*
358   mailimf_field_new_custom creates a new field of type optional
359 
360   @param name should be allocated with malloc()
361   @param value should be allocated with malloc()
362 */
363 
364 struct mailimf_field * mailimf_field_new_custom(char * name, char * value);
365 
366 #ifdef __cplusplus
367 }
368 #endif
369 
370 #endif
371