2 * libEtPan! -- a mail stuff library
4 * Copyright (C) 2001, 2002 - DINH Viet Hoa
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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.
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
36 #ifndef MAILIMF_TYPES_HELPER
38 #define MAILIMF_TYPES_HELPER
44 #include "mailimf_types.h"
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
54 allocation functions will return NULL on failure
58 mailimf_mailbox_list_new_empty creates an empty list of mailboxes
61 struct mailimf_mailbox_list *
62 mailimf_mailbox_list_new_empty();
65 mailimf_mailbox_list_add adds a mailbox to the list of mailboxes
67 @return MAILIMF_NO_ERROR will be returned on success,
68 other code will be returned otherwise
71 int mailimf_mailbox_list_add(struct mailimf_mailbox_list * mailbox_list,
72 struct mailimf_mailbox * mb);
75 mailimf_mailbox_list_add_parse parse the given string
76 into a mailimf_mailbox structure and adds it to the list of mailboxes
78 @return MAILIMF_NO_ERROR will be returned on success,
79 other code will be returned otherwise
82 int mailimf_mailbox_list_add_parse(struct mailimf_mailbox_list * mailbox_list,
86 mailimf_mailbox creates a mailimf_mailbox structure with the given
87 arguments and adds it to the list of mailboxes
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()
93 - address is the mailbox, for example 'mailbox@domain'
94 in '"name" <mailbox@domain>, should be allocated with malloc()
96 @return MAILIMF_NO_ERROR will be returned on success,
97 other code will be returned otherwise
100 int mailimf_mailbox_list_add_mb(struct mailimf_mailbox_list * mailbox_list,
101 char * display_name, char * address);
104 mailimf_address_list_new_empty creates an empty list of addresses
107 struct mailimf_address_list *
108 mailimf_address_list_new_empty();
111 mailimf_address_list_add adds a mailbox to the list of addresses
113 @return MAILIMF_NO_ERROR will be returned on success,
114 other code will be returned otherwise
117 int mailimf_address_list_add(struct mailimf_address_list * address_list,
118 struct mailimf_address * addr);
121 mailimf_address_list_add_parse parse the given string
122 into a mailimf_address structure and adds it to the list of addresses
124 @return MAILIMF_NO_ERROR will be returned on success,
125 other code will be returned otherwise
128 int mailimf_address_list_add_parse(struct mailimf_address_list * address_list,
132 mailimf_address_list_add_mb creates a mailbox mailimf_address
133 with the given arguments and adds it to the list of addresses
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()
139 - address is the mailbox, for example 'mailbox@domain'
140 in '"name" <mailbox@domain>, should be allocated with malloc()
142 @return MAILIMF_NO_ERROR will be returned on success,
143 other code will be returned otherwise
146 int mailimf_address_list_add_mb(struct mailimf_address_list * address_list,
147 char * display_name, char * address);
150 mailimf_resent_fields_add_data adds a set of resent fields in the
151 given mailimf_fields structure.
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
156 @param resent_msg_id sould be allocated with malloc()
158 @return MAILIMF_NO_ERROR will be returned on success,
159 other code will be returned otherwise
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);
173 mailimf_resent_fields_new_with_data_all creates a new mailimf_fields
174 structure with a set of resent fields
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
179 @param resent_msg_id sould be allocated with malloc()
181 @return MAILIMF_NO_ERROR will be returned on success,
182 other code will be returned otherwise
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);
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.
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
202 @return MAILIMF_NO_ERROR will be returned on success,
203 other code will be returned otherwise
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);
214 this function creates a new mailimf_fields structure with no fields
217 struct mailimf_fields *
218 mailimf_fields_new_empty(void);
222 this function adds a field to the mailimf_fields structure
224 @return MAILIMF_NO_ERROR will be returned on success,
225 other code will be returned otherwise
228 int mailimf_fields_add(struct mailimf_fields * fields,
229 struct mailimf_field * field);
233 mailimf_fields_add_data adds a set of fields in the
234 given mailimf_fields structure.
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
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
243 @param references each elements of this list should be allocated
246 @return MAILIMF_NO_ERROR will be returned on success,
247 other code will be returned otherwise
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,
264 mailimf_fields_new_with_data_all creates a new mailimf_fields
265 structure with a set of fields
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
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
274 @param references each elements of this list should be allocated
277 @return MAILIMF_NO_ERROR will be returned on success,
278 other code will be returned otherwise
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,
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.
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
302 @param subject should be allocated with malloc()
303 @param in_reply_to each elements of this list should be allocated
305 @param references each elements of this list should be allocated
308 @return MAILIMF_NO_ERROR will be returned on success,
309 other code will be returned otherwise
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,
324 this function returns an allocated message identifier to
325 use in a Message-ID or Resent-Message-ID field
328 char * mailimf_get_message_id(void);
331 this function returns a mailimf_date_time structure to
332 use in a Date or Resent-Date field
335 struct mailimf_date_time * mailimf_get_current_date(void);
339 mailimf_single_fields_init fills a mailimf_single_fields structure
340 with the content of a mailimf_fields structure
343 void mailimf_single_fields_init(struct mailimf_single_fields * single_fields,
344 struct mailimf_fields * fields);
347 mailimf_single_fields_new creates a new mailimf_single_fields and
348 fills the structure with mailimf_fields
351 struct mailimf_single_fields *
352 mailimf_single_fields_new(struct mailimf_fields * fields);
354 void mailimf_single_fields_free(struct mailimf_single_fields *
358 mailimf_field_new_custom creates a new field of type optional
360 @param name should be allocated with malloc()
361 @param value should be allocated with malloc()
364 struct mailimf_field * mailimf_field_new_custom(char * name, char * value);