Mstdlib-1.24.0
m_email.h
1/* The MIT License (MIT)
2 *
3 * Copyright (c) 2020 Monetra Technologies, LLC.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 * THE SOFTWARE.
22 */
23
24#ifndef __M_EMAIL_H__
25#define __M_EMAIL_H__
26
27/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
28
29#include <mstdlib/base/m_defs.h>
30#include <mstdlib/base/m_types.h>
31
32/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
33
34__BEGIN_DECLS
35
36/*! \addtogroup m_email Email
37 * \ingroup m_formats
38 *
39 * \warning incomplete and under active development
40 *
41 * Email envelope reading and writing.
42 *
43 * This is a flexible implementation and does not auto encode or decode. Also, only
44 * minimal data validation is performed. It is possible generate messages that are
45 * not standard compliant but it should not be possible to generate a email that
46 * with this module that cannot then be parsed by this module.
47 *
48 * Conforms to:
49 * - RFC 5322 Internet Message Format
50 *
51 * Supported:
52 * - RFC 6854 Update to Internet Message Format to Allow Group Syntax in the "From:" and "Sender:" Header Fields
53 *
54 * Not supported:
55 * - RFC 2047 MIME (Multipurpose Internet Mail Extensions) Part Three: Message Header Extensions for Non-ASCII Text
56 * - Splitting multipart within a multipart body part. The sub multipart will be returned as if it is all body data
57 *
58 * There are two types of email parsing supported.
59 * - Stream based callback
60 * - Simple reader (memory buffered)
61 *
62 * Currently supported Read:
63 * - Callback
64 * - Simple
65 *
66 * Currently support Write:
67 * - Simple
68 *
69 * @{
70 */
71
72/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
73
74/*! Error codes. */
75typedef enum {
76 M_EMAIL_ERROR_SUCCESS = 0, /*!< Success. Data fully parsed data is present. More data is possible because email does not have a length indicator. However, a complete email has been seen. */
77 M_EMAIL_ERROR_MOREDATA, /*!< Incomplete email, more data required. Not necessarily an error if parsing as data is streaming. */
78 M_EMAIL_ERROR_STOP, /*!< Stop processing (Used by callback functions to indicate non-error but stop processing). */
79 M_EMAIL_ERROR_INVALIDUSE, /*!< Invalid use. */
80 M_EMAIL_ERROR_HEADER_INVALID, /*!< Header is malformed. */
81 M_EMAIL_ERROR_ADDRESS, /*!< Address is malformed. */
82 M_EMAIL_ERROR_MULTIPART_NOBOUNDARY, /*!< Multipart email missing boundary. */
83 M_EMAIL_ERROR_MULTIPART_HEADER_INVALID, /*!< Multipart email missing boundary. */
84 M_EMAIL_ERROR_MULTIPART_MISSING_DATA, /*!< Multipart data missing. */
85 M_EMAIL_ERROR_MULTIPART_INVALID, /*!< Multipart is invalid. */
86 M_EMAIL_ERROR_NOT_EMAIL, /*!< Not an EMAIL email. */
87 M_EMAIL_ERROR_USER_FAILURE /*!< Generic callback generated failure. */
89
90/*! Email Content type. */
91typedef enum {
92 M_EMAIL_DATA_FORMAT_UNKNOWN = 0, /*! Could not determine the format of the data. */
94 M_EMAIL_DATA_FORMAT_MULTIPART /*!< Data is multipart. */
96
97/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
98
99
100/*! \addtogroup m_email_msssage Email Message
101 * \ingroup m_email
102 *
103 * Email Message.
104 *
105 * @{
106 */
107
108struct M_email;
109typedef struct M_email M_email_t;
110
111
112/*! Create an empty email email
113 *
114 * return Message
115 */
117M_API void M_email_destroy(M_email_t *email);
118
119/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
120
121/* Will update / replace / remove, To, CC, BCC, Subject, Reply-To.
122 * Nothing updated on failure. */
123M_API M_bool M_email_set_headers(M_email_t *email, const M_hash_dict_t *headers);
124/* If exists will add to list. Use remove if needing to replace. */
125M_API M_bool M_email_headers_insert(M_email_t *email, const char *key, const char *val);
126M_API void M_email_headers_remove(M_email_t *email, const char *key);
127/* Does not include, To, CC, BCC, Subject, Reply-To.
128 * Multi value. */
129M_API const M_hash_dict_t *M_email_headers(const M_email_t *email);
130
131/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
132
133M_API M_bool M_email_from(const M_email_t *email, char const **group, char const **name, char const **address);
134M_API char *M_email_from_field(const M_email_t *email);
135M_API void M_email_set_from(M_email_t *email, const char *group, const char *name, const char *address);
136
137/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
138
139M_API size_t M_email_to_len(const M_email_t *email);
140M_API M_bool M_email_to(const M_email_t *email, size_t idx, char const **group, char const **name, char const **address);
141M_API char *M_email_to_field(const M_email_t *email);
142M_API void M_email_to_append(M_email_t *email, const char *group, const char *name, const char *address);
143M_API void M_email_to_remove(M_email_t *email, size_t idx);
144M_API void M_email_to_clear(M_email_t *email);
145
146/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
147
148M_API size_t M_email_cc_len(const M_email_t *email);
149M_API M_bool M_email_cc(const M_email_t *email, size_t idx, char const **group, char const **name, char const **address);
150M_API char *M_email_cc_field(const M_email_t *email);
151M_API void M_email_cc_append(M_email_t *email, const char *group, const char *name, const char *address);
152M_API void M_email_cc_remove(M_email_t *email, size_t idx);
153M_API void M_email_cc_clear(M_email_t *email);
154
155/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
156
157M_API size_t M_email_bcc_len(const M_email_t *email);
158M_API M_bool M_email_bcc(const M_email_t *email, size_t idx, char const **group, char const **name, char const **address);
159M_API char *M_email_bcc_field(const M_email_t *email);
160M_API void M_email_bcc_append(M_email_t *email, const char *group, const char *name, const char *address);
161M_API void M_email_bcc_remove(M_email_t *email, size_t idx);
162M_API void M_email_bcc_clear(M_email_t *email);
163
164/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
165
166M_API void M_email_set_reply_to(M_email_t *email, const char *group, const char *name, const char *address);
167M_API char *M_email_reply_to_field(const M_email_t *email);
168M_API M_bool M_email_reply_to(const M_email_t *email, char const **group, char const **name, char const **address);
170
171/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
172
173M_API void M_email_set_subject(M_email_t *email, const char *subject);
174M_API const char *M_email_subject(const M_email_t *email);
175
176/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
177
178/*! Stamp email with randomized message id. That is, generate and assign to header "Message-ID".
179 *
180 * \param[in] email The email to stamp.
181 *
182 * \param[in] prefix Prefix to id string
183 *
184 * \param[in] suffix Suffix to id string
185 *
186 */
187M_API void M_email_messageid(M_email_t *email, const char *prefix, const char *suffix);
188
189/*! Stamp email with date. That is, generate and assign to header "Date".
190 *
191 * \param[in] email The email to stamp.
192 *
193 * \param[in] format Date format string. NULL defaults to "%a, %d %b %Y %T %z"
194 *
195 */
196M_API void M_email_date(M_email_t *email, const char *format);
197
198/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
199
200M_API const char *M_email_preamble(const M_email_t *email);
201M_API void M_email_set_preamble(M_email_t *email, const char *data, size_t len);
202M_API const char *M_email_epilouge(const M_email_t *email);
203M_API void M_email_set_epilouge(M_email_t *email, const char *data, size_t len);
204
205M_API void M_email_set_mixed_multipart(M_email_t *email, M_bool is_mixed_multipart);
206M_API M_bool M_email_is_mixed_multipart(const M_email_t *email);
207M_API M_bool M_email_part_append(M_email_t *email, const char *data, size_t len, const M_hash_dict_t *headers, size_t *idx);
208/* Headers exclude Content-Type, Content-Disposition, Content-Transfer-Encoding.
209 * If need to be parsed instead of being set directly use part_append which
210 * will parse these headers out. */
211M_API M_bool M_email_part_append_attachment(M_email_t *email, const char *data, size_t len, const M_hash_dict_t *headers, const char *content_type, const char *transfer_encoding, const char *filename, size_t *idx);
212M_API M_bool M_email_part_append_data(M_email_t *email, size_t idx, const char *data, size_t len);
213M_API M_bool M_email_part_set_data(M_email_t *email, size_t idx, const char *data, size_t len);
214
215M_API size_t M_email_parts_len(const M_email_t *email);
217
218M_API const char *M_email_part_data(const M_email_t *email, size_t idx);
219/* If attachment, exclude Content-Type, Content-Disposition, Content-Transfer-Encoding */
220M_API const M_hash_dict_t *M_email_part_headers(const M_email_t *email, size_t idx);
221
222M_API M_bool M_email_part_is_attachmenet(const M_email_t *email, size_t idx);
223M_API M_bool M_email_part_attachment_info(const M_email_t *email, size_t idx, char const **content_type, char const **transfer_encoding, char const **filename);
224
225M_API void M_email_part_remove(M_email_t *email, size_t idx);
226
227
228/*! @} */
229
230
231/*! \addtogroup m_email_reader Email Stream Reader
232 * \ingroup m_email
233 *
234 * Stream reader used for parsing using callbacks.
235 * Very useful for large Email messages.
236 *
237 * @{
238 */
239
240struct M_email_reader;
241typedef struct M_email_reader M_email_reader_t;
242
243/*! Function definition for reading headers.
244 *
245 * This will provide the full unparsed header.
246 * This is always called for every header.
247 * It may be called multiple times if a header appears multiple times.
248 *
249 * All headers will trigger this function including ones that have
250 * their own dedicated callbacks. If headers are handled in their
251 * resistive dedicated callback, they should be checked for and
252 * ignored when this callback is called.
253 *
254 * A header appearing multiple times here means it was present multiple times.
255 *
256 * \param[in] key Header key.
257 * \param[in] val Header value.
258 * \param[in] thunk Thunk.
259 *
260 * \return Result
261 *
262 * \see M_email_reader_to_func
263 * \see M_email_reader_from_func
264 * \see M_email_reader_cc_func
265 * \see M_email_reader_bcc_func
266 * \see M_email_reader_reply_to_func
267 * \see M_email_reader_subject_func
268 */
269typedef M_email_error_t (*M_email_reader_header_func)(const char *key, const char *val, void *thunk);
270
271
272/*! Function definition for To recipients
273 *
274 * This will be called for every address that appears as a To recipient.
275 * A group with no listed recipients can also be received. If address only is desired
276 * then address should be checked if empty before processing.
277 *
278 * Data combinations that could be passed as parameters:
279 * - group, name, address
280 * - name, address
281 * - group, address
282 * - group
283 *
284 * \param[in] group Email group.
285 * \param[in] name Pretty name of recipient.
286 * \param[in] address Email address of recipient.
287 * \param[in] thunk Thunk.
288 *
289 * \return Result
290 */
291typedef M_email_error_t (*M_email_reader_to_func)(const char *group, const char *name, const char *address, void *thunk);
292
293
294/*! Function definition for From sender
295 *
296 * Data combinations that could be passed as parameters:
297 * - group, name, address
298 * - name, address
299 * - group, address
300 * - group
301 *
302 * \param[in] group Email group.
303 * \param[in] name Pretty name of recipient.
304 * \param[in] address Email address of recipient.
305 * \param[in] thunk Thunk.
306 *
307 * \return Result
308 */
309typedef M_email_error_t (*M_email_reader_from_func)(const char *group, const char *name, const char *address, void *thunk);
310
311
312/*! Function definition for CC recipients
313 *
314 * This will be called for every address that appears as a CC recipient.
315 * A group with no listed recipients can also be received. If address only is desired
316 * then address should be checked if empty before processing.
317 *
318 * Data combinations that could be passed as parameters:
319 * - group, name, address
320 * - name, address
321 * - group, address
322 * - group
323 *
324 * \param[in] group Email group.
325 * \param[in] name Pretty name of recipient.
326 * \param[in] address Email address of recipient.
327 * \param[in] thunk Thunk.
328 *
329 * \return Result
330 */
331typedef M_email_error_t (*M_email_reader_cc_func)(const char *group, const char *name, const char *address, void *thunk);
332
333
334/*! Function definition for BCC recipients
335 *
336 * This will be called for every address that appears as a BCC recipient.
337 * A group with no listed recipients can also be received. If address only is desired
338 * then address should be checked if empty before processing.
339 *
340 * Data combinations that could be passed as parameters:
341 * - group, name, address
342 * - name, address
343 * - group, address
344 * - group
345 *
346 * \param[in] group Email group.
347 * \param[in] name Pretty name of recipient.
348 * \param[in] address Email address of recipient.
349 * \param[in] thunk Thunk.
350 *
351 * \return Result
352 */
353typedef M_email_error_t (*M_email_reader_bcc_func)(const char *group, const char *name, const char *address, void *thunk);
354
355
356/*! Function definition for Reply-To address
357 *
358 * Data combinations that could be passed as parameters:
359 * - group, name, address
360 * - name, address
361 * - group, address
362 * - group
363 *
364 * \param[in] group Email group.
365 * \param[in] name Pretty name of recipient.
366 * \param[in] address Email address of recipient.
367 * \param[in] thunk Thunk.
368 *
369 * \return Result
370 */
371typedef M_email_error_t (*M_email_reader_reply_to_func)(const char *group, const char *name, const char *address, void *thunk);
372
373
374/*! Function definition for the email Subject
375 *
376 * \param[in] subject The subject.
377 * \param[in] thunk Thunk.
378 *
379 * \return Result
380 */
381typedef M_email_error_t (*M_email_reader_subject_func)(const char *subject, void *thunk);
382
383
384/*! Function definition for header parsing completion.
385 *
386 * \param[in] format The format data was sent using.
387 * \param[in] thunk Thunk.
388 *
389 * \return Result
390 */
392
393
394/*! Function definition for reading body data.
395 *
396 * \param[in] data Data.
397 * \param[in] len Length of data.
398 * \param[in] thunk Thunk.
399 *
400 * \return Result
401 */
402typedef M_email_error_t (*M_email_reader_body_func)(const char *data, size_t len, void *thunk);
403
404
405/*! Function definition for reading multipart preamble.
406 *
407 * Typically the preamble should be ignored if present.
408 *
409 * \param[in] data Data.
410 * \param[in] len Length of data.
411 * \param[in] thunk Thunk.
412 *
413 * \return Result
414 */
415typedef M_email_error_t (*M_email_reader_multipart_preamble_func)(const char *data, size_t len, void *thunk);
416
417
418/*! Function definition for completion of multipart preamble parsing.
419 *
420 * Only called if a preamble was present.
421 *
422 * \param[in] thunk Thunk.
423 *
424 * \return Result
425 */
427
428/*! Function definition for reading multi part headers.
429 *
430 * This will provide the full unparsed header.
431 * This is always called for every header.
432 * It may be called multiple times if a header appears multiple times.
433 * This is intended for informational use or if passing along data and
434 * not altering any headers in the process.
435 *
436 * A header appearing multiple times here means it was present multiple times.
437 *
438 * \param[in] key Header key.
439 * \param[in] val Header value.
440 * \param[in] idx Part number the header belongs to.
441 * \param[in] thunk Thunk.
442 *
443 * \return Result
444 *
445 * \see M_http_reader_header_func
446 */
447typedef M_email_error_t (*M_email_reader_multipart_header_func)(const char *key, const char *val, size_t idx, void *thunk);
448
449
450/*! Function definition for multipart attachment meta data.
451 *
452 * Will only be called when a part is marked as an attachment.
453 * Will be called immediately before M_email_reader_multipart_header_done_func.
454 *
455 * \param[in] content_type The content type.
456 * \param[in] transfer_encoding The format the data was received in. E.g. Base64, clear text, ext..
457 * \param[in] filename The filename of the attachment.
458 * \param[in] idx Part number.
459 * \param[in] thunk Thunk.
460 *
461 * \return Result
462 */
463typedef M_email_error_t (*M_email_reader_multipart_header_attachment_func)(const char *content_type, const char *transfer_encoding, const char *filename, size_t idx, void *thunk);
464
465
466/*! Function definition for completion of multipart part header parsing.
467 *
468 * \param[in] idx Part number.
469 * \param[in] thunk Thunk.
470 *
471 * \return Result
472 */
474
475
476/*! Function definition for reading multipart part data.
477 *
478 * \param[in] data Data.
479 * \param[in] len Length of data.
480 * \param[in] idx Partnumber the data belongs to.
481 * \param[in] thunk Thunk.
482 *
483 * \return Result
484 */
485typedef M_email_error_t (*M_email_reader_multipart_data_func)(const char *data, size_t len, size_t idx, void *thunk);
486
487
488/*! Function definition for completion of multipart part data.
489 *
490 * \param[in] idx Chunk number that has been completely processed.
491 * \param[in] thunk Thunk.
492 *
493 * \return Result
494 */
496
497
498/*! Function definition for completion of parsing all multipart parts.
499 *
500 * Only called when data is chunked.
501 *
502 * \param[in] thunk Thunk.
503 *
504 * \return Result
505 */
507
508
509/*! Function definition for completion of multipart epilogue parsing.
510 *
511 * Only called if a epilogue was present.
512 *
513 * \param[in] data Data.
514 * \param[in] len Length of data.
515 * \param[in] thunk Thunk.
516 *
517 * \return Result
518 */
519typedef M_email_error_t (*M_email_reader_multipart_epilouge_func)(const char *data, size_t len, void *thunk);
520
521
522/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
523
524/*! Flags controlling reader behavior. */
525typedef enum {
526 M_EMAIL_READER_NONE = 0 /*!< Default operation. */
528
529
530/*! Callbacks for various stages of parsing. */
550};
551
552
553/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
554
555/*! Create an email reader object.
556 *
557 * \param[in] cbs Callbacks for processing.
558 * \param[in] flags Flags controlling behavior.
559 * \param[in] thunk Thunk passed to callbacks.
560 *
561 * \return Object.
562 */
563M_API M_email_reader_t *M_email_reader_create(struct M_email_reader_callbacks *cbs, M_uint32 flags, void *thunk);
564
565
566/*! Destroy an email object.
567 *
568 * \param[in] emailr email reader object.
569 */
571
572
573/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
574
575/*! Parse email email from given data.
576 *
577 * When a parse returns without error but a full email has not been read, the
578 * parse should be run again starting where the last parse stopped. The reader
579 * can only be used once per complete email.
580 *
581 * Will _not_ return M_EMAIL_ERROR_MOREDATA. It is up to the caller to
582 * determine when a full email has been read based on the callbacks that have
583 * been called. The _done callbacks can indicate if all processing has
584 * completed. If the email is not multipart it is impossible to determine if
585 * a parse is complete.
586 *
587 * \param[in] emailr email reader object.
588 * \param[in] data Data to parse.
589 * \param[in] data_len Length of data.
590 * \param[out] len_read How much data was read.
591 *
592 * \return Result.
593 */
594M_API M_email_error_t M_email_reader_read(M_email_reader_t *emailr, const char *data, size_t data_len, size_t *len_read);
595
596/*! @} */
597
598/*! \addtogroup m_email_simple Email Simple
599 * \ingroup m_email
600 *
601 * Buffered reader and writer.
602 *
603 * @{
604 */
605
606/*! \addtogroup m_email_simple_read Email Simple Reader
607 * \ingroup m_email_simple
608 *
609 * Reads a full email. Useful for small messages.
610 * Alls all data is contained within an email object for
611 * easy processing.
612 *
613 * @{
614 */
615
616typedef enum {
619
620/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
621
622/*! Read the next email from the given buffer, store results in a new M_email_t object.
623 *
624 * Will return M_EMAIL_ERROR_MOREDATA if we need to wait for more data to get a complete email.
625 *
626 * \param[out] email Place to store new M_email_t object. Can be NULL to check for valid email.
627 * Will only be set on M_EMAIL_ERROR_SUCCESS, and M_EMAIL_ERROR_SUCCESS_MORE_POSSIBLE.
628 * \param[in] data Buffer containing EMAIL messages to read.
629 * \param[in] data_len Length of \a data.
630 * \param[in] flags Read options (OR'd combo of M_email_simple_read_flags_t).
631 * \param[in] len_read Num bytes consumed from \a data (may be NULL, if caller doesn't need this info).
632 * Will be set on error indicating the location in the email that generated the error.
633 *
634 * \return Response code.
635 *
636 * \see M_email_reader_read
637 * \see M_email_simple_read_parser
638 */
639M_API M_email_error_t M_email_simple_read(M_email_t **email, const char *data, size_t data_len, M_uint32 flags, size_t *len_read);
640
641
642/*! Read the next email from the given parser.
643 *
644 * Will return M_EMAIL_ERROR_MOREDATA if we need to wait for more data to get a complete email.
645 * No data will be dropped from the parser, in this case.
646 *
647 * On all other return values the parser will advance and data consumed. On a hard ERROR condition
648 * the parser will start at the point of the error. If this is undesirable, the parser should be
649 * marked and rewound after this function is called.
650 *
651 * \param[out] email Place to store new M_email_t object. Can be NULL to check for valid email.
652 * Will only be set on M_EMAIL_ERROR_SUCCESS, and M_EMAIL_ERROR_SUCCESS_MORE_POSSIBLE.
653 * \param[in] parser Buffer containing messages to read.
654 * \param[in] flags Read options (OR'd combo of M_email_simple_read_flags_t).
655 *
656 * \return Response code.
657 *
658 * \see M_email_reader_read
659 * \see M_email_simple_read
660 */
661M_API M_email_error_t M_email_simple_read_parser(M_email_t **email, M_parser_t *parser, M_uint32 flags);
662
663/*! @} */
664
665
666/*! \addtogroup m_email_simple_write Email Simple Writer
667 * \ingroup m_email_simple
668 *
669 * Writes an email. Useful for small messages.
670 * Alls all data is contained within an email object for
671 * easy processing.
672 *
673 * @{
674 */
675
676/*! Create an email message string.
677 *
678 * \param[in] email Email object.
679 *
680 * \return String.
681 */
682M_API char *M_email_simple_write(const M_email_t *email);
683
684
685/*! Create an email message string added to the given buffer.
686 *
687 * \param[in] email Email object.
688 * \param[in] buf Buffer to write message.
689 *
690 * \return M_TRUE on success, otherwise M_FALSE.
691 */
692M_API M_bool M_email_simple_write_buf(const M_email_t *email, M_buf_t *buf);
693
694/*! @} */
695
696
697/*! \addtogroup m_email_simple_helper Email Simple Helpers
698 * \ingroup m_email_simple
699 *
700 * @{
701 */
702
703M_API M_email_error_t M_email_simple_split_header_body(const char *message, M_hash_dict_t **headers, char **body);
704
705/*! @} */
706
707/*! @} */
708
709/*! \addtogroup m_email_address Email Address
710 * \ingroup m_email
711 *
712 * @{
713 */
714
715M_API M_email_error_t M_email_process_address(const char *val, M_email_error_t (*address_func)(const char *group, const char *name, const char *address, void *thunk), void *thunk);
716M_API char *M_email_write_single_recipient(const char *group, const char *name, const char *address);
717
718/*! @} */
719
720/*! @} */
721
722__END_DECLS
723
724#endif /* __M_EMAIL_H__ */
struct M_buf M_buf_t
Definition: m_buf.h:77
M_email_error_t M_email_process_address(const char *val, M_email_error_t(*address_func)(const char *group, const char *name, const char *address, void *thunk), void *thunk)
char * M_email_write_single_recipient(const char *group, const char *name, const char *address)
M_bool M_email_headers_insert(M_email_t *email, const char *key, const char *val)
M_bool M_email_from(const M_email_t *email, char const **group, char const **name, char const **address)
void M_email_headers_remove(M_email_t *email, const char *key)
char * M_email_to_field(const M_email_t *email)
size_t M_email_to_len(const M_email_t *email)
void M_email_bcc_remove(M_email_t *email, size_t idx)
M_email_t * M_email_create(void)
M_bool M_email_reply_to(const M_email_t *email, char const **group, char const **name, char const **address)
void M_email_messageid(M_email_t *email, const char *prefix, const char *suffix)
char * M_email_bcc_field(const M_email_t *email)
void M_email_parts_clear(M_email_t *email)
void M_email_set_subject(M_email_t *email, const char *subject)
M_bool M_email_part_is_attachmenet(const M_email_t *email, size_t idx)
M_bool M_email_set_headers(M_email_t *email, const M_hash_dict_t *headers)
void M_email_to_append(M_email_t *email, const char *group, const char *name, const char *address)
void M_email_to_remove(M_email_t *email, size_t idx)
const char * M_email_subject(const M_email_t *email)
size_t M_email_bcc_len(const M_email_t *email)
char * M_email_cc_field(const M_email_t *email)
void M_email_set_from(M_email_t *email, const char *group, const char *name, const char *address)
const char * M_email_epilouge(const M_email_t *email)
void M_email_set_preamble(M_email_t *email, const char *data, size_t len)
M_bool M_email_is_mixed_multipart(const M_email_t *email)
void M_email_set_epilouge(M_email_t *email, const char *data, size_t len)
struct M_email M_email_t
Definition: m_email.h:109
const char * M_email_preamble(const M_email_t *email)
void M_email_set_reply_to(M_email_t *email, const char *group, const char *name, const char *address)
void M_email_part_remove(M_email_t *email, size_t idx)
M_bool M_email_part_set_data(M_email_t *email, size_t idx, const char *data, size_t len)
char * M_email_from_field(const M_email_t *email)
void M_email_cc_clear(M_email_t *email)
const M_hash_dict_t * M_email_part_headers(const M_email_t *email, size_t idx)
M_bool M_email_part_append(M_email_t *email, const char *data, size_t len, const M_hash_dict_t *headers, size_t *idx)
void M_email_to_clear(M_email_t *email)
char * M_email_reply_to_field(const M_email_t *email)
void M_email_set_mixed_multipart(M_email_t *email, M_bool is_mixed_multipart)
size_t M_email_cc_len(const M_email_t *email)
void M_email_bcc_clear(M_email_t *email)
size_t M_email_parts_len(const M_email_t *email)
void M_email_date(M_email_t *email, const char *format)
M_bool M_email_part_append_data(M_email_t *email, size_t idx, const char *data, size_t len)
const M_hash_dict_t * M_email_headers(const M_email_t *email)
M_bool M_email_cc(const M_email_t *email, size_t idx, char const **group, char const **name, char const **address)
M_bool M_email_to(const M_email_t *email, size_t idx, char const **group, char const **name, char const **address)
void M_email_bcc_append(M_email_t *email, const char *group, const char *name, const char *address)
void M_email_reply_to_remove(M_email_t *email)
void M_email_cc_remove(M_email_t *email, size_t idx)
M_bool M_email_part_append_attachment(M_email_t *email, const char *data, size_t len, const M_hash_dict_t *headers, const char *content_type, const char *transfer_encoding, const char *filename, size_t *idx)
void M_email_cc_append(M_email_t *email, const char *group, const char *name, const char *address)
const char * M_email_part_data(const M_email_t *email, size_t idx)
M_bool M_email_bcc(const M_email_t *email, size_t idx, char const **group, char const **name, char const **address)
M_bool M_email_part_attachment_info(const M_email_t *email, size_t idx, char const **content_type, char const **transfer_encoding, char const **filename)
void M_email_destroy(M_email_t *email)
M_email_reader_subject_func subject_func
Definition: m_email.h:538
M_email_reader_reply_to_func reply_to_func
Definition: m_email.h:537
M_email_reader_to_func to_func
Definition: m_email.h:533
M_email_reader_cc_func cc_func
Definition: m_email.h:535
M_email_reader_multipart_data_func multipart_data_func
Definition: m_email.h:546
M_email_reader_header_done_func header_done_func
Definition: m_email.h:539
M_email_reader_body_func body_func
Definition: m_email.h:540
M_email_reader_multipart_preamble_done_func multipart_preamble_done_func
Definition: m_email.h:542
M_email_reader_multipart_preamble_func multipart_preamble_func
Definition: m_email.h:541
M_email_reader_from_func from_func
Definition: m_email.h:534
M_email_reader_multipart_header_done_func multipart_header_done_func
Definition: m_email.h:545
M_email_reader_header_func header_func
Definition: m_email.h:532
M_email_reader_multipart_header_func multipart_header_func
Definition: m_email.h:543
M_email_reader_multipart_data_done_func multipart_data_done_func
Definition: m_email.h:547
M_email_reader_multipart_epilouge_func multipart_epilouge_func
Definition: m_email.h:549
M_email_reader_multipart_header_attachment_func multipart_header_attachment_func
Definition: m_email.h:544
M_email_reader_multipart_data_finished_func multipart_data_finished_func
Definition: m_email.h:548
M_email_reader_bcc_func bcc_func
Definition: m_email.h:536
M_email_error_t(* M_email_reader_header_func)(const char *key, const char *val, void *thunk)
Definition: m_email.h:269
M_email_reader_t * M_email_reader_create(struct M_email_reader_callbacks *cbs, M_uint32 flags, void *thunk)
M_email_error_t(* M_email_reader_to_func)(const char *group, const char *name, const char *address, void *thunk)
Definition: m_email.h:291
struct M_email_reader M_email_reader_t
Definition: m_email.h:241
M_email_error_t(* M_email_reader_multipart_data_finished_func)(void *thunk)
Definition: m_email.h:506
M_email_error_t(* M_email_reader_header_done_func)(M_email_data_format_t format, void *thunk)
Definition: m_email.h:391
M_email_error_t(* M_email_reader_multipart_data_func)(const char *data, size_t len, size_t idx, void *thunk)
Definition: m_email.h:485
M_email_error_t(* M_email_reader_cc_func)(const char *group, const char *name, const char *address, void *thunk)
Definition: m_email.h:331
M_email_reader_flags_t
Definition: m_email.h:525
M_email_error_t M_email_reader_read(M_email_reader_t *emailr, const char *data, size_t data_len, size_t *len_read)
M_email_error_t(* M_email_reader_multipart_header_func)(const char *key, const char *val, size_t idx, void *thunk)
Definition: m_email.h:447
M_email_error_t(* M_email_reader_multipart_preamble_done_func)(void *thunk)
Definition: m_email.h:426
void M_email_reader_destroy(M_email_reader_t *emailr)
M_email_error_t(* M_email_reader_multipart_header_attachment_func)(const char *content_type, const char *transfer_encoding, const char *filename, size_t idx, void *thunk)
Definition: m_email.h:463
M_email_error_t(* M_email_reader_subject_func)(const char *subject, void *thunk)
Definition: m_email.h:381
M_email_error_t(* M_email_reader_from_func)(const char *group, const char *name, const char *address, void *thunk)
Definition: m_email.h:309
M_email_error_t(* M_email_reader_multipart_preamble_func)(const char *data, size_t len, void *thunk)
Definition: m_email.h:415
M_email_error_t(* M_email_reader_body_func)(const char *data, size_t len, void *thunk)
Definition: m_email.h:402
M_email_error_t(* M_email_reader_bcc_func)(const char *group, const char *name, const char *address, void *thunk)
Definition: m_email.h:353
M_email_error_t(* M_email_reader_reply_to_func)(const char *group, const char *name, const char *address, void *thunk)
Definition: m_email.h:371
M_email_error_t(* M_email_reader_multipart_header_done_func)(size_t idx, void *thunk)
Definition: m_email.h:473
M_email_error_t(* M_email_reader_multipart_data_done_func)(size_t idx, void *thunk)
Definition: m_email.h:495
M_email_error_t(* M_email_reader_multipart_epilouge_func)(const char *data, size_t len, void *thunk)
Definition: m_email.h:519
@ M_EMAIL_READER_NONE
Definition: m_email.h:526
Definition: m_email.h:531
M_email_error_t M_email_simple_split_header_body(const char *message, M_hash_dict_t **headers, char **body)
M_email_error_t M_email_simple_read_parser(M_email_t **email, M_parser_t *parser, M_uint32 flags)
M_email_error_t M_email_simple_read(M_email_t **email, const char *data, size_t data_len, M_uint32 flags, size_t *len_read)
M_email_simple_read_flags_t
Definition: m_email.h:616
@ M_EMAIL_SIMPLE_READ_NONE
Definition: m_email.h:617
M_bool M_email_simple_write_buf(const M_email_t *email, M_buf_t *buf)
char * M_email_simple_write(const M_email_t *email)
M_email_data_format_t
Definition: m_email.h:91
M_email_error_t
Definition: m_email.h:75
@ M_EMAIL_DATA_FORMAT_MULTIPART
Definition: m_email.h:94
@ M_EMAIL_DATA_FORMAT_UNKNOWN
Definition: m_email.h:92
@ M_EMAIL_DATA_FORMAT_BODY
Definition: m_email.h:93
@ M_EMAIL_ERROR_MULTIPART_HEADER_INVALID
Definition: m_email.h:83
@ M_EMAIL_ERROR_MULTIPART_NOBOUNDARY
Definition: m_email.h:82
@ M_EMAIL_ERROR_INVALIDUSE
Definition: m_email.h:79
@ M_EMAIL_ERROR_HEADER_INVALID
Definition: m_email.h:80
@ M_EMAIL_ERROR_SUCCESS
Definition: m_email.h:76
@ M_EMAIL_ERROR_MOREDATA
Definition: m_email.h:77
@ M_EMAIL_ERROR_MULTIPART_MISSING_DATA
Definition: m_email.h:84
@ M_EMAIL_ERROR_NOT_EMAIL
Definition: m_email.h:86
@ M_EMAIL_ERROR_MULTIPART_INVALID
Definition: m_email.h:85
@ M_EMAIL_ERROR_USER_FAILURE
Definition: m_email.h:87
@ M_EMAIL_ERROR_ADDRESS
Definition: m_email.h:81
@ M_EMAIL_ERROR_STOP
Definition: m_email.h:78
struct M_hash_dict M_hash_dict_t
Definition: m_hash_dict.h:52
struct M_parser M_parser_t
Definition: m_parser.h:52