Mstdlib-1.24.0
Email Stream Reader

Data Structures

Typedefs

typedef struct M_email_reader M_email_reader_t
 
typedef M_email_error_t(* M_email_reader_header_func) (const char *key, const char *val, void *thunk)
 
typedef M_email_error_t(* M_email_reader_to_func) (const char *group, const char *name, const char *address, void *thunk)
 
typedef M_email_error_t(* M_email_reader_from_func) (const char *group, const char *name, const char *address, void *thunk)
 
typedef M_email_error_t(* M_email_reader_cc_func) (const char *group, const char *name, const char *address, void *thunk)
 
typedef M_email_error_t(* M_email_reader_bcc_func) (const char *group, const char *name, const char *address, void *thunk)
 
typedef M_email_error_t(* M_email_reader_reply_to_func) (const char *group, const char *name, const char *address, void *thunk)
 
typedef M_email_error_t(* M_email_reader_subject_func) (const char *subject, void *thunk)
 
typedef M_email_error_t(* M_email_reader_header_done_func) (M_email_data_format_t format, void *thunk)
 
typedef M_email_error_t(* M_email_reader_body_func) (const char *data, size_t len, void *thunk)
 
typedef M_email_error_t(* M_email_reader_multipart_preamble_func) (const char *data, size_t len, void *thunk)
 
typedef M_email_error_t(* M_email_reader_multipart_preamble_done_func) (void *thunk)
 
typedef M_email_error_t(* M_email_reader_multipart_header_func) (const char *key, const char *val, size_t idx, void *thunk)
 
typedef 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)
 
typedef M_email_error_t(* M_email_reader_multipart_header_done_func) (size_t idx, void *thunk)
 
typedef M_email_error_t(* M_email_reader_multipart_data_func) (const char *data, size_t len, size_t idx, void *thunk)
 
typedef M_email_error_t(* M_email_reader_multipart_data_done_func) (size_t idx, void *thunk)
 
typedef M_email_error_t(* M_email_reader_multipart_data_finished_func) (void *thunk)
 
typedef M_email_error_t(* M_email_reader_multipart_epilouge_func) (const char *data, size_t len, void *thunk)
 

Enumerations

enum  M_email_reader_flags_t { M_EMAIL_READER_NONE = 0 }
 

Functions

M_email_reader_tM_email_reader_create (struct M_email_reader_callbacks *cbs, M_uint32 flags, void *thunk)
 
void M_email_reader_destroy (M_email_reader_t *emailr)
 
M_email_error_t M_email_reader_read (M_email_reader_t *emailr, const char *data, size_t data_len, size_t *len_read)
 

Detailed Description

Stream reader used for parsing using callbacks. Very useful for large Email messages.


Data Structure Documentation

◆ M_email_reader_callbacks

struct M_email_reader_callbacks

Callbacks for various stages of parsing.

Data Fields
M_email_reader_header_func header_func
M_email_reader_to_func to_func
M_email_reader_from_func from_func
M_email_reader_cc_func cc_func
M_email_reader_bcc_func bcc_func
M_email_reader_reply_to_func reply_to_func
M_email_reader_subject_func subject_func
M_email_reader_header_done_func header_done_func
M_email_reader_body_func body_func
M_email_reader_multipart_preamble_func multipart_preamble_func
M_email_reader_multipart_preamble_done_func multipart_preamble_done_func
M_email_reader_multipart_header_func multipart_header_func
M_email_reader_multipart_header_attachment_func multipart_header_attachment_func
M_email_reader_multipart_header_done_func multipart_header_done_func
M_email_reader_multipart_data_func multipart_data_func
M_email_reader_multipart_data_done_func multipart_data_done_func
M_email_reader_multipart_data_finished_func multipart_data_finished_func
M_email_reader_multipart_epilouge_func multipart_epilouge_func

Typedef Documentation

◆ M_email_reader_t

typedef struct M_email_reader M_email_reader_t

◆ M_email_reader_header_func

typedef M_email_error_t(* M_email_reader_header_func) (const char *key, const char *val, void *thunk)

Function definition for reading headers.

This will provide the full unparsed header. This is always called for every header. It may be called multiple times if a header appears multiple times.

All headers will trigger this function including ones that have their own dedicated callbacks. If headers are handled in their resistive dedicated callback, they should be checked for and ignored when this callback is called.

A header appearing multiple times here means it was present multiple times.

Parameters
[in]keyHeader key.
[in]valHeader value.
[in]thunkThunk.
Returns
Result
See also
M_email_reader_to_func
M_email_reader_from_func
M_email_reader_cc_func
M_email_reader_bcc_func
M_email_reader_reply_to_func
M_email_reader_subject_func

◆ M_email_reader_to_func

typedef M_email_error_t(* M_email_reader_to_func) (const char *group, const char *name, const char *address, void *thunk)

Function definition for To recipients

This will be called for every address that appears as a To recipient. A group with no listed recipients can also be received. If address only is desired then address should be checked if empty before processing.

Data combinations that could be passed as parameters:

  • group, name, address
  • name, address
  • group, address
  • group
Parameters
[in]groupEmail group.
[in]namePretty name of recipient.
[in]addressEmail address of recipient.
[in]thunkThunk.
Returns
Result

◆ M_email_reader_from_func

typedef M_email_error_t(* M_email_reader_from_func) (const char *group, const char *name, const char *address, void *thunk)

Function definition for From sender

Data combinations that could be passed as parameters:

  • group, name, address
  • name, address
  • group, address
  • group
Parameters
[in]groupEmail group.
[in]namePretty name of recipient.
[in]addressEmail address of recipient.
[in]thunkThunk.
Returns
Result

◆ M_email_reader_cc_func

typedef M_email_error_t(* M_email_reader_cc_func) (const char *group, const char *name, const char *address, void *thunk)

Function definition for CC recipients

This will be called for every address that appears as a CC recipient. A group with no listed recipients can also be received. If address only is desired then address should be checked if empty before processing.

Data combinations that could be passed as parameters:

  • group, name, address
  • name, address
  • group, address
  • group
Parameters
[in]groupEmail group.
[in]namePretty name of recipient.
[in]addressEmail address of recipient.
[in]thunkThunk.
Returns
Result

◆ M_email_reader_bcc_func

typedef M_email_error_t(* M_email_reader_bcc_func) (const char *group, const char *name, const char *address, void *thunk)

Function definition for BCC recipients

This will be called for every address that appears as a BCC recipient. A group with no listed recipients can also be received. If address only is desired then address should be checked if empty before processing.

Data combinations that could be passed as parameters:

  • group, name, address
  • name, address
  • group, address
  • group
Parameters
[in]groupEmail group.
[in]namePretty name of recipient.
[in]addressEmail address of recipient.
[in]thunkThunk.
Returns
Result

◆ M_email_reader_reply_to_func

typedef M_email_error_t(* M_email_reader_reply_to_func) (const char *group, const char *name, const char *address, void *thunk)

Function definition for Reply-To address

Data combinations that could be passed as parameters:

  • group, name, address
  • name, address
  • group, address
  • group
Parameters
[in]groupEmail group.
[in]namePretty name of recipient.
[in]addressEmail address of recipient.
[in]thunkThunk.
Returns
Result

◆ M_email_reader_subject_func

typedef M_email_error_t(* M_email_reader_subject_func) (const char *subject, void *thunk)

Function definition for the email Subject

Parameters
[in]subjectThe subject.
[in]thunkThunk.
Returns
Result

◆ M_email_reader_header_done_func

typedef M_email_error_t(* M_email_reader_header_done_func) (M_email_data_format_t format, void *thunk)

Function definition for header parsing completion.

Parameters
[in]formatThe format data was sent using.
[in]thunkThunk.
Returns
Result

◆ M_email_reader_body_func

typedef M_email_error_t(* M_email_reader_body_func) (const char *data, size_t len, void *thunk)

Function definition for reading body data.

Parameters
[in]dataData.
[in]lenLength of data.
[in]thunkThunk.
Returns
Result

◆ M_email_reader_multipart_preamble_func

typedef M_email_error_t(* M_email_reader_multipart_preamble_func) (const char *data, size_t len, void *thunk)

Function definition for reading multipart preamble.

Typically the preamble should be ignored if present.

Parameters
[in]dataData.
[in]lenLength of data.
[in]thunkThunk.
Returns
Result

◆ M_email_reader_multipart_preamble_done_func

typedef M_email_error_t(* M_email_reader_multipart_preamble_done_func) (void *thunk)

Function definition for completion of multipart preamble parsing.

Only called if a preamble was present.

Parameters
[in]thunkThunk.
Returns
Result

◆ M_email_reader_multipart_header_func

typedef M_email_error_t(* M_email_reader_multipart_header_func) (const char *key, const char *val, size_t idx, void *thunk)

Function definition for reading multi part headers.

This will provide the full unparsed header. This is always called for every header. It may be called multiple times if a header appears multiple times. This is intended for informational use or if passing along data and not altering any headers in the process.

A header appearing multiple times here means it was present multiple times.

Parameters
[in]keyHeader key.
[in]valHeader value.
[in]idxPart number the header belongs to.
[in]thunkThunk.
Returns
Result
See also
M_http_reader_header_func

◆ M_email_reader_multipart_header_attachment_func

typedef 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)

Function definition for multipart attachment meta data.

Will only be called when a part is marked as an attachment. Will be called immediately before M_email_reader_multipart_header_done_func.

Parameters
[in]content_typeThe content type.
[in]transfer_encodingThe format the data was received in. E.g. Base64, clear text, ext..
[in]filenameThe filename of the attachment.
[in]idxPart number.
[in]thunkThunk.
Returns
Result

◆ M_email_reader_multipart_header_done_func

typedef M_email_error_t(* M_email_reader_multipart_header_done_func) (size_t idx, void *thunk)

Function definition for completion of multipart part header parsing.

Parameters
[in]idxPart number.
[in]thunkThunk.
Returns
Result

◆ M_email_reader_multipart_data_func

typedef M_email_error_t(* M_email_reader_multipart_data_func) (const char *data, size_t len, size_t idx, void *thunk)

Function definition for reading multipart part data.

Parameters
[in]dataData.
[in]lenLength of data.
[in]idxPartnumber the data belongs to.
[in]thunkThunk.
Returns
Result

◆ M_email_reader_multipart_data_done_func

typedef M_email_error_t(* M_email_reader_multipart_data_done_func) (size_t idx, void *thunk)

Function definition for completion of multipart part data.

Parameters
[in]idxChunk number that has been completely processed.
[in]thunkThunk.
Returns
Result

◆ M_email_reader_multipart_data_finished_func

typedef M_email_error_t(* M_email_reader_multipart_data_finished_func) (void *thunk)

Function definition for completion of parsing all multipart parts.

Only called when data is chunked.

Parameters
[in]thunkThunk.
Returns
Result

◆ M_email_reader_multipart_epilouge_func

typedef M_email_error_t(* M_email_reader_multipart_epilouge_func) (const char *data, size_t len, void *thunk)

Function definition for completion of multipart epilogue parsing.

Only called if a epilogue was present.

Parameters
[in]dataData.
[in]lenLength of data.
[in]thunkThunk.
Returns
Result

Enumeration Type Documentation

◆ M_email_reader_flags_t

Flags controlling reader behavior.

Enumerator
M_EMAIL_READER_NONE 

Default operation.

Function Documentation

◆ M_email_reader_create()

M_email_reader_t * M_email_reader_create ( struct M_email_reader_callbacks cbs,
M_uint32  flags,
void *  thunk 
)

Create an email reader object.

Parameters
[in]cbsCallbacks for processing.
[in]flagsFlags controlling behavior.
[in]thunkThunk passed to callbacks.
Returns
Object.

◆ M_email_reader_destroy()

void M_email_reader_destroy ( M_email_reader_t emailr)

Destroy an email object.

Parameters
[in]emailremail reader object.

◆ M_email_reader_read()

M_email_error_t M_email_reader_read ( M_email_reader_t emailr,
const char *  data,
size_t  data_len,
size_t *  len_read 
)

Parse email email from given data.

When a parse returns without error but a full email has not been read, the parse should be run again starting where the last parse stopped. The reader can only be used once per complete email.

Will not return M_EMAIL_ERROR_MOREDATA. It is up to the caller to determine when a full email has been read based on the callbacks that have been called. The _done callbacks can indicate if all processing has completed. If the email is not multipart it is impossible to determine if a parse is complete.

Parameters
[in]emailremail reader object.
[in]dataData to parse.
[in]data_lenLength of data.
[out]len_readHow much data was read.
Returns
Result.