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
44 #include "mailimf_types.h"
45 #include "mailimf_write.h"
46 #include "mailimf_types_helper.h"
49 #include <sys/types.h>
52 mailimf_message_parse will parse the given message
54 @param message this is a string containing the message content
55 @param length this is the size of the given string
56 @param index this is a pointer to the start of the message in
57 the given string, (* index) is modified to point at the end
59 @param result the result of the parse operation is stored in
62 @return MAILIMF_NO_ERROR on success, MAILIMF_ERROR_XXX on error
65 int mailimf_message_parse(const char * message, size_t length,
67 struct mailimf_message ** result);
70 mailimf_body_parse will parse the given text part of a message
72 @param message this is a string containing the message text part
73 @param length this is the size of the given string
74 @param index this is a pointer to the start of the message text part in
75 the given string, (* index) is modified to point at the end
77 @param result the result of the parse operation is stored in
80 @return MAILIMF_NO_ERROR on success, MAILIMF_ERROR_XXX on error
83 int mailimf_body_parse(const char * message, size_t length,
85 struct mailimf_body ** result);
88 mailimf_fields_parse will parse the given header fields
90 @param message this is a string containing the header fields
91 @param length this is the size of the given string
92 @param index this is a pointer to the start of the header fields in
93 the given string, (* index) is modified to point at the end
95 @param result the result of the parse operation is stored in
98 @return MAILIMF_NO_ERROR on success, MAILIMF_ERROR_XXX on error
101 int mailimf_fields_parse(const char * message, size_t length,
103 struct mailimf_fields ** result);
106 mailimf_mailbox_list_parse will parse the given mailbox list
108 @param message this is a string containing the mailbox list
109 @param length this is the size of the given string
110 @param index this is a pointer to the start of the mailbox list in
111 the given string, (* index) is modified to point at the end
113 @param result the result of the parse operation is stored in
116 @return MAILIMF_NO_ERROR on success, MAILIMF_ERROR_XXX on error
120 mailimf_mailbox_list_parse(const char * message, size_t length,
122 struct mailimf_mailbox_list ** result);
125 mailimf_address_list_parse will parse the given address list
127 @param message this is a string containing the address list
128 @param length this is the size of the given string
129 @param index this is a pointer to the start of the address list in
130 the given string, (* index) is modified to point at the end
132 @param result the result of the parse operation is stored in
135 @return MAILIMF_NO_ERROR on success, MAILIMF_ERROR_XXX on error
139 mailimf_address_list_parse(const char * message, size_t length,
141 struct mailimf_address_list ** result);
144 mailimf_address_parse will parse the given address
146 @param message this is a string containing the address
147 @param length this is the size of the given string
148 @param index this is a pointer to the start of the address in
149 the given string, (* index) is modified to point at the end
151 @param result the result of the parse operation is stored in
154 @return MAILIMF_NO_ERROR on success, MAILIMF_ERROR_XXX on error
157 int mailimf_address_parse(const char * message, size_t length,
159 struct mailimf_address ** result);
162 mailimf_mailbox_parse will parse the given address
164 @param message this is a string containing the mailbox
165 @param length this is the size of the given string
166 @param index this is a pointer to the start of the mailbox in
167 the given string, (* index) is modified to point at the end
169 @param result the result of the parse operation is stored in
172 @return MAILIMF_NO_ERROR on success, MAILIMF_ERROR_XXX on error
175 int mailimf_mailbox_parse(const char * message, size_t length,
177 struct mailimf_mailbox ** result);
180 mailimf_date_time_parse will parse the given RFC 2822 date
182 @param message this is a string containing the date
183 @param length this is the size of the given string
184 @param index this is a pointer to the start of the date in
185 the given string, (* index) is modified to point at the end
187 @param result the result of the parse operation is stored in
190 @return MAILIMF_NO_ERROR on success, MAILIMF_ERROR_XXX on error
193 int mailimf_date_time_parse(const char * message, size_t length,
195 struct mailimf_date_time ** result);
198 mailimf_envelope_fields_parse will parse the given fields (Date,
199 From, Sender, Reply-To, To, Cc, Bcc, Message-ID, In-Reply-To,
200 References and Subject)
202 @param message this is a string containing the header fields
203 @param length this is the size of the given string
204 @param index this is a pointer to the start of the header fields in
205 the given string, (* index) is modified to point at the end
207 @param result the result of the parse operation is stored in
210 @return MAILIMF_NO_ERROR on success, MAILIMF_ERROR_XXX on error
213 int mailimf_envelope_fields_parse(const char * message, size_t length,
215 struct mailimf_fields ** result);
218 mailimf_ignore_field_parse will skip the given field
220 @param message this is a string containing the header field
221 @param length this is the size of the given string
222 @param index this is a pointer to the start of the header field in
223 the given string, (* index) is modified to point at the end
226 @return MAILIMF_NO_ERROR on success, MAILIMF_ERROR_XXX on error
230 int mailimf_ignore_field_parse(const char * message, size_t length,
234 mailimf_envelope_fields will parse the given fields (Date,
235 From, Sender, Reply-To, To, Cc, Bcc, Message-ID, In-Reply-To,
236 References and Subject), other fields will be added as optional
239 @param message this is a string containing the header fields
240 @param length this is the size of the given string
241 @param index this is a pointer to the start of the header fields in
242 the given string, (* index) is modified to point at the end
244 @param result the result of the parse operation is stored in
247 @return MAILIMF_NO_ERROR on success, MAILIMF_ERROR_XXX on error
252 mailimf_envelope_and_optional_fields_parse(const char * message, size_t length,
254 struct mailimf_fields ** result);
257 mailimf_envelope_fields will parse the given fields as optional
260 @param message this is a string containing the header fields
261 @param length this is the size of the given string
262 @param index this is a pointer to the start of the header fields in
263 the given string, (* index) is modified to point at the end
265 @param result the result of the parse operation is stored in
268 @return MAILIMF_NO_ERROR on success, MAILIMF_ERROR_XXX on error
272 mailimf_optional_fields_parse(const char * message, size_t length,
274 struct mailimf_fields ** result);
277 /* internal use, exported for MIME */
279 int mailimf_fws_parse(const char * message, size_t length, size_t * index);
281 int mailimf_cfws_parse(const char * message, size_t length,
284 int mailimf_char_parse(const char * message, size_t length,
285 size_t * index, char token);
287 int mailimf_unstrict_char_parse(const char * message, size_t length,
288 size_t * index, char token);
290 int mailimf_crlf_parse(const char * message, size_t length, size_t * index);
293 mailimf_custom_string_parse(const char * message, size_t length,
294 size_t * index, char ** result,
295 int (* is_custom_char)(char));
298 mailimf_token_case_insensitive_len_parse(const char * message, size_t length,
299 size_t * index, char * token,
300 size_t token_length);
302 #define mailimf_token_case_insensitive_parse(message, length, index, token) \
303 mailimf_token_case_insensitive_len_parse(message, length, index, token, \
306 int mailimf_quoted_string_parse(const char * message, size_t length,
307 size_t * index, char ** result);
310 mailimf_number_parse(const char * message, size_t length,
311 size_t * index, uint32_t * result);
313 int mailimf_msg_id_parse(const char * message, size_t length,
317 int mailimf_msg_id_list_parse(const char * message, size_t length,
318 size_t * index, clist ** result);
320 int mailimf_word_parse(const char * message, size_t length,
321 size_t * index, char ** result);
323 int mailimf_atom_parse(const char * message, size_t length,
324 size_t * index, char ** result);
326 int mailimf_fws_atom_parse(const char * message, size_t length,
327 size_t * index, char ** result);
329 int mailimf_fws_word_parse(const char * message, size_t length,
330 size_t * index, char ** result);
332 int mailimf_fws_quoted_string_parse(const char * message, size_t length,
333 size_t * index, char ** result);
335 /* exported for IMAP */
337 int mailimf_references_parse(const char * message, size_t length,
339 struct mailimf_references ** result);