smf_message.h File Reference

Defines the SMFMessage_T data type and related functions. More...

#include <cmime.h>
#include "smf_core.h"
#include "smf_email_address.h"
#include "smf_header.h"
#include "smf_list.h"
#include "smf_part.h"
Include dependency graph for smf_message.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef CMimeMessage_T SMFMessage_T
 Represents an email message.
 

Enumerations

enum  SMFMultipartType_T {
  SMF_MULTIPART_MIXED, SMF_MULTIPART_DIGEST, SMF_MULTIPART_MESSAGE, SMF_MULTIPART_ALTERNATIVE,
  SMF_MULTIPART_RELATED
}
 Possible multipart mime subtypes. More...
 

Functions

SMFMessage_Tsmf_message_new (void)
 Creates a new SMFMessage_T object.
 
void smf_message_free (SMFMessage_T *message)
 Free SMFMessage_T object.
 
void smf_message_set_sender (SMFMessage_T *message, const char *sender)
 
SMFEmailAddress_Tsmf_message_get_sender (SMFMessage_T *message)
 Gets a SMFEmailAddress_T object of the sender from message.
 
char * smf_message_get_sender_string (SMFMessage_T *message)
 Get sender of a SMFMessage_T object as string.
 
void smf_message_set_message_id (SMFMessage_T *message, const char *message_id)
 Set the Message-Id on a message.
 
char * smf_message_get_message_id (SMFMessage_T *message)
 Get the Message-Id of a message.
 
char * smf_message_generate_message_id (void)
 
int smf_message_set_header (SMFMessage_T *message, const char *header)
 Set a header to message object. If header already exists, it will be overwritten.
 
int smf_message_update_header (SMFMessage_T *message, const char *header, const char *value)
 Updates the header-value with the given key.
 
int smf_message_add_header (SMFMessage_T *message, const char *header, const char *value)
 Appends the header-value to the given key.
 
SMFHeader_Tsmf_message_get_header (SMFMessage_T *message, const char *header)
 Get header for given key.
 
SMFList_Tsmf_message_get_headers (SMFMessage_T *message)
 Get list with all headers.
 
int smf_message_remove_header (SMFMessage_T *message, const char *header_name)
 Remove a header from message.
 
int smf_message_add_recipient (SMFMessage_T *message, const char *recipient, SMFEmailAddressType_T t)
 
SMFList_Tsmf_message_get_recipients (SMFMessage_T *message)
 Get list with all recipients of message.
 
void smf_message_set_content_type (SMFMessage_T *message, const char *s)
 Set Content-Type header.
 
char * smf_message_get_content_type (SMFMessage_T *message)
 Get Content-Type header value.
 
void smf_message_set_content_transfer_encoding (SMFMessage_T *message, const char *s)
 set Content-Transfer-Encoding value
 
char * smf_message_get_content_transfer_encoding (SMFMessage_T *message)
 Get Content-Transfer-Encoding value.
 
void smf_message_set_content_id (SMFMessage_T *message, const char *s)
 Set Content-ID header value.
 
char * smf_message_get_content_id (SMFMessage_T *message)
 Get Content-ID header value.
 
void smf_message_set_mime_version (SMFMessage_T *message, const char *s)
 Set Mime-Version header value. According to RFC 2045, Mime-Version header is required at the top level of a message. Not required for each body part of a multipart entity. It's required for the embedded headers of a body of type "message/rfc822" or "message/partial" if the embedded message is itself claimed to be MIME.
 
char * smf_message_get_mime_version (SMFMessage_T *message)
 Get Mime-Version header value.
 
void smf_message_set_date (SMFMessage_T *message, const char *s)
 Set date string header.
 
char * smf_message_get_date (SMFMessage_T *message)
 Get date string from SMFMessage_T object.
 
int smf_message_set_date_now (SMFMessage_T *message)
 Get current time and set date header.
 
void smf_message_set_boundary (SMFMessage_T *message, const char *boundary)
 Set message boundary.
 
char * smf_message_get_boundary (SMFMessage_T *message)
 Get message boundary.
 
char * smf_message_generate_boundary (void)
 Generate a message boundary.
 
void smf_message_add_generated_boundary (SMFMessage_T *message)
 Add a newly generated boundary to a SMFMessage_T object.
 
void smf_message_set_subject (SMFMessage_T *message, const char *s)
 Set message subject.
 
char * smf_message_get_subject (SMFMessage_T *message)
 Get the subject string from SMFMessage_T object.
 
int smf_message_from_file (SMFMessage_T **message, const char *filename, int header_only)
 Parse given file and create a SMFMessage_T object.
 
int smf_message_to_file (SMFMessage_T *message, const char *filename)
 Write SMFMessage_T object to file.
 
int smf_message_to_fd (SMFMessage_T *message, int fd)
 Write SMFMessage_T object into the file-descriptor.
 
char * smf_message_to_string (SMFMessage_T *message)
 Allocates a string buffer containing the contents of SMFMessage_T.
 
int smf_message_from_string (SMFMessage_T **message, const char *content, int header_only)
 Parse given string and create a new SMFMessage_T object.
 
void smf_message_prepend_subject (SMFMessage_T *message, const char *s)
 prepend string to subject
 
void smf_message_append_subject (SMFMessage_T *message, const char *s)
 append string to subject
 
int smf_message_set_body (SMFMessage_T *message, const char *content)
 Set plain body to non multipart message.
 
int smf_message_append_part (SMFMessage_T *message, SMFPart_T *part)
 Append mime part to message object and generate boundary if necessary.
 
int smf_message_get_part_count (SMFMessage_T *message)
 Get number of mime parts.
 
void smf_message_add_attachment (SMFMessage_T *message, char *attachment)
 add attachment to message
 
SMFMessage_Tsmf_message_create_skeleton (const char *sender, const char *recipient, const char *subject)
 create message skeleton with basic header information
 
int smf_message_add_child_part (SMFMessage_T *message, SMFPart_T *part, SMFPart_T *child, SMFMultipartType_T subtype)
 Add a child part to given mimepart, set content type and generate a boundary if necessary.
 
SMFPart_Tsmf_message_part_first (SMFMessage_T *message)
 Get the first mime part of a SMFMessage_T object.
 
SMFPart_Tsmf_message_part_last (SMFMessage_T *message)
 Get the last mime part of a SMFMessage_T object.
 
int smf_message_write_skip_header (FILE *src, FILE *dest)
 Utility function to copy a message without the header The function reads a message from src but skips the header. When the body is reached, the content is written into dest.
 

Detailed Description

Defines the SMFMessage_T data type and related functions.

SMFMessage_T represents an email message.

To create a new SMFMessage_T, use smf_message_new()

To destroy a SMFMessage_T use smf_message_free()

Enumeration Type Documentation

Possible multipart mime subtypes.

Enumerator
SMF_MULTIPART_MIXED 

multipart/mixed

SMF_MULTIPART_DIGEST 

multipart/digest

SMF_MULTIPART_MESSAGE 

message/rfc822

SMF_MULTIPART_ALTERNATIVE 

multipart/alternative

SMF_MULTIPART_RELATED 

multipart/related

Function Documentation

void smf_message_add_attachment ( SMFMessage_T message,
char *  attachment 
)

add attachment to message

Parameters
messagea SMFMessage_T object
attachmenta file pointer
int smf_message_add_child_part ( SMFMessage_T message,
SMFPart_T part,
SMFPart_T child,
SMFMultipartType_T  subtype 
)

Add a child part to given mimepart, set content type and generate a boundary if necessary.

Parameters
messagea CMimeMessage_T object
partthe parent mime part
childthe child mime part, which should be added
subtypethe multipart subtype
Returns
0 on success or -1 in case of error
void smf_message_add_generated_boundary ( SMFMessage_T message)

Add a newly generated boundary to a SMFMessage_T object.

Parameters
messagea SMFMessage_T object
int smf_message_add_header ( SMFMessage_T message,
const char *  header,
const char *  value 
)

Appends the header-value to the given key.

If the header-entry does not exist, it will be created

Parameters
messagea SMFMessage_T object
headerThe key of the header-entry to update resp. create
valueA new value for the header-entry
Returns
0 on success or -1 in case of error
int smf_message_add_recipient ( SMFMessage_T message,
const char *  recipient,
SMFEmailAddressType_T  t 
)

Add a recipient of a chosen type to the message object.

Parameters
messageSMFMessage_T object
recipientrecipient string
tA SMFEmailAddressType_T
Returns
0 on success or -1 in case of error
int smf_message_append_part ( SMFMessage_T message,
SMFPart_T part 
)

Append mime part to message object and generate boundary if necessary.

Parameters
messagea SMFMessage_T object
parta SMFPart_T part
Returns
0 on success, -1 in case of error
void smf_message_append_subject ( SMFMessage_T message,
const char *  s 
)

append string to subject

Parameters
messagea SMFMessage_T object
sa append string for subject
SMFMessage_T* smf_message_create_skeleton ( const char *  sender,
const char *  recipient,
const char *  subject 
)

create message skeleton with basic header information

Parameters
sendera from sender
recipienta to recipient
subjecta subject string
Returns
SMFMessage_T pointer
void smf_message_free ( SMFMessage_T message)

Free SMFMessage_T object.

Free SMFMessage_T object

Parameters
messageSMFMessage_T object
int smf_message_from_file ( SMFMessage_T **  message,
const char *  filename,
int  header_only 
)

Parse given file and create a SMFMessage_T object.

Parameters
messageout param to return the new message object
filenamepath to message file
header_onlyparse only message headers, 1 = tue, 0 = false
Returns
0 on success, -1 on stat error, -2 if not a regular file, -3 if reading fails, 1 if parsing failed because of invalid input, 2 if parsing failed due to memory exhaustion
int smf_message_from_string ( SMFMessage_T **  message,
const char *  content,
int  header_only 
)

Parse given string and create a new SMFMessage_T object.

Parameters
messageout param to return the new message object
contentmessage string to parse
header_onlyparse only message headers, 1 = tue, 0 = false
Returns
0 on success or -1 in case of error, 1 if parsing failed because of invalid input, 2 if parsing failed due to memory exhaustion
char* smf_message_generate_boundary ( void  )

Generate a message boundary.

Returns
a newly allocated boundary
char* smf_message_generate_message_id ( void  )

Generates a unique Message-Id.

Returns
a unique string in an addr-spec format suitable for use as a Message-Id.
char* smf_message_get_boundary ( SMFMessage_T message)

Get message boundary.

Parameters
messagea SMFMessage_T object
Returns
message boundary
char* smf_message_get_content_id ( SMFMessage_T message)

Get Content-ID header value.

Parameters
messagea SMFMessage_T object
Returns
Content-ID header value
char* smf_message_get_content_transfer_encoding ( SMFMessage_T message)

Get Content-Transfer-Encoding value.

Parameters
messagea SMFMessage_T object
Returns
Content-Transfer-Encoding header value
char* smf_message_get_content_type ( SMFMessage_T message)

Get Content-Type header value.

Parameters
messagea SMFMessage_T object
Returns
Content-Type header value
char* smf_message_get_date ( SMFMessage_T message)

Get date string from SMFMessage_T object.

Parameters
messagea SMFMessage_T object
Returns
date string
SMFHeader_T* smf_message_get_header ( SMFMessage_T message,
const char *  header 
)

Get header for given key.

Parameters
messagea SMFMessage_T object
headername of header to search for
Returns
a SMFHeader_T object, or NULL in case of error
SMFList_T* smf_message_get_headers ( SMFMessage_T message)

Get list with all headers.

Parameters
messagea SMFMessage_T object
Returns
a SMFList_T object, or NULL in case of error
char* smf_message_get_message_id ( SMFMessage_T message)

Get the Message-Id of a message.

Parameters
messageSMFMessage_T object
Returns
the message id
char* smf_message_get_mime_version ( SMFMessage_T message)

Get Mime-Version header value.

Parameters
messagea SMFMessage_T object
Returns
Mime-Version header value
int smf_message_get_part_count ( SMFMessage_T message)

Get number of mime parts.

Parameters
messagea SMFMessage_T object
Returns
number of mime parts
SMFList_T* smf_message_get_recipients ( SMFMessage_T message)

Get list with all recipients of message.

Parameters
messagea SMFMessage_T object
Returns
SMFList_T with recipients
SMFEmailAddress_T* smf_message_get_sender ( SMFMessage_T message)

Gets a SMFEmailAddress_T object of the sender from message.

Gets the email address of the sender from message.

Parameters
messageSMFmessage_T object
Returns
the sender's name and address of the message.
char* smf_message_get_sender_string ( SMFMessage_T message)

Get sender of a SMFMessage_T object as string.

Parameters
messagea SMFMessage_T object
Returns
sender of message as newly allocated string
char* smf_message_get_subject ( SMFMessage_T message)

Get the subject string from SMFMessage_T object.

Parameters
messagea SMFMessage_T object
Returns
subject string to append
SMFMessage_T* smf_message_new ( void  )

Creates a new SMFMessage_T object.

Creates a new SMFMessage_T object

Returns
an empty message object
SMFPart_T* smf_message_part_first ( SMFMessage_T message)

Get the first mime part of a SMFMessage_T object.

Parameters
messagea SMFMessage_T object
Returns
returns the first mime part of message
SMFPart_T* smf_message_part_last ( SMFMessage_T message)

Get the last mime part of a SMFMessage_T object.

Parameters
messagea SMFMessage_T object
Returns
returns the lat mime part of message
void smf_message_prepend_subject ( SMFMessage_T message,
const char *  s 
)

prepend string to subject

Parameters
messagea SMFMessage_T object
sstring to prepend
int smf_message_remove_header ( SMFMessage_T message,
const char *  header_name 
)

Remove a header from message.

Parameters
messagea SMFMessage_T object
header_namename of the header
Returns
0 on success or -1 in case of error
int smf_message_set_body ( SMFMessage_T message,
const char *  content 
)

Set plain body to non multipart message.

Parameters
messagea SMFMessage_T object
contentbody content
Returns
0 on sucess, -1 if message is multipart
void smf_message_set_boundary ( SMFMessage_T message,
const char *  boundary 
)

Set message boundary.

Parameters
messagea SMFMessage_T object
boundarythe boundary to set
void smf_message_set_content_id ( SMFMessage_T message,
const char *  s 
)

Set Content-ID header value.

Parameters
messagea SMFMessage_T object
sContent-ID header value
void smf_message_set_content_transfer_encoding ( SMFMessage_T message,
const char *  s 
)

set Content-Transfer-Encoding value

Parameters
messagea SMFMessage_T object
sContent-Transfer-Encoding value
void smf_message_set_content_type ( SMFMessage_T message,
const char *  s 
)

Set Content-Type header.

Parameters
messagea SMFMessage_T object
sContent-Type string
void smf_message_set_date ( SMFMessage_T message,
const char *  s 
)

Set date string header.

Parameters
messagea SMFMessage_T object
sdate string
int smf_message_set_date_now ( SMFMessage_T message)

Get current time and set date header.

Parameters
messagea SMFMessage_T object
Returns
0 on success or -1 in case of error
int smf_message_set_header ( SMFMessage_T message,
const char *  header 
)

Set a header to message object. If header already exists, it will be overwritten.

Parameters
messagea SMFMessage_T object
headerfull header string
Returns
0 on success or -1 in case of error
void smf_message_set_message_id ( SMFMessage_T message,
const char *  message_id 
)

Set the Message-Id on a message.

Parameters
messageSMFMessage_T object
message_idthe message id
void smf_message_set_mime_version ( SMFMessage_T message,
const char *  s 
)

Set Mime-Version header value. According to RFC 2045, Mime-Version header is required at the top level of a message. Not required for each body part of a multipart entity. It's required for the embedded headers of a body of type "message/rfc822" or "message/partial" if the embedded message is itself claimed to be MIME.

Parameters
messagea SMFMessage_T object
sMime-Version header value
void smf_message_set_sender ( SMFMessage_T message,
const char *  sender 
)

Set the sender's name and address on the message object.

Parameters
messageSMFMessage_T object
senderThe name and address of the sender
void smf_message_set_subject ( SMFMessage_T message,
const char *  s 
)

Set message subject.

Parameters
messagea SMFMessage_T object
sthe subject string
int smf_message_to_fd ( SMFMessage_T message,
int  fd 
)

Write SMFMessage_T object into the file-descriptor.

Parameters
messagea SMFMessage_T object
fdthe file-descriptor, where the file should be written
Returns
the number of bytes written into the file-descriptor
int smf_message_to_file ( SMFMessage_T message,
const char *  filename 
)

Write SMFMessage_T object to file.

Parameters
messagea SMFMessage_T object
filenamepath to file, which should be written
Returns
the number of items successfully written on success, -1 in case of error
char* smf_message_to_string ( SMFMessage_T message)

Allocates a string buffer containing the contents of SMFMessage_T.

Parameters
messagea SMFMessage_T object
Returns
message as newly allocated string
int smf_message_update_header ( SMFMessage_T message,
const char *  header,
const char *  value 
)

Updates the header-value with the given key.

If the header-entry does not exist, it will be created

Parameters
messagea SMFMessage_T object
headerThe key of the header-entry to update resp. create
valueThe new value of the header-entry
Returns
0 on success or -1 in case of error
int smf_message_write_skip_header ( FILE *  src,
FILE *  dest 
)

Utility function to copy a message without the header The function reads a message from src but skips the header. When the body is reached, the content is written into dest.

Parameters
srcA readable FILE pointer to the source message
destA writable FILE pointer to the destination message
Returns
On success the number of bytes, which were written is returned. If an error occured, -1 is returned.