libEtPan! include a collection of datatypes such as lists, arrays, hash tables and tools such as buffered I/O.
#include <libetpan/libetpan.h> typedef struct carray_s carray;
carray is an array of pointers that will resize automatically in case a new element is added.
The carray is implemented with an array (void **) that can be resized. An array has a size: this is the number of elements that can be added before the table is resized. It also has a count of elements: this is the elements that exist in the array.
carray * carray_new(unsigned int initsize); void carray_free(carray * array);
carray_new() creates a new array with an initial size. The array is not resized until the number of element reach the initial size. It returns NULL in case of failure.
carray_free() releases memory used by the given array.
int carray_set_size(carray * array, uint32_t new_size);
carray_set_size() sets the size of the array. It returns 0 in case of success, -1 in case of failure.
Example 2-2. preallocating carray
#include <libetpan/libetpan.h> #include <stdlib.h> #define SIZE 50 #define NEWSIZE 200 int main(void) { carray * a; unsigned int i; char p[500]; a = carray_new(SIZE); if (a == NULL) goto err; r = carray_set_size(NEWSIZE); if (r < 0) goto free; for(i = 0 ; i < NEWSIZE ; i ++) carray_set(a, i, &p[i]); /* do things here */ carray_free(a); exit(EXIT_SUCESS); free: carray_free(a); err: exit(EXIT_FAILURE); }
int carray_count(carray); int carray_add(carray * array, void * data, unsigned int * index); void * carray_get(carray * array, unsigned int indx); void carray_set(carray * array, unsigned int indx, void * value);
carray_count() returns the number of elements in the carray. Complexity is O(1).
carray_add()adds an element at the end of the array. The index of the element is returns in (* index) if index is not NULL. It returns 0 in case of success, -1 in case of failure. Complexity is O(1).
carray_get() returns the elements contained at the given cell of the table. Complexity is O(1).
carray_set() replace the element at the given index of table table with the given value. Complexity is O(1).
Example 2-3. carray access
#include <libetpan/libetpan.h> #include <string.h> #define SIZE 50 int main(void) { carray * a; int r; a = carray_new(SIZE); if (a == NULL) goto err; r = carray_add(a, "foo-bar-1", NULL); if (r < 0) goto free; carray_add(a, "foo-bar-2", NULL); if (r < 0) goto free; carray_add(a, "foo-bar-3", NULL); if (r < 0) goto free; for(i = 0 ; i < carray_count(a) ; i ++) { char * str; str = carray_get(a, i); if (strcmp("foo-bar-2", str) == 0) carray_set(a, i, "foo-bar-2-replacement"); printf("%s\n", str); } carray_free(a); exit(EXIT_SUCESS); free: carray_free(a); err: exit(EXIT_FAILURE); }
int carray_delete(carray * array, uint32_t indx); int carray_delete_slow(carray * array, uint32_t indx); int carray_delete_fast(carray * array, uint32_t indx);
carray_delete() removes an element of the table. Order will not be garanteed. The returned result can be ignored. Complexity is O(1).
carray_delete_slow() removes an element of the table. Order will be garanteed. The returned result can be ignored. Complexity is O(n).
carray_delete_fast() the element will just be replaced with NULL. Order will be kept but the number of elements will remains the same. The returned result can be ignored. Complexity is O(1).
Example 2-4. deletion in carray
#include <libetpan/libetpan.h> #define SIZE 50 carray * build_array(void) { carray * a; a = carray_new(SIZE); if (a == NULL) goto err; r = carray_add(a, "foo-bar-1", NULL); if (r < 0) goto free; carray_add(a, "foo-bar-2", NULL); if (r < 0) goto free; carray_add(a, "foo-bar-3", NULL); if (r < 0) goto free; return a; free: carray_free(a); err: exit(EXIT_FAILURE); } void delete(carray * a) { /* deleting foo-bar-1 */ carray_delete(a, 0); /* resulting size is 2, order of elements is undefined */ } void delete_slow(carray * a) { /* deleting foo-bar-1 */ carray_delete_slow(a, 0); /* resulting size is 2, order of elements is the same */ } void delete_fast(carray * a) { /* deleting foo-bar-1 */ carray_delete_slow(a, 0); /* resulting size is 3, order of elements is { NULL, foo-bar-2, foo-bar-3 } */ }
void ** carray_data(carray);
carray_datareturns the table used for implementation : (void **).
#include <libetpan/libetpan.h> typedef struct clist_s clist; typedef clistcell clistiter;
clist() is a list of cells. Each cell of the list contains one element. This element is a pointer. An iterator (clistiter) is a pointer to an element of the list. With an iterator, we can get the previous element of the list, the next element of the list and the content of the element.
clist * clist_new(void); void clist_free(clist *);
clist_new() allocates a new empty list and returns it.
clist_free() frees the entire list with its cells.
int clist_isempty(clist *); int clist_count(clist *);
clist_isempty() returns 1 if the list is empty, else it is 0. Complexity is O(1).
clist_count() returns the number of elements in the list. Complexity is O(1).
clistiter * clist_begin(clist *); clistiter * clist_end(clist *); clistiter * clist_next(clistiter *); clistiter * clist_previous(clistiter *); void * clist_content(clistiter *); void * clist_nth_data(clist * lst, int index); clistiter * clist_nth(clist * lst, int index);
clist_begin() returns an iterator to the first element of the list. Complexity is O(1).
clist_end() returns an iterator to the last element of the list. Complexity is O(1).
clist_next() returns an iterator to the next element of the list. Complexity is O(1).
clist_previous() returns an iterator to the previous element of the list. Complexity is O(1).
clist_content() returns the element contained in the cell pointed by the iterator in the list. Complexity is O(1).
clist_nth() returns an iterator on the index-th element of the list. Complexity is O(n).
clist_nth_data() returns the index-th element of the list. Complexity is O(n).
Example 2-6. displaying content of clist
#include <libetpan/libetpan.h> int main(void) { clist * list; clistiter * iter; list = build_string_list(); if (list == NULL) goto err; for(iter = clist_begin(list) ; iter != NULL ; iter = clist_next(iter)) { char * str; str = clist_content(iter); printf("%s\n", str); } clist_free(list); exit(EXIT_SUCCESS); free: clist_free(list); err: exit(EXIT_FAILURE); }
int clist_prepend(clist *, void *); int clist_append(clist *, void *); int clist_insert_before(clist *, clistiter *, void *); int clist_insert_after(clist *, clistiter *, void *); clistiter * clist_delete(clist *, clistiter *);
clist_prepend() adds an element at the beginning of the list. Returns 0 on sucess, -1 on error. Complexity is O(1).
clist_append() adds an element at the end of the list. Returns 0 on sucess, -1 on error. Complexity is O(1).
clist_insert_before() adds an element before the element pointed by the given iterator in the list. Returns 0 on sucess, -1 on error. Complexity is O(1).
clist_insert_after() adds an element after the element pointed by the given iterator in the list. Returns 0 on sucess, -1 on error. Complexity is O(1).
clist_delete() the elements pointed by the given iterator in the list and returns an iterator to the next element of the list. Complexity is O(1).
Example 2-7. deleting elements in a clist
#include <libetpan/libetpan.h> voir print_content(void * content, void * user_data) { char * str; str = content; printf("%s\n", str); } int main(void) { clist * list; clistiter * iter; list = build_string_list(); if (list == NULL) goto err; iter = = clist_begin(list); while (iter != NULL) char * str; str = clist_content(iter); if (strcmp(str, "foo-bar") == 0) iter = clist_delete(list, cur); else iter = clist_next(iter); } clist_foreach(list, print_content, NULL); printf("\n"); clist_free(list); exit(EXIT_SUCCESS); free: clist_free(list); err: exit(EXIT_FAILURE); }
typedef void (* clist_func)(void *, void *); void clist_foreach(clist * lst, clist_func func, void * data);
clist_foreach() apply a fonction to each element of the list. Complexity is O(n).
void clist_concat(clist * dest, clist * src);
clist_concat() adds all the elements of src at the end of dest. Elements are added in the same order. src is an empty list when the operation is finished. Complexity is O(1).
Example 2-8. merging two clists
#include <libetpan/libetpan.h> int main(void) { clist * list; clist * list_2; clistiter * iter; list = build_string_list(); if (list == NULL) goto err; list_2 = build_string_list_2(); if (list == NULL) goto free_list; clist_concat(list, list_2); clist_free(list_2); for(iter = clist_begin(list) ; iter != NULL ; iter = clist_next(iter)) { char * str; str = clist_content(iter); printf("%s\n", str); } clist_free(list); exit(EXIT_SUCCESS); free_list: clist_free(list); err: exit(EXIT_FAILURE); }
#include <libetpan/libetpan.h> typedef struct chash chash; typedef struct chashcell chashiter; typedef struct { char * data; int len; } chashdatum;
chash is a hash table. chashiter is a pointer to an element of the hash table. chashdatum is an element to be placed in the hash table as a key or a value. It consists in data and a corresponding length.
#define CHASH_COPYNONE 0 #define CHASH_COPYKEY 1 #define CHASH_COPYVALUE 2 #define CHASH_COPYALL (CHASH_COPYKEY | CHASH_COPYVALUE) chash * chash_new(int size, int flags); void chash_free(chash * hash);
chash_new() returns a new empty hash table or NULL if this failed. size is the initial size of the table used for implementation. flags can be a combinaison of CHASH_COPYKEY and CHASH_COPYVALUE. CHASH_COPYKEY enables copy of key, so that the initial value used for chash_set()
chash_free() releases memory used by the hash table.
int chash_set(chash * hash, chashdatum * key, chashdatum * value, chashdatum * oldvalue); int chash_get(chash * hash, chashdatum * key, chashdatum * result);
chash_set() adds a new element into the hash table. If a previous element had the same key, it is returns into oldvalue if oldvalue is different of NULL. Medium complexity is O(1).
returns -1 if it fails, 0 on success.
chash_get()returns the corresponding value of the given key. If there is no corresponding value, -1 is returned. 0 on success. Medium complexity is O(1).
Example 2-9. chash insert and lookup
int main(void) { chash * hash; int r; chashdatum key; chashdatum value; char * str1 = "my-data"; char * str2 = "my-data"; hash = chash_new(CHASH_DEFAULTSIZE, CHASH_COPYNONE); key.data = "foo"; key.len = strlen("foo"); value.data = str1; value.data = strlen(str1) + 1; /* + 1 is needed to get the terminal zero in the returned string */ r = chash_set(hash, &key, &value, NULL); if (r < 0) goto free_hash; key.data = "bar"; key.len = strlen("bar"); value.data = str2; value.data = strlen(str2) + 1; if (r < 0) goto free_hash; key.data = "foo"; key.len = strlen("foo"); r = chash_get(hash, &key, &value); if (r < 0) { printf("element not found\n"); } else { char * str; str = value.data; printf("found : %s", str); } chash_free(hash); exit(EXIT_SUCCESS); free_hash: chash_free(hash); err: exit(EXIT_FAILURE); }
int chash_delete(chash * hash, chashdatum * key, chashdatum * oldvalue);
deletes the key/value pair given the corresponding key. The value is returned in old_value. If there is no corresponding value, -1 is returned. 0 on success. Medium complexity is O(1).
Example 2-10. key deletion in a chash
int main(void) { chash * hash; int r; chashdatum key; chashdatum value; char * str1 = "my-data"; char * str2 = "my-data"; hash = build_hash(); key.data = "foo"; key.len = strlen("foo"); chash_delete(hash, &key, &value); /* it will never be possible to lookup "foo" */ key.data = "foo"; key.len = strlen("foo"); r = chash_get(hash, &key, &value); if (r < 0) { printf("element not found\n"); } else { char * str; str = value.data; printf("found : %s", str); } chash_free(hash); exit(EXIT_SUCCESS); free_hash: chash_free(hash); err: exit(EXIT_FAILURE); }
int chash_resize(chash * hash, int size);
chash_resize() changes the size of the table used for implementation of the hash table. returns 0 on success, -1 on failure.
chashiter * chash_begin(chash * hash); chashiter * chash_next(chash * hash, chashiter * iter); void chash_key(chashiter * iter, chashdatum * result); void chash_value(chashiter iter, chashdatum * result);
chash_begin() returns a pointer to the first element of the hash table. Returns NULL if there is no elements in the hash table. Complexity is O(n).
chash_next() returns a pointer to the next element of the hash table. Returns NULL if there is no next element. Complexity is O(n) but n calls to chash_next() also has a complexity of O(n).
chash_key() returns the key of the given element of the hash table.
chash_value returns the value of the given element of the hash table.
Example 2-11. running through a chash
int main(void) { chash * hash; int r; chashiter * iter; hash = build_hash(); /* this will display all the values stored in the hash */ for(iter = chash_begin(hash) ; iter != NULL ; iter = chash_next(hash, iter)) { chashdatum key; chashdatum value; char * str; chash_value(iter, &value); str = value.data; printf("%s\n", str); } chash_free(hash); }
int chash_size(chash * hash); int chash_count(chash * hash);
chash_size() returns the size of the table used for implementation of the hash table. Complexity is O(1).
chash_count() returns the number of elements in the hash table. Complexity is O(1).
#include <libetpan/libetpan.h> typedef struct _mailstream mailstream;
streams are objects where we can read data from and write data to. They are not seekable. That can be for example a pipe or a network stream.
mailstream * mailstream_new(mailstream_low * low, size_t buffer_size); int mailstream_close(mailstream * s);
mailstream_new() creates a new stream stream with the low-level (see the Section called non-buffered I/O) stream and a given buffer size.
mailstream_close() closes the stream. This function will be in charge to free the mailstream_low structure.
ssize_t mailstream_write(mailstream * s, void * buf, size_t count); int mailstream_flush(mailstream * s); ssize_t mailstream_read(mailstream * s, void * buf, size_t count); ssize_t mailstream_feed_read_buffer(mailstream * s);
mailstream_write() writes a buffer to the given stream. This write operation will be buffered.
mailstream_flush() will force a write of all buffered data for a given stream.
mailstream_read() reads data from the stream to the given buffer.
mailstream_feed_read_buffer() this function will just fill the buffer for reading.
mailstream_low * mailstream_get_low(mailstream * s); void mailstream_set_low(mailstream * s, mailstream_low * low);
mailstream_get_low() returns the low-level stream of the given stream.
mailstream_set_low() changes the low-level of the given stream. Useful, for example, when a stream change from clear stream to SSL stream.
char * mailstream_read_line(mailstream * stream, MMAPString * line); char * mailstream_read_line_append(mailstream * stream, MMAPString * line); char * mailstream_read_line_remove_eol(mailstream * stream, MMAPString * line); char * mailstream_read_multiline(mailstream * s, size_t size, MMAPString * stream_buffer, MMAPString * multiline_buffer, size_t progr_rate, progress_function * progr_fun);
mailstream_read_line() reads an entire line from the buffer and store it into the given string. returns NULL on error, the corresponding array of char is returned otherwise.
mailstream_read_line_append() reads an entire line from the buffer and appends it to the given string. returns NULL on error, the array of char corresponding to the entire buffer is returned otherwise.
mailstream_read_line_remove_eol() reads an entire line from the buffer and store it into the given string. All CR LF are removed. returns NULL on error, the corresponding array of char is returned otherwise.
mailstream_read_multiline() reads a multiline data (several lines, the data are ended with a single period '.') from the given stream and store it into the given multiline buffer (multiline_buffer). progr_rate should be 0 and progr_fun NULL (deprecated things). stream_buffer is a buffer used for internal work of the function. size should be 0 (deprecated things).
int mailstream_is_end_multiline(char * line);
returns 1 if the line is an end of multiline data (a single period '.', eventually with CR and/or LF). 0 is returned otherwise.
int mailstream_send_data(mailstream * s, char * message, size_t size, size_t progr_rate, progress_function * progr_fun);
sends multiline data to the given stream. size is the size of the data. progr_rate and progr_fun are deprecated. progr_rate must be 0, progr_fun must be NULL.
mailstream * mailstream_socket_open(int fd);
mailstream_socket_open() will open a clear-text socket.
mailstream * mailstream_ssl_open(int fd);
mailstream_ssl_open() will open a TLS/SSL socket.
#include <libetpan/libetpan.h> struct mailstream_low_driver { ssize_t (* mailstream_read)(mailstream_low *, void *, size_t); ssize_t (* mailstream_write)(mailstream_low *, void *, size_t); int (* mailstream_close)(mailstream_low *); int (* mailstream_get_fd)(mailstream_low *); void (* mailstream_free)(mailstream_low *); }; typedef struct mailstream_low_driver mailstream_low_driver; struct _mailstream_low { void * data; mailstream_low_driver * driver; };
mailstream_low is a non-buffered stream.
The mailstream_low_driver is a set of functions used to access the stream.
mailstream_read/write/close() is the same interface as read/write/close() system calls, except that the file descriptor is replaced with the mailstream_low structure.
mailstream_get_fd() returns the file descriptor used for this non-buffered stream.
mailstream_free() is in charge to free the internal structure of the mailstream_low and the mailstream_low itself.
mailstream_low * mailstream_low_new(void * data, mailstream_low_driver * driver);
mailstream_low_new() creates a low-level mailstream with the given internal structure (data) and using the given set of functions (driver).
ssize_t mailstream_low_write(mailstream_low * s, void * buf, size_t count); ssize_t mailstream_low_read(mailstream_low * s, void * buf, size_t count); int mailstream_low_close(mailstream_low * s); int mailstream_low_get_fd(mailstream_low * s); void mailstream_low_free(mailstream_low * s);
Each of these calls will call the corresponding function defined in the driver.
#include <libetpan/libetpan.h> struct _MMAPString { char * str; size_t len; size_t allocated_len; int fd; size_t mmapped_size; }; typedef struct _MMAPString MMAPString;
MMAPString is a string which size that can increase automatically.
MMAPString * mmap_string_new(const char * init); MMAPString * mmap_string_new_len(const char * init, size_t len); MMAPString * mmap_string_sized_new(size_t dfl_size); void mmap_string_free(MMAPString * string);
mmap_string_new() allocates a new string. init is the intial value of the string. NULL will be returned on error.
mmap_string_new_len() allocates a new string. init is the intial value of the string, len is the length of the initial string. NULL will be returned on error.
mmap_string_sized_new() allocates a new string. dfl_size is the initial allocation of the string. NULL will be returned on error.
mmap_string_free() release the memory used by the string.
MMAPString * mmap_string_assign(MMAPString * string, const char * rval); MMAPString * mmap_string_truncate(MMAPString *string, size_t len);
mmap_string_assign() sets a new value for the given string. NULL will be returned on error.
mmap_string_truncate() sets a length for the string. NULL will be returned on error.
MMAPString * mmap_string_set_size (MMAPString * string, size_t len);
sets the allocation of the string. NULL will be returned on error.
MMAPString * mmap_string_insert_len(MMAPString * string, size_t pos, const char * val, size_t len); MMAPString * mmap_string_append(MMAPString * string, const char * val); MMAPString * mmap_string_append_len(MMAPString * string, const char * val, size_t len); MMAPString * mmap_string_append_c(MMAPString * string, char c); MMAPString * mmap_string_prepend(MMAPString * string, const char * val); MMAPString * mmap_string_prepend_c(MMAPString * string, char c); MMAPString * mmap_string_prepend_len(MMAPString * string, const char * val, size_t len); MMAPString * mmap_string_insert(MMAPString * string, size_t pos, const char * val); MMAPString * mmap_string_insert_c(MMAPString *string, size_t pos, char c); MMAPString * mmap_string_erase(MMAPString * string, size_t pos, size_t len);
For complexity here, n is the size of the given MMAPString, and len is the size of the string to insert.
mmap_string_insert_len() inserts the given string value of given length in the string at the given position. NULL will be returned on error. Complexity is O(n + len).
mmap_string_append() appends the given string value at the end of the string. NULL will be returned on error. Complexity is O(len).
mmap_string_append_len() appends the given string value of given length at the end of the string. NULL will be returned on error. Complexity is O(len).
mmap_string_append_c() appends the given character at the end of the string. NULL will be returned on error. Complexity is O(1).
mmap_string_prepend() insert the given string value at the beginning of the string. NULL will be returned on error. Complexity is O(n + len).
mmap_string_prepend_c() insert the given character at the beginning of the string. NULL will be returned on error. Complexity is O(n).
mmap_string_prepend_len() insert the given string value of given length at the beginning of the string. NULL will be returned on error. Complexity is O(n + len).
mmap_string_insert() inserts the given string value in the string at the given position. NULL will be returned on error. Complexity is O(n + len).
mmap_string_insert_c() inserts the given character in the string at the given position. NULL will be returned on error. Complexity is O(n).
mmap_string_erase() removes the given count of characters (len) at the given position of the string. NULL will be returned on error. Complexity is O(n).
int mmap_string_ref(MMAPString * string); int mmap_string_unref(char * str);
MMAPString provides a mechanism that let you use MMAPString like normal strings. You have first to use mmap_string_ref(), so that you notify that the string will be used as a normal string, then, you use mmapstr->str to refer to the string. When you have finished and you want to free a string corresponding to a MMAPString, you will use mmap_string_unref.
mmap_string_ref() references the string so that the array of characters can be used as a normal string then released with mmap_string_unref(). The array of characters will be obtained with string->str. returns -1 on error, 0 on success.
libEtPan! implements Internet Message parser. Currently, format is RFC 2822. This module also allows to generate messages.
| Warning |
All allocation functions will take as argument allocated data and will store these data in the structure they will allocate. Data should be persistant during all the use of the structure and will be freed by the free function of the structure allocation functions will return NULL on failure functions returning integer will be returning one of the following error code: MAILIMF_NO_ERROR, MAILIMF_ERROR_PARSE, MAILIMF_ERROR_MEMORY, MAILIMF_ERROR_INVAL, or MAILIMF_ERROR_FILE. |
You will need this module when you want to parse headers of messages or when you want to build message headers conformant to standards.
You will use one of the four following functions, depending on your needs :
mailimf_envelope_and_optional_fields_parse (the Section called mailimf_envelope_and_optional_fields_parse),
mailimf_envelope_fields_parse (the Section called mailimf_envelope_fields_parse),
mailimf_optional_fields_parse (the Section called mailimf_optional_fields_parse),
mailimf_fields_parse (the Section called mailimf_fields_parse).
Build your message headers, then use mailimf_fields_write (the Section called Header fields) to render the headers.
#include <libetpan/libetpan.h> struct mailimf_mailbox { char * mb_display_name; /* can be NULL */ char * mb_addr_spec; /* != NULL */ }; struct mailimf_mailbox * mailimf_mailbox_new(char * mb_display_name, char * mb_addr_spec); void mailimf_mailbox_free(struct mailimf_mailbox * mailbox);
This is an email mailbox with a display name.
mailimf_mailbox_new creates and initializes a data structure with a value. Strings given as argument are referenced by the created object and will be freed if the object is released.
mailimf_mailbox_free frees memory used by the structure and substructures will also be released.
Example 3-2. mailbox creation and display
#include <libetpan/libetpan.h> int main(int argc, char ** argv) { struct mailimf_mailbox * mb; char * display_name; char * address; display_name = strdup("DINH =?iso-8859-1?Q?Vi=EAt_Ho=E0?="); address = strdup("dinh.viet.hoa@free.fr"); mb = mailimf_mailbox_new(str, address); /* do the things */ mailimf_mailbox_free(mb); return 0; } /* display mailbox information */ #include <libetpan/libetpan.h> #include <stdio.h> void display_mailbox(struct mailimf_mailbox * mb) { if (mb->mb_display_name != NULL) printf("display name: %s\n", mb->mb_display_name); printf("address specifier : %s\n", mb->mb_addr_spec); }
#include <libetpan/libetpan.h> struct mailimf_address { int ad_type; union { struct mailimf_mailbox * ad_mailbox; /* can be NULL */ struct mailimf_group * ad_group; /* can be NULL */ } ad_data; }; struct mailimf_address * mailimf_address_new(int ad_type, struct mailimf_mailbox * ad_mailbox, struct mailimf_group * ad_group); void mailimf_address_free(struct mailimf_address * address);
This is a mailbox or a group of mailbox.
ad_type can be MAILIMF_ADDRESS_MAILBOX or MAILIMF_ADDRESS_GROUP.
ad_data.ad_mailbox is a mailbox if ad_type is MAILIMF_ADDRESS_MAILBOX see the Section called mailimf_mailbox - mailbox)
ad_data.group is a group if type is MAILIMF_ADDRESS_GROUP. see the Section called mailimf_group - named group of mailboxes)
mailimf_address_new() creates and initializes a data structure with a value. Structures given as argument are referenced by the created object and will be freed if the object is released.
mailimf_address_free frees memory used by the structure and substructures will also be released.
Example 3-3. address creation and display
/* creates an address of type mailbox */ #include <libetpan/libetpan.h> int main(int argc, char ** argv) { struct mailimf_address * a_mb; struct mailimf_mailbox * mb; char * display_name; char * address; display_name = strdup("DINH =?iso-8859-1?Q?Vi=EAt_Ho=E0?="); address = strdup("dinh.viet.hoa@free.fr"); mb = mailimf_mailbox_new(str, address); a_mb = mailimf_address_new(MAILIMF_ADDRESS_MAILBOX, mb, NULL); /* do the things */ mailimf_address_free(a_mb); } /* creates an address of type group */ #include <libetpan/libetpan.h> int main(int argc, char ** argv) { struct mailimf_address * a_g; struct mailimf_group * g; char * display_name; display_name = strdup("undisclosed-recipient"); g = mailimf_group_new(display_name, NULL); a_g = mailimf_address_new(MAILIMF_ADDRESS_GROUP, NULL, g); /* do the things */ mailimf_address_free(a_g); return 0; } /* display the content of an address */ #include <libetpan/libetpan.h> void display_address(struct mailimf_address * a) { clistiter * cur; switch (a->ad_type) { case MAILIMF_ADDRESS_GROUP: display_mailimf_group(a->ad_data.ad_group); break; case MAILIMF_ADDRESS_MAILBOX: display_mailimf_mailbox(a->ad_data.ad_mailbox); break; } }
#include <libetpan/libetpan.h> struct mailimf_mailbox_list { clist * mb_list; /* list of (struct mailimf_mailbox *), != NULL */ }; struct mailimf_mailbox_list * mailimf_mailbox_list_new(clist * mb_list); void mailimf_mailbox_list_free(struct mailimf_mailbox_list * mb_list);
This is a list of mailboxes.
mb_list is a list of mailboxes. This is a clist which elements are of type mailimf_mailbox (see the Section called mailimf_mailbox - mailbox).
mailimf_mailbox_list_new() creates and initializes a data structure with a value. Structures given as argument are referenced by the created object and will be freed if the object is released.
mailimf_mailbox_list_free() frees memory used by the structure and substructures will also be released.
Example 3-4. Creation and display of mailimf_mailbox_list
/* creates a list of mailboxes with two mailboxes */ #include <libetpan/libetpan.h> int main(int argc, char ** argv) { struct mailimf_group * g; char * display_name; struct mailimf_mailbox_list * mb_list; clist * list; list = clist_new(); mb = mailimf_mailbox_new(strdup("DINH =?iso-8859-1?Q?Vi=EAt_Ho=E0?="), strdup("dinh.viet.hoa@free.fr")); list = clist_append(mb); mb = mailimf_mailbox_new(strdup("Christophe GIAUME"), strdup("christophe@giaume.com")); list = clist_append(mb); mb_list = mailimf_mailbox_list_new(list); /* do the things */ mailimf_mailbox_list_free(mb_list); return 0; } /* display a list of mailboxes */ #include <libetpan/libetpan.h> #include <stdio.h> void display_mailbox_list(struct mailimf_mailbox_list * mb_list) { clistiter * cur; for(cur = clist_begin(mb_list->mb_list) ; cur != NULL ; cur = clist_next(cur)) { struct mailimf_mailbox * mb; mb = clist_content(cur); display_mailbox(mb); printf("\n"); } }
#include <libetpan/libetpan.h> struct mailimf_address_list { clist * ad_list; /* list of (struct mailimf_address *), != NULL */ }; struct mailimf_address_list * mailimf_address_list_new(clist * ad_list); void mailimf_address_list_free(struct mailimf_address_list * addr_list);
This is a list of addresses.
ad_list is a list of addresses. This is a clist which elements are of type mailimf_address (see the Section called mailimf_address - address).
mailimf_address_list_new() creates and initializes a data structure with a value. Structures given as argument are referenced by the created object and will be freed if the object is released.
mailimf_address_list_free() frees memory used by the structure and substructures will also be released.
Example 3-5. creation and display of list of addresses
/* creates a list of addresses with two addresses */ #include <libetpan/libetpan.h> int main(int argc, char ** argv) { struct mailimf_address_list * addr_list; clist * list; struct mailimf_mailbox * mb; struct mailimf_address * addr; list = clist_new(); mb = mailimf_mailbox_new(strdup("DINH =?iso-8859-1?Q?Vi=EAt_Ho=E0?="), strdup("dinh.viet.hoa@free.fr")); addr = mailimf_address_new(MAILIMF_ADDRESS_MAILBOX, mb, NULL); list = clist_append(addr); mb = mailimf_mailbox_new(strdup("Christophe GIAUME"), strdup("christophe@giaume.com")); addr = mailimf_address_new(MAILIMF_ADDRESS_MAILBOX, mb, NULL); list = clist_append(addr); addr_list = mailimf_address_list_new(list); /* do the things */ mailimf_address_list_free(mb_list); return 0; } /* display a list of addresses */ #include <libetpan/libetpan.h> #include <stdio.h> void display_address_list(struct mailimf_address_list * addr_list) { clistiter * cur; for(cur = clist_begin(addr_list->ad_list) ; cur != NULL ; cur = clist_next(cur)) { struct mailimf_address * addr; addr = clist_content(cur); display_address(addr); printf("\n"); } }
#include <libetpan/libetpan.h> struct mailimf_group { char * grp_display_name; /* != NULL */ struct mailimf_mailbox_list * grp_mb_list; /* can be NULL */ }; struct mailimf_group * mailimf_group_new(char * grp_display_name, struct mailimf_mailbox_list * grp_mb_list); void mailimf_group_free(struct mailimf_group * group);
This is a list of mailboxes tagged with a name.
Example 3-6. example of group
they play music<EMAIL_ADDRESS><EMAIL_ADDRESS><EMAIL_ADDRESS><EMAIL_ADDRESS>grp_display_name is the name that will be displayed for this group, for example 'group_name' in 'group_name: address1@domain1, address2@domain2;'. This must be allocated with malloc(). grp_mb_list is a list of mailboxes (see the Section called mailimf_mailbox_list - list of mailboxes).
mailimf_group_new() creates and initializes a data structure with a value. Structures given as argument are referenced by the created object and will be freed if the object is released.
mailimf_group_free() frees memory used by the structure and substructures will also be released.
Example 3-7. creation and display of a group
/* creates an empty group */ #include <libetpan/libetpan.h> int main(int argc, char ** argv) { struct mailimf_group * g; char * display_name; display_name = strdup("undisclosed-recipient"); g = mailimf_group_new(display_name, NULL); /* do the things */ mailimf_group_free(g); } /* creates a group with two mailboxes */ #include <libetpan/libetpan.h> int main(int argc, char ** argv) { struct mailimf_group * g; char * display_name; struct mailimf_mailbox_list * mb_list; struct mailimf_mailbox * mb; clist * list; list = clist_new(); mb = mailimf_mailbox_new(strdup("DINH =?iso-8859-1?Q?Vi=EAt_Ho=E0?="), strdup("dinh.viet.hoa@free.fr")); list = clist_append(mb); mb = mailimf_mailbox_new(strdup("Christophe GIAUME"), strdup("christophe@giaume.com")); list = clist_append(mb); mb_list = mailimf_mailbox_list_new(list); display_name = strdup("my_group"); g = mailimf_group_new(display_name, mb_list); /* do the things */ mailimf_group_free(g); return 0; } /* display content of group */ #include <libetpan/libetpan.h> #include <stdio.h> void display_group(struct mailimf_group * group) { printf("name of the group: %s\n", a->group->display_name); for(cur = clist_begin(a->group->mb_list->list) ; cur != NULL ; cur = clist_next(cur)) { struct mailimf_mailbox * mb; mb = clist_content(cur); display_mailbox(mb); printf("\n"); } }
#include <libetpan/libetpan.h> struct mailimf_date_time { int dt_day; int dt_month; int dt_year; int dt_hour; int dt_min; int dt_sec; int dt_zone; }; struct mailimf_date_time * mailimf_date_time_new(int dt_day, int dt_month, int dt_year, int dt_hour, int dt_min, int dt_sec, int dt_zone); void mailimf_date_time_free(struct mailimf_date_time * date_time);
This is the date and time of a message. For example :
dt_day is the day of month (1 to 31)
dt_month (1 to 12)
dt_year (4 digits)
dt_hour (0 to 23)
dt_min (0 to 59)
dt_sec (0 to 59)
dt_zone (this is the decimal value that we can read, for example: for '-0200', the value is -200).
mailimf_date_time_new() creates and initializes a date structure with a value.
mailimf_date_time_free() frees memory used by the structure.
Example 3-9. creation and display of date
#include <libetpan/libetpan.h> int main(int argc, char ** argv) { struct mailimf_date_time * d; d = mailimf_date_time_new(9, 5, 2003, 3, 01, 40, -0200); /* do the things */ mailimf_date_time_free(d); return 0; } /* display the date */ #include <libetpan/libetpan.h> #include <stdio.h> void display_date(struct mailimf_date_time * d) { printf("%02i/%02i/%i %02i:%02i:%02i %+04i\n", d->dt_day, d->dt_month, d->dt_year, d->dt_hour, d->dt_min, d->dt_sec, d->dt_zone); }
#include <libetpan/libetpan.h> struct mailimf_orig_date { struct mailimf_date_time * dt_date_time; /* != NULL */ }; struct mailimf_orig_date * mailimf_orig_date_new(struct mailimf_date_time * dt_date_time); void mailimf_orig_date_free(struct mailimf_orig_date * orig_date);
This is the content of a header Date or Resent-Date. It encapsulates a mailimf_date_time
dt_date_time is the parsed date (see the Section called mailimf_date_time - date of a message).
mailimf_orig_date_new() creates and initializes a data structure with a value. Structures given as argument are referenced by the created object and will be freed if the object is released.
mailimf_orig_date_free() frees memory used by the structure and substructures will also be released.
Example 3-10. creation and display of Date field
#include <libetpan/libetpan.h> int main(int argc, char ** argv) { struct mailimf_date_time * d; struct mailimf_orig_date * date; d = mailimf_date_time_new(9, 5, 2003, 3, 01, 40, -0200); date = mailimf_orig_date_new(d); /* do the things */ mailimf_orig_date_free(date); return 0; } /* display date header */ #include <libetpan/libetpan.h> void display_orig_date(struct mailimf_orig_date * orig_date) { display_date_time(d->dt_date_time); }
#include <libetpan/libetpan.h> struct mailimf_from { struct mailimf_mailbox_list * frm_mb_list; /* != NULL */ }; struct mailimf_from * mailimf_from_new(struct mailimf_mailbox_list * frm_mb_list); void mailimf_from_free(struct mailimf_from * from);
This is the content of a header From or Resent-From.
frm_mb_list is the parsed mailbox list (see the Section called mailimf_mailbox_list - list of mailboxes).
mailimf_from_new() creates and initializes a data structure with a value. Structures given as argument are referenced by the created object and will be freed if the object is released.
mailimf_from_free() frees memory used by the structure and substructures will also be released.
Example 3-11. creation and display of a From header
#include <libetpan/libetpan.h> int main(int argc, char ** argv) { clist * list; struct mailimf_mailbox * mb; struct mailimf_mailbox_list * mb_list; struct mailimf_from * from; list = clist_new(); mb = mailimf_mailbox_new(strdup("DINH =?iso-8859-1?Q?Vi=EAt_Ho=E0?="), strdup("dinh.viet.hoa@free.fr")); clist_append(list, mb); mb_list = mailimf_mailbox_list_new(list); from = mailimf_from_new(mb_list); /* do the things */ mailimf_from_free(from); return 0; } /* display content of from header */ #include <libetpan/libetpan.h> void display_from(struct mailimf_from * from) { display_mailbox_list(from->frm_mb_list); }
#include <libetpan/libetpan.h> struct mailimf_sender { struct mailimf_mailbox * snd_mb; /* != NULL */ }; struct mailimf_sender * mailimf_sender_new(struct mailimf_mailbox * snd_mb); void mailimf_sender_free(struct mailimf_sender * sender);
This is the content of a header Sender or Resent-Sender.
snd_mb is the parsed mailbox (see the Section called mailimf_mailbox - mailbox).
mailimf_sender_new() creates and initializes a data structure with a value. Structures given as argument are referenced by the created object and will be freed if the object is released.
mailimf_sender_free() This function frees memory used by the structure and substructures will also be released.
Example 3-12. creation and display of Sender field
#include <libetpan/libetpan.h> int main(int argc, char ** argv) { struct mailimf_mailbox * mb; struct mailimf_sender * sender; mb = mailimf_mailbox_new(strdup("DINH =?iso-8859-1?Q?Vi=EAt_Ho=E0?="), strdup("dinh.viet.hoa@free.fr")); sender = mailimf_sender_new(mb); /* do the things */ mailimf_sender_free(sender); return 0; } #include <libetpan/libetpan.h> #include <stdio.h> void display_sender(struct mailimf_sender * sender) { display_mailbox(sender->snd_mb); }
#include <libetpan/libetpan.h> struct mailimf_reply_to { struct mailimf_address_list * rt_addr_list; /* != NULL */ }; struct mailimf_reply_to * mailimf_reply_to_new(struct mailimf_address_list * rt_addr_list); void mailimf_reply_to_free(struct mailimf_reply_to * reply_to);
This is the content of a header Reply-To.
addr_list is the parsed address list (see the Section called mailimf_address_list - list of addresses).
mailimf_reply_to_new() creates and initializes a data structure with a value. Structures given as argument are referenced by the created object and will be freed if the object is released.
mailimf_reply_to_free() frees memory used by the structure and substructures will also be released.
Example 3-13. creation and display of Reply-To field
#include <libetpan/libetpan.h> int main(int argc, char ** argv) { clist * list; struct mailimf_mailbox * mb; struct mailimf_address * addr; struct mailimf_address_list * addr_list; struct mailimf_reply_to * reply_to; list = clist_new(); mb = mailimf_mailbox_new(strdup("DINH =?iso-8859-1?Q?Vi=EAt_Ho=E0?="), strdup("dinh.viet.hoa@free.fr")); addr = mailimf_address_new(MAILIMF_ADDRESS_MAILBOX, mb, NULL); clist_append(list, addr); mb = mailimf_mailbox_new(strdup("Christophe GIAUME"), strdup("christophe@giaume.com")); addr = mailimf_address_new(MAILIMF_ADDRESS_MAILBOX, mb, NULL); clist_append(list, addr); addr_list = mailimf_address_list_new(list); reply_to = mailimf_reply_to_new(addr_list); /* do the things */ mailimf_reply_to_free(reply_to); return 0; } /* display Reply-To header */ #include <libetpan/libetpan.h> void display_reply_to(struct mailimf_reply_to * reply_to) { display_address_list(reply_to->addr_list); }
struct mailimf_to { struct mailimf_address_list * to_addr_list; /* != NULL */ }; struct mailimf_to * mailimf_to_new(struct mailimf_address_list * to_addr_list); void mailimf_to_free(struct mailimf_to * to);
This is the content of a header To or Resent-To.
to_addr_list is the parsed address list (see the Section called mailimf_address_list - list of addresses).
mailimf_to_new() creates and initializes a data structure with a value. Structures given as argument are referenced by the created object and will be freed if the object is released.
mailimf_to_free() frees memory used by the structure and substructures will also be released.
Example 3-14. creation and display of To field
#include <libetpan/libetpan.h> int main(int argc, char ** argv) { clist * list; struct mailimf_mailbox * mb; struct mailimf_address * addr; struct mailimf_address_list * addr_list; struct mailimf_to * to; list = clist_new(); mb = mailimf_mailbox_new(strdup("DINH =?iso-8859-1?Q?Vi=EAt_Ho=E0?="), strdup("dinh.viet.hoa@free.fr")); addr = mailimf_address_new(MAILIMF_ADDRESS_MAILBOX, mb, NULL); clist_append(list, addr); mb = mailimf_mailbox_new(strdup("Christophe GIAUME"), strdup("christophe@giaume.com")); addr = mailimf_address_new(MAILIMF_ADDRESS_MAILBOX, mb, NULL); clist_append(list, addr); addr_list = mailimf_address_list_new(list); to = mailimf_to_new(addr_list); /* do the things */ mailimf_to_free(to); return 0; } /* display To header */ #include <libetpan/libetpan.h> void display_to(struct mailimf_to * to) { display_address_list(to->to_addr_list); }
#include <libetpan/libetpan.h> struct mailimf_cc { struct mailimf_address_list * cc_addr_list; /* != NULL */ }; struct mailimf_cc * mailimf_cc_new(struct mailimf_address_list * cc_addr_list); void mailimf_cc_free(struct mailimf_cc * cc);
This is the content of a header Cc or Resent-Cc.
cc_addr_list is the parsed address list (see the Section called mailimf_address_list - list of addresses).
mailimf_cc_new() creates and initializes a data structure with a value. Structures given as argument are referenced by the created object and will be freed if the object is released.
mailimf_cc_free() This function frees memory used by the structure and substructures will also be released.
Example 3-15. creation and display of Cc field
#include <libetpan/libetpan.h> int main(int argc, char ** argv) { clist * list; struct mailimf_mailbox * mb; struct mailimf_address * addr; struct mailimf_address_list * addr_list; struct mailimf_cc * cc; list = clist_new(); mb = mailimf_mailbox_new(strdup("DINH =?iso-8859-1?Q?Vi=EAt_Ho=E0?="), strdup("dinh.viet.hoa@free.fr")); addr = mailimf_address_new(MAILIMF_ADDRESS_MAILBOX, mb, NULL); clist_append(list, addr); mb = mailimf_mailbox_new(strdup("Christophe GIAUME"), strdup("christophe@giaume.com")); addr = mailimf_address_new(MAILIMF_ADDRESS_MAILBOX, mb, NULL); clist_append(list, addr); addr_list = mailimf_address_list_new(list); cc = mailimf_cc_new(addr_list); /* do the things */ mailimf_cc_free(cc); return 0; } /* display content of Cc field */ #include <libetpan/libetpan.h> void display_cc(struct mailimf_cc * cc) { display_address_list(cc->cc_addr_list); }
#include <libetpan/libetpan.h> struct mailimf_bcc { struct mailimf_address_list * bcc_addr_list; /* can be NULL */ }; struct mailimf_bcc * mailimf_bcc_new(struct mailimf_address_list * bcc_addr_list); void mailimf_bcc_free(struct mailimf_bcc * bcc);
This is the content of a header Bcc or Resent-Bcc.
bcc_addr_list is the parsed address list (see the Section called mailimf_address_list - list of addresses).
mailimf_bcc_new() creates and initializes a data structure with a value. Structures given as argument are referenced by the created object and will be freed if the object is released.
mailimf_bcc_free() frees memory used by the structure and substructures will also be released.
Example 3-16. creation and display of Bcc field
/* create visible Bcc */ #include <libetpan/libetpan.h> int main(int argc, char ** argv) { clist * list; struct mailimf_mailbox * mb; struct mailimf_address * addr; struct mailimf_address_list * addr_list; struct mailimf_bcc * bcc; list = clist_new(); mb = mailimf_mailbox_new(strdup("DINH =?iso-8859-1?Q?Vi=EAt_Ho=E0?="), strdup("dinh.viet.hoa@free.fr")); addr = mailimf_address_new(MAILIMF_ADDRESS_MAILBOX, mb, NULL); clist_append(list, addr); mb = mailimf_mailbox_new(strdup("Christophe GIAUME"), strdup("christophe@giaume.com")); addr = mailimf_address_new(MAILIMF_ADDRESS_MAILBOX, mb, NULL); clist_append(list, addr); addr_list = mailimf_address_list_new(list); bcc = mailimf_bcc_new(addr_list); /* do the things */ mailimf_bcc_free(bcc); return 0; } /* create unvisible Bcc */ #include <libetpan/libetpan.h> int main(int argc, char ** argv) { struct mailimf_bcc * bcc; bcc = mailimf_bcc_new(NULL); /* do the things */ mailimf_bcc_free(bcc); return 0; } /* display content of Bcc field */ #include <libetpan/libetpan.h> #include <stdio.h> void display_bcc(struct mailimf_bcc * bcc) { if (bcc->addr_list == NULL) { printf("hidden Bcc\n"); } else { display_address_list(bcc->bcc_addr_list); } }
#include <libetpan/libetpan.h> struct mailimf_message_id { char * mid_value; /* != NULL */ }; struct mailimf_message_id * mailimf_message_id_new(char * mid_value); void mailimf_message_id_free(struct mailimf_message_id * message_id);
This is the content of a header Message-ID or Resent-Message-ID. For example :
mid_value is the message identifier. It is not enclosed by angle bracket.
mailimf_message_id_new() This function creates and initializes a data structure with a value. Structures given as argument are referenced by the created object and will be freed if the object is released.
The given string is allocated with malloc() and is not enclosed by angle bracket.
mailimf_message_id_free() frees memory used by the structure and substructures will also be released.
Example 3-18. creation and display of Message-ID field
#include <libetpan/libetpan.h> int main(int argc, char ** argv) { struct mailimf_message_id * msg_id; char * id; id = strdup("1037197913.3dd26259752fa@imp.free.fr"); msg_id = mailimf_message_id_new(id); /* do the things */ mailimf_message_id_free(msg_id); return 0; } /* display message id */ #include <libetpan/libetpan.h> #include <stdio.h> void display_message_id(struct mailimf_message_id * msg_id) { printf("%s\n", msg_id->mid_value); }
#include <libetpan/libetpan.h> struct mailimf_in_reply_to { clist * mid_list; /* list of (char *), != NULL */ }; struct mailimf_in_reply_to * mailimf_in_reply_to_new(clist * mid_list); void mailimf_in_reply_to_free(struct mailimf_in_reply_to * in_reply_to);
content of a header In-Reply-To. For example :
In-Reply-To: <etPan.3fd5fa29.4c3901c1.6b39@homer>
mid_list is a clist in which elements are message identifiers. their types are (char *) and they are allocated with malloc().
mailimf_in_reply_to_new() creates and initializes a data structure with a value. Structures given as argument are referenced by the created object and will be freed if the object is released.
mailimf_in_reply_to_free() frees memory used by the structure and substructures will also be released.
Example 3-19. creation and display of In-Reply-To field
#include <libetpan/libetpan.h> int main(int argc, char ** argv) { struct mailimf_in_reply_to * in_reply_to; clist * msg_id_list; msg_id_list = clist_new(); clist_append(msg_id_list, strdup("etPan.3ebbcc18.4014197f.bc1@homer.invalid")); in_reply_to = mailimf_in_reply_to_new(msg_id_list); /* do the things */ mailimf_in_reply_to_free(in_reply_to); return 0; } /* display the content of mailimf_in_reply_to */ #include <libetpan/libetpan.h> #include <stdio.h> void display_in_reply_to(struct mailimf_in_reply_to * in_reply_to) { clistiter * cur; for(cur = clist_begin(in_reply_to->mid_list) ; cur != NULL ; cur = clist_next(cur)) { char * str; str = clist_content(cur); printf("%s\n", str); } }
#include <libetpan/libetpan.h> struct mailimf_references { clist * mid_list; /* list of (char *) */ /* != NULL */ }; struct mailimf_references * mailimf_references_new(clist * mid_list); void mailimf_references_free(struct mailimf_references * references);
This is the content of a header References. For example :
In-Reply-To: <etPan.3fd5fa29.4c3901c1.6b39@homer> <EMAIL_ADDRESS><etPan.3fd5fc69.2b349482.730e@homer>
mid_list is a clist in which elements are message identifiers. their types are (char *) and they are allocated with malloc().
mailimf_references_new() creates and initializes a data structure with a value. Structures given as argument are referenced by the created object and will be freed if the object is released.
mailimf_references_free() frees memory used by the structure and substructures will also be released.
Example 3-20. creation and display of References field
#include <libetpan/libetpan.h> int main(int argc, char ** argv) { struct mailimf_references * ref; clist * msg_id_list; msg_id_list = clist_new(); clist_append(msg_id_list, strdup("200304280144.23633.wim.delvaux@adaptiveplanet.com")); clist_append(msg_id_list, strdup("200304301153.19688.wim.delvaux@adaptiveplanet.com")); clist_append(msg_id_list, strdup("etPan.3eb29de4.5fc4d652.3f83@homer")); ref = mailimf_references_new(msg_id_list); /* do the things */ mailimf_in_reply_to_free(ref); return 0; } /* display references */ #include <libetpan/libetpan.h> #include <stdio.h> void display_references(struct mailimf_references * ref) { clistiter * cur; for(cur = clist_begin(ref->mid_list) ; cur != NULL ; cur = clist_next(cur)) { char * msg_id; msg_id = clist_content(cur); printf("%s\n", msg_id); } }
#include <libetpan/libetpan.h> struct mailimf_subject { char * sbj_value; /* != NULL */ }; struct mailimf_subject * mailimf_subject_new(char * sbj_value); void mailimf_subject_free(struct mailimf_subject * subject);
This is the content of a header Subject.
sbj_value is the value of the field.
mailimf_subject_new() creates and initializes a data structure with a value. Structures given as argument are referenced by the created object and will be freed if the object is released.
mailimf_subject_free frees memory used by the structure and substructures will also be released.
Example 3-21. creation and display of Subject field
#include <libetpan/libetpan.h> int main(int argc, char ** argv) { struct mailimf_subject * subject; subject = mailimf_subject_new(strdup("example of subject")); /* do the things */ mailimf_subject_free(subject); return 0; } /* display subject header */ #include <libetpan/libetpan.h> #include <stdio.h> void display_subject(struct mailimf_subject * subject) { printf("%s\n", subject->value); }
#include <libetpan/libetpan.h> struct mailimf_comments { char * cm_value; /* != NULL */ }; struct mailimf_comments * mailimf_comments_new(char * cm_value); void mailimf_comments_free(struct mailimf_comments * comments);
This is the content of a header Comments.
cm_value is the value of the field.
mailimf_comments_new() creates and initializes a data structure with a value. Structures given as argument are referenced by the created object and will be freed if the object is released.
mailimf_comments_free() frees memory used by the structure and substructures will also be released.
Example 3-22. creation and display of Comment field
#include <libetpan/libetpan.h> int main(int argc, char ** argv) { struct mailimf_comments * comments; comments = mailimf_comments_new(strdup("example of comment")); /* do the things */ mailimf_comments_free(comments); return 0; } /* display the content of a comments */ #include <libetpan/libetpan.h> #include <stdio.h> void display_comments(struct mailimf_comments * comments) { printf("%s\n", comments->cm_value); }
#include <libetpan/libetpan.h> struct mailimf_keywords { clist * kw_list; /* list of (char *), != NULL */ }; struct mailimf_keywords * mailimf_keywords_new(clist * kw_list); void mailimf_keywords_free(struct mailimf_keywords * keywords);
This is the content of a header Keywords.
kw_list is the list of keywords. This is a list of (char *) allocated with malloc().
mailimf_keywords_new() creates and initializes a data structure with a value. Structures given as argument are referenced by the created object and will be freed if the object is released.
mailimf_keywords_free() frees memory used by the structure and substructures will also be released.
Example 3-23. creation and display of Keywords field
#include <libetpan/libetpan.h> int main(int argc, char ** argv) { struct mailimf_keywords * keywords; clist * list; list = clist_new(); clist_append(list, strdup("sauerkraut")); clist_append(list, strdup("potatoes")); clist_append(list, strdup("cooking")); keywords = mailimf_keywords_new(list); /* do the things */ mailimf_keywords_free(keywords); return 0; } /* display the content of mailimf_in_reply_to */ #include <libetpan/libetpan.h> #include <stdio.h> void display_keywords(struct mailimf_keywords * kw) { clistiter * cur; for(cur = clist_begin(kw->kw_list) ; cur != NULL ; cur = clist_next(cur)) { char * str; str = clist_content(cur); printf("%s\n", str); } }
#include <libetpan/libetpan.h> struct mailimf_return { struct mailimf_path * ret_path; /* != NULL */ }; struct mailimf_return * mailimf_return_new(struct mailimf_path * ret_path); void mailimf_return_free(struct mailimf_return * return_path);
This is the content of a header Return-Path.
ret_path is the parsed value of Return-Path (see the Section called mailimf_path - address in Return-Path field).
mailimf_return_new() creates and initializes a data structure with a value. Structures given as argument are referenced by the created object and will be freed if the object is released.
mailimf_return_free() frees memory used by the structure and substructures will also be released.
Example 3-24. creation and display of Return-Path field
#include <libetpan/libetpan.h> int main(int argc, char ** argv) { struct mailimf_path * path; struct mailimf_return * r; path = mailimf_path_new(strdup("dinh.viet.hoa@free.fr")); r = mailimf_return_new(path); /* do the things */ mailimf_return_free(r); return 0; } /* display return path */ #include <libetpan/libetpan.h> void display_return(struct mailimf_return * r) { display_path(r->ret_path); }
#include <libetpan/libetpan.h> struct mailimf_path { char * pt_addr_spec; /* can be NULL */ }; struct mailimf_path * mailimf_path_new(char * pt_addr_spec); void mailimf_path_free(struct mailimf_path * path);
This is the encapsulation of address specifier for Return-Path content.
pt_addr_spec is a mailbox destination.
mailimf_path_new() creates and initializes a data structure with a value. Structures given as argument are referenced by the created object and will be freed if the object is released.
The given string is allocated with malloc(). This is a address specifier.
mailimf_path_free() frees memory used by the structure and substructures will also be released.
Example 3-25. Creation and display of return path
#include <libetpan/libetpan.h> int main(int argc, char ** argv) { struct mailimf_path * path; path = mailimf_path_new(strdup("dinh.viet.hoa@free.fr")); /* do the things */ mailimf_path_free(r); return 0; } /* display return path */ #include <libetpan/libetpan.h> #include <stdio.h> void display_path(struct mailimf_path * path) { printf("%s\n", path->pt_addr_spec); }
#include <libetpan/libetpan.h> struct mailimf_optional_field { char * fld_name; /* != NULL */ char * fld_value; /* != NULL */ }; struct mailimf_optional_field * mailimf_optional_field_new(char * fld_name, char * fld_value); void mailimf_optional_field_free(struct mailimf_optional_field * opt_field);
This is a non-standard header or unparsed header.
fld_name is the name of the header field.
fld_value is the value of the header field.
mailimf_optional_field_new() This function creates and initializes a data structure with a value. Structures given as argument are referenced by the created object and will be freed if the object is released.
field name and field value have to be allocated with malloc().
mailimf_optional_field_free() This function frees memory used by the structure and substructures will also be released.
Example 3-26. creation and display of non-standard fields
#include <libetpan/libetpan.h> int main(int argc, char ** argv) { struct mailimf_optional_field * opt; opt = mailimf_optional_field_new(strdup("X-My-Field"), strdup("my value")); /* do the things */ mailimf_optional_field_free(opt); return 0; } /* display the optional field */ #include <libetpan/libetpan.h> #include <stdio.h> void display_optional_field(struct mailimf_optional_field * opt) { printf("%s: %s\n", opt->fld_name, opt->fld_value); }
#include <libetpan/libetpan.h> enum { MAILIMF_FIELD_NONE, /* on parse error */ MAILIMF_FIELD_RETURN_PATH, /* Return-Path */ MAILIMF_FIELD_RESENT_DATE, /* Resent-Date */ MAILIMF_FIELD_RESENT_FROM, /* Resent-From */ MAILIMF_FIELD_RESENT_SENDER, /* Resent-Sender */ MAILIMF_FIELD_RESENT_TO, /* Resent-To */ MAILIMF_FIELD_RESENT_CC, /* Resent-Cc */ MAILIMF_FIELD_RESENT_BCC, /* Resent-Bcc */ MAILIMF_FIELD_RESENT_MSG_ID, /* Resent-Message-ID */ MAILIMF_FIELD_ORIG_DATE, /* Date */ MAILIMF_FIELD_FROM, /* From */ MAILIMF_FIELD_SENDER, /* Sender */ MAILIMF_FIELD_REPLY_TO, /* Reply-To */ MAILIMF_FIELD_TO, /* To */ MAILIMF_FIELD_CC, /* Cc */ MAILIMF_FIELD_BCC, /* Bcc */ MAILIMF_FIELD_MESSAGE_ID, /* Message-ID */ MAILIMF_FIELD_IN_REPLY_TO, /* In-Reply-To */ MAILIMF_FIELD_REFERENCES, /* References */ MAILIMF_FIELD_SUBJECT, /* Subject */ MAILIMF_FIELD_COMMENTS, /* Comments */ MAILIMF_FIELD_KEYWORDS, /* Keywords */ MAILIMF_FIELD_OPTIONAL_FIELD, /* other field */ }; struct mailimf_field { int fld_type; union { struct mailimf_return * fld_return_path; /* can be NULL */ struct mailimf_orig_date * fld_resent_date; /* can be NULL */ struct mailimf_from * fld_resent_from; /* can be NULL */ struct mailimf_sender * fld_resent_sender; /* can be NULL */ struct mailimf_to * fld_resent_to; /* can be NULL */ struct mailimf_cc * fld_resent_cc; /* can be NULL */ struct mailimf_bcc * fld_resent_bcc; /* can be NULL */ struct mailimf_message_id * fld_resent_msg_id; /* can be NULL */ struct mailimf_orig_date * fld_orig_date; /* can be NULL */ struct mailimf_from * fld_from; /* can be NULL */ struct mailimf_sender * fld_sender; /* can be NULL */ struct mailimf_reply_to * fld_reply_to; /* can be NULL */ struct mailimf_to * fld_to; /* can be NULL */ struct mailimf_cc * fld_cc; /* can be NULL */ struct mailimf_bcc * fld_bcc; /* can be NULL */ struct mailimf_message_id * fld_message_id; /* can be NULL */ struct mailimf_in_reply_to * fld_in_reply_to; /* can be NULL */ struct mailimf_references * fld_references; /* can be NULL */ struct mailimf_subject * fld_subject; /* can be NULL */ struct mailimf_comments * fld_comments; /* can be NULL */ struct mailimf_keywords * fld_keywords; /* can be NULL */ struct mailimf_optional_field * fld_optional_field; /* can be NULL */ } fld_data; }; struct mailimf_field * mailimf_field_new(int fld_type, struct mailimf_return * fld_return_path, struct mailimf_orig_date * fld_resent_date, struct mailimf_from * fld_resent_from, struct mailimf_sender * fld_resent_sender, struct mailimf_to * fld_resent_to, struct mailimf_cc * fld_resent_cc, struct mailimf_bcc * fld_resent_bcc, struct mailimf_message_id * fld_resent_msg_id, struct mailimf_orig_date * fld_orig_date, struct mailimf_from * fld_from, struct mailimf_sender * fld_sender, struct mailimf_reply_to * fld_reply_to, struct mailimf_to * fld_to, struct mailimf_cc * fld_cc, struct mailimf_bcc * fld_bcc, struct mailimf_message_id * fld_message_id, struct mailimf_in_reply_to * fld_in_reply_to, struct mailimf_references * fld_references, struct mailimf_subject * fld_subject, struct mailimf_comments * fld_comments, struct mailimf_keywords * fld_keywords, struct mailimf_optional_field * fld_optional_field); void mailimf_field_free(struct mailimf_field * field);
This is one header field of a message.
type is the type of the field. This define the type of the field. Only the corresponding field should be, then, filled. The value of this field can be one of : MAILIMF_FIELD_RETURN_PATH, MAILIMF_FIELD_RESENT_DATE, MAILIMF_FIELD_RESENT_FROM, MAILIMF_FIELD_RESENT_SENDER, MAILIMF_FIELD_RESENT_TO, MAILIMF_FIELD_RESENT_CC, MAILIMF_FIELD_RESENT_BCC, MAILIMF_FIELD_RESENT_MSG_ID, MAILIMF_FIELD_ORIG_DATE, MAILIMF_FIELD_FROM, MAILIMF_FIELD_SENDER, MAILIMF_FIELD_REPLY_TO, MAILIMF_FIELD_TO, MAILIMF_FIELD_CC, MAILIMF_FIELD_BCC, MAILIMF_FIELD_MESSAGE_ID, MAILIMF_FIELD_IN_REPLY_TO, MAILIMF_FIELD_REFERENCES, MAILIMF_FIELD_SUBJECT, MAILIMF_FIELD_COMMENTS, MAILIMF_FIELD_KEYWORDS, MAILIMF_FIELD_OPTIONAL_FIELD.
fld_data.fld_return_path is the parsed content of the Return-Path field if type is MAILIMF_FIELD_RETURN_PATH (see the Section called mailimf_return - parsed content of Return-Path field).
fld_data.fld_resent_date is the parsed content of the Resent-Date field if type is MAILIMF_FIELD_RESENT_DATE (see the Section called mailimf_orig_date - parsed content of date header).
fld_data.fld_resent_from is the parsed content of the Resent-From field if type is MAILIMF_FIELD_RESENT_FROM (see the Section called mailimf_from - parsed content of From header).
fld_data.fld_resent_sender is the parsed content of the Resent-Sender field if type is MAILIMF_FIELD_RESENT_SENDER (see the Section called mailimf_sender - parsed content of Sender header).
fld_data.fld_resent_to is the parsed content of the Resent-To field if type is MAILIMF_FIELD_RESENT_TO (see the Section called mailimf_to - parsed content of To header).
fld_data.fld_resent_cc is the parsed content of the Resent-Cc field if type is MAILIMF_FIELD_CC (see the Section called mailimf_cc - parsed content of Cc).
fld_data.fld_resent_bcc is the parsed content of the Resent-Bcc field if type is MAILIMF_FIELD_BCC (see the Section called mailimf_bcc - parsed content of Bcc field).
fld_data.fld_resent_msg_id is the parsed content of the Resent-Message-ID field if type is MAILIMF_FIELD_RESENT_MSG_ID (see the Section called mailimf_message_id - parsed content of Message-ID header).
fld_data.fld_orig_date is the parsed content of the Date field if type is MAILIMF_FIELD_ORIG_DATE (see the Section called mailimf_orig_date - parsed content of date header).
fld_data.fld_from is the parsed content of the From field if type is MAILIMF_FIELD_FROM (see the Section called mailimf_from - parsed content of From header).
fld_data.fld_sender is the parsed content of the Sender field if type is MAILIMF_FIELD_SENDER (see the Section called mailimf_sender - parsed content of Sender header).
fld_data.fld_reply_to is the parsed content of the Reply-To field if type is MAILIMF_FIELD_REPLY_TO (see the Section called mailimf_reply_to - parsed content of Reply-To header).
fld_data.fld_to is the parsed content of the To field if type is MAILIMF_FIELD_TO (see the Section called mailimf_to - parsed content of To header).
fld_data.fld_cc is the parsed content of the Cc field if type is MAILIMF_FIELD_CC (see the Section called mailimf_cc - parsed content of Cc).
fld_data.fld_bcc is the parsed content of the Bcc field if type is MAILIMF_FIELD_BCC (see the Section called mailimf_bcc - parsed content of Bcc field).
fld_data.fld_message_id is the parsed content of the Message-ID field if type is MAILIMF_FIELD_MESSAGE_ID (see the Section called mailimf_message_id - parsed content of Message-ID header).
fld_data.fld_in_reply_to is the parsed content of the In-Reply-To field if type is MAILIMF_FIELD_IN_REPLY_TO (see the Section called mailimf_in_reply_to - parsed content of In-Reply-To field).
fld_data.fld_references is the parsed content of the References field if type is MAILIMF_FIELD_REFERENCES (see the Section called mailimf_references - parsed content of References field).
fld_data.fld_subject is the content of the Subject field if type is MAILIMF_FIELD_SUBJECT (see the Section called mailimf_subject - parsed content of Subject field).
fld_data.fld_comments is the content of the Comments field if type is MAILIMF_FIELD_COMMENTS (see the Section called mailimf_comments - parsed content of Comments field).
fld_data.fld_keywords is the parsed content of the Keywords field if type is MAILIMF_FIELD_KEYWORDS (see the Section called mailimf_keywords - parsed content of Keywords field).
fld_data.fld_optional_field is an other field and is not parsed if type is MAILIMF_FIELD_OPTIONAL_FIELD (see the Section called mailimf_optional_field - non-standard header).
mailimf_field_new() creates and initializes a data structure with a value. Structures given as argument are referenced by the created object and will be freed if the object is released.
mailimf_field_free() frees memory used by the structure and substructures will also be released.
Example 3-27. creation and display of field
#include <libetpan/libetpan.h> int main(int argc, char ** argv) { struct mailimf_field * f; struct mailimf_mailbox * mb; struct mailimf_mailbox_list * mb_list; struct mailimf_from * from; /* build header 'From' */ list = clist_new(); mb = mailimf_mailbox_new(strdup("DINH =?iso-8859-1?Q?Vi=EAt_Ho=E0?="), strdup("dinh.viet.hoa@free.fr")); clist_append(list, mb); mb_list = mailimf_mailbox_list_new(list); from = mailimf_from_new(mb_list); f = mailimf_field_new(MAILIMF_FIELD_FROM, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, from, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); /* do the things */ mailimf_field_free(f); return 0; } /* display content of the header */ #include <libetpan/libetpan.h> #include <stdio.h> void display_field(struct mailimf_field * field) { switch (field->type) { case MAILIMF_FIELD_RETURN_PATH: printf("Return-Path:\n"); display_return(field->fld_data.fld_return_path); break; case MAILIMF_FIELD_RESENT_DATE: printf("Resent-Date:\n"); display_orig_date(field->fld_data.fld_orig_date); break; case MAILIMF_FIELD_RESENT_FROM: printf("Resent-From:\n"); display_from(field->fld_data.fld_orig_date); break; case MAILIMF_FIELD_RESENT_SENDER: printf("Resent-Sender:\n"); display_sender(field->fld_data.fld_resent_sender); break; case MAILIMF_FIELD_RESENT_TO: printf("Resent-To:\n"); display_to(field->fld_data.fld_resent_to); break; case MAILIMF_FIELD_RESENT_CC: printf("Resent-Cc:\n"); display_from(field->fld_data.fld_resent_cc); break; case MAILIMF_FIELD_RESENT_BCC: printf("Resent-Bcc:\n"); display_from(field->fld_data.fld_resent_bcc); break; case MAILIMF_FIELD_RESENT_MSG_ID: printf("Resent-Message-ID:\n"); display_message_id(field->fld_data.fld_resent_msg_id); break; case MAILIMF_FIELD_ORIG_DATE: printf("Date:\n"); display_orig_date(field->fld_data.fld_orig_date); break; case MAILIMF_FIELD_FROM: printf("From:\n"); display_from(field->fld_data.fld_from); break; case MAILIMF_FIELD_SENDER: printf("Sender:\n"); display_sender(field->fld_data.fld_sender); break; case MAILIMF_FIELD_REPLY_TO: printf("Reply-To:\n"); display_reply_to(field->fld_data.fld_reply_to); break; case MAILIMF_FIELD_TO: printf("To:\n"); display_to(field->fld_data.fld_to); break; case MAILIMF_FIELD_CC: printf("Cc:\n"); display_cc(field->fld_data.fld_cc); break; case MAILIMF_FIELD_BCC: printf("Bcc:\n"); display_bcc(field->fld_data.fld_bcc); break; case MAILIMF_FIELD_MESSAGE_ID: printf("Message-ID:\n"); display_message_id(field->fld_data.fld_message_id); break; case MAILIMF_FIELD_IN_REPLY_TO: printf("In-Reply-To:\n"); display_in_reply_to(field->fld_data.fld_in_reply_to); break; case MAILIMF_FIELD_REFERENCES: printf("References:\n"); display_references(field->fld_data.fld_references_to); break; case MAILIMF_FIELD_SUBJECT: printf("Subject:\n"); display_subject(field->fld_data.fld_subject); break; case MAILIMF_FIELD_COMMENTS: printf("Comments:\n"); display_comments(field->fld_data.fld_comments); break; case MAILIMF_FIELD_KEYWORDS: printf("Keywords:\n"); display_keywords(field->fld_data.fld_keywords); break; case MAILIMF_FIELD_OPTIONAL_FIELD: printf("[optional field]:\n"); display_optional_field(field->fld_data.fld_optional_field); break; } }
#include <libetpan/libetpan.h> struct mailimf_fields { clist * fld_list; /* list of (struct mailimf_field *), != NULL */ }; struct mailimf_fields * mailimf_fields_new(clist * fld_list); void mailimf_fields_free(struct mailimf_fields * fields);
This is the list of header fields of a message.
fld_list is a list of header fields. This is a clist which elements are of type mailimf_field (see the Section called mailimf_field - header field).
mailimf_fields_new() creates and initializes a data structure with a value. Structures given as argument are referenced by the created object and will be freed if the object is released.
mailimf_fields_free() frees memory used by the structure and substructures will also be released.
Example 3-28. creation and display of header fields
#include <libetpan/libetpan.h> int main(int argc, char ** argv) { struct mailimf_fields * fields; struct mailimf_field * f; clist * list; struct mailimf_from * from; struct mailimf_to * to struct mailimf_mailbox * mb; struct mailimf_address * addr; struct mailimf_mailbox_list * mb_list; struct mailimf_address_list * addr_list; clist * fields_list; /* build headers */ fields_list = clist_new(); /* build header 'From' */ list = clist_new(); mb = mailimf_mailbox_new(strdup("DINH =?iso-8859-1?Q?Vi=EAt_Ho=E0?="), strdup("dinh.viet.hoa@free.fr")); clist_append(list, mb); mb_list = mailimf_mailbox_list_new(list); from = mailimf_from_new(mb_list); f = mailimf_field_new(MAILIMF_FIELD_FROM, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, from, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); clist_append(fields_list, f); /* build header To */ list = clist_new(); mb = mailimf_mailbox_new(strdup("DINH =?iso-8859-1?Q?Vi=EAt_Ho=E0?="), strdup("dinh.viet.hoa@free.fr")); addr = mailimf_address_new(MAILIMF_ADDRESS_MAILBOX, mb, NULL); clist_append(list, addr); addr_list = mailimf_address_list_new(list); to = mailimf_to_new(addr_list); f = mailimf_field_new(MAILIMF_FIELD_TO, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, to, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); clist_append(fields_list, f); fields = mailimf_fields_new(fields_list); /* do the things */ mailimf_fields_free(fields); return 0; } /* display list of headers */ #include <libetpan/libetpan.h> #include <stdio.h> void display_fields(struct mailimf_fields * fields) { clistiter * cur; for(cur = clist_begin(field->fld_list) ; cur != NULL ; cur = clist_next(cur)) { struct mailimf_field * f; f = clist_content(cur); display_field(f); printf("\n"); } }
#include <libetpan/libetpan.h> struct mailimf_body { const char * bd_text; /* != NULL */ size_t bd_size; }; struct mailimf_body * mailimf_body_new(const char * bd_text, size_t bd_size); void mailimf_body_free(struct mailimf_body * body);
This is the text content of a message (without headers).
bd_text is the beginning of the text part, it is a substring of an other string. It is not necessarily zero terminated.
bd_size is the size of the text part
mailimf_body_new() creates and initializes a data structure with a value. Text given as argument will NOT be released.
mailimf_body_free() frees memory used by the structure.
Example 3-29. creation and display of message body
#include <libetpan/libetpan.h> int main(int argc, char ** argv) { struct mailimf_body * b; b = mailimf_body_new("this is the content of the message", 34); /* do the things */ mailimf_body_free(b); return 0; } #include <libetpan/libetpan.h> #include <stdio.h> void display_body(struct mailimf_body * b) { char * text; text = malloc(b->size + 1); strncpy(text, b->bd_text, b->bd_size); text[b->size] = 0; puts(text); printf("\n"); free(text); return 0; }
#include <libetpan/libetpan.h> struct mailimf_message { struct mailimf_fields * msg_fields; /* != NULL */ struct mailimf_body * msg_body; /* != NULL */ }; struct mailimf_message * mailimf_message_new(struct mailimf_fields * msg_fields, struct mailimf_body * msg_body); void mailimf_message_free(struct mailimf_message * message);
This is the message content (text and headers).
msg_fields is the header fields of the message (see the Section called mailimf_fields - list of header fields).
msg_body is the text part of the message (see the Section called mailimf_body - message body without headers).
mailimf_message_new() creates and initializes a data structure with a value. Structures given as argument are referenced by the created object and will be freed if the object is released.
mailimf_message_free() frees memory used by the structure and substructures will also be released.
Example 3-30. creation and display of message
#include <libetpan/libetpan.h> int main(int argc, char ** argv) { struct mailimf_body * b; struct mailimf_message * m; struct mailimf_fields * fields; struct mailimf_fields * f; clist * list; struct mailimf_from * from; struct mailimf_to * to struct mailimf_mailbox * mb; struct mailimf_address * addr; struct mailimf_mailbox_list * mb_list; struct mailimf_address_list * addr_list; clist * fields_list; /* build text content */ b = mailimf_body_new("this is the content of the message", 34); /* build headers */ fields_list = clist_new(); /* build header 'From' */ list = clist_new(); mb = mailimf_mailbox_new(strdup("DINH =?iso-8859-1?Q?Vi=EAt_Ho=E0?="), strdup("dinh.viet.hoa@free.fr")); clist_append(list, mb); mb_list = mailimf_mailbox_list_new(list); from = mailimf_from_new(mb_list); f = mailimf_field_new(MAILIMF_FIELD_FROM, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, from, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); clist_append(fields_list, f); /* build header To */ list = clist_new(); mb = mailimf_mailbox_new(strdup("DINH =?iso-8859-1?Q?Vi=EAt_Ho=E0?="), strdup("dinh.viet.hoa@free.fr")); addr = mailimf_address_new(MAILIMF_ADDRESS_MAILBOX, mb, NULL); clist_append(list, addr); addr_list = mailimf_address_list_new(list); to = mailimf_to_new(addr_list); f = mailimf_field_new(MAILIMF_FIELD_TO, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, to, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); clist_append(fields_list, f); fields = mailimf_fields_new(fields_list); /* build message */ m = mailimf_message_new(fields, b); /* do the things */ mailimf_message_free(m); return 0; } /* display the message */ #include <libetpan/libetpan.h> #include <stdio.h> void display_message(struct mailimf_message * msg) { display_fields(msg->msg_fields); printf("\n"); display_body(msg->msg_body); printf("\n"); }
#include <libetpan/libetpan.h> struct mailimf_single_fields { struct mailimf_orig_date * fld_orig_date; /* can be NULL */ struct mailimf_from * fld_from; /* can be NULL */ struct mailimf_sender * fld_sender; /* can be NULL */ struct mailimf_reply_to * fld_reply_to; /* can be NULL */ struct mailimf_to * fld_to; /* can be NULL */ struct mailimf_cc * fld_cc; /* can be NULL */ struct mailimf_bcc * fld_bcc; /* can be NULL */ struct mailimf_message_id * fld_message_id; /* can be NULL */ struct mailimf_in_reply_to * fld_in_reply_to; /* can be NULL */ struct mailimf_references * fld_references; /* can be NULL */ struct mailimf_subject * fld_subject; /* can be NULL */ struct mailimf_comments * fld_comments; /* can be NULL */ struct mailimf_keywords * fld_keywords; /* can be NULL */ }; struct mailimf_single_fields * mailimf_single_fields_new(struct mailimf_fields * fields); void mailimf_single_fields_free(struct mailimf_single_fields * single_fields); void mailimf_single_fields_init(struct mailimf_single_fields * single_fields, struct mailimf_fields * fields);
Structure that contains some standard fields and allows access to a given header without running through the list.
mailimf_fields is the native structure that IMF module will use, this module will provide an easier structure to use when parsing fields. mailimf_single_fields is an easier structure to get parsed fields, rather than iteration over the list of fields
fld_orig_date is the parsed "Date" field (see the Section called mailimf_orig_date - parsed content of date header).
fld_from is the parsed "From" field (see the Section called mailimf_from - parsed content of From header).
fld_sender is the parsed "Sender "field (see the Section called mailimf_sender - parsed content of Sender header).
reply_to is the parsed "Reply-To" field (see the Section called mailimf_reply_to - parsed content of Reply-To header).
fld_to is the parsed "To" field (see the Section called mailimf_to - parsed content of To header).
fld_cc is the parsed "Cc" field (see the Section called mailimf_cc - parsed content of Cc).
fld_bcc is the parsed "Bcc" field (see the Section called mailimf_bcc - parsed content of Bcc field).
fld_message_id is the parsed "Message-ID" field. (see the Section called mailimf_message_id - parsed content of Message-ID header).
fld_in_reply_to is the parsed "In-Reply-To" field. (see the Section called mailimf_in_reply_to - parsed content of In-Reply-To field).
fld_references is the parsed "References" field. (see the Section called mailimf_references - parsed content of References field).
fld_subject is the parsed "Subject" field (see the Section called mailimf_subject - parsed content of Subject field).
fld_comments is the parsed "Comments" field (see the Section called mailimf_comments - parsed content of Comments field).
fld_keywords is the parsed "Keywords" field (see the Section called mailimf_keywords - parsed content of Keywords field).
mailimf_single_fields_new() creates and initializes a data structure with a value. Structures given as argument are referenced by the created object and will NOT be freed if the object is released.
mailimf_single_fields_free() frees memory used by the structure and substructures will NOT be released. They should be released by the application.
mailimf_single_fields_init() will initialize fill the data structure, using the given argument (fields). The interesting fields will be filled into single_fields.
Example 3-31. using mailimf_single_fields
#include <libetpan/libetpan.h> int main(int argc, char ** argv) { struct mailimf_single_fields * single_fields; struct mailimf_fields * fields; struct mailimf_field * f; clist * list; struct mailimf_from * from; struct mailimf_to * to struct mailimf_mailbox * mb; struct mailimf_address * addr; struct mailimf_mailbox_list * mb_list; struct mailimf_address_list * addr_list; clist * fields_list; /* build headers */ fields_list = clist_new(); /* build header 'From' */ list = clist_new(); mb = mailimf_mailbox_new(strdup("DINH =?iso-8859-1?Q?Vi=EAt_Ho=E0?="), strdup("dinh.viet.hoa@free.fr")); clist_append(list, mb); mb_list = mailimf_mailbox_list_new(list); from = mailimf_from_new(mb_list); f = mailimf_field_new(MAILIMF_FIELD_FROM, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, from, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); clist_append(fields_list, f); /* build header To */ list = clist_new(); mb = mailimf_mailbox_new(strdup("DINH =?iso-8859-1?Q?Vi=EAt_Ho=E0?="), strdup("dinh.viet.hoa@free.fr")); addr = mailimf_address_new(MAILIMF_ADDRESS_MAILBOX, mb, NULL); clist_append(list, addr); addr_list = mailimf_address_list_new(list); to = mailimf_to_new(addr_list); f = mailimf_field_new(MAILIMF_FIELD_TO, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, to, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); clist_append(fields_list, f); fields = mailimf_fields_new(fields_list); /* create the single fields */ single_fields = mailimf_single_fields_new(fields); /* do the things */ mailimf_single_fields_free(single_fields); mailimf_fields_free(fields); return 0; }
Example 3-32. using mailimf_single_fields without memory allocation
#include <libetpan/libetpan.h> int main(int argc, char ** argv) { struct mailimf_single_fields single_fields; struct mailimf_fields * fields; struct mailimf_field * f; clist * list; struct mailimf_from * from; struct mailimf_to * to struct mailimf_mailbox * mb; struct mailimf_address * addr; struct mailimf_mailbox_list * mb_list; struct mailimf_address_list * addr_list; clist * fields_list; /* build headers */ fields_list = clist_new(); /* build header 'From' */ list = clist_new(); mb = mailimf_mailbox_new(strdup("DINH =?iso-8859-1?Q?Vi=EAt_Ho=E0?="), strdup("dinh.viet.hoa@free.fr")); clist_append(list, mb); mb_list = mailimf_mailbox_list_new(list); from = mailimf_from_new(mb_list); f = mailimf_field_new(MAILIMF_FIELD_FROM, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, from, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); clist_append(fields_list, f); /* build header To */ list = clist_new(); mb = mailimf_mailbox_new(strdup("DINH =?iso-8859-1?Q?Vi=EAt_Ho=E0?="), strdup("dinh.viet.hoa@free.fr")); addr = mailimf_address_new(MAILIMF_ADDRESS_MAILBOX, mb, NULL); clist_append(list, addr); addr_list = mailimf_address_list_new(list); to = mailimf_to_new(addr_list); f = mailimf_field_new(MAILIMF_FIELD_TO, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, to, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); clist_append(fields_list, f); fields = mailimf_fields_new(fields_list); /* fill the single fields */ mailimf_fields_fields_init(&single_fields, fields); /* do the things */ mailimf_fields_free(fields); return 0; }
int mailimf_address_list_parse(char * message, size_t length, size_t * index, struct mailimf_address_list ** result);
mailimf_address_list_parse() parse a list of addresses in RFC 2822 form.
message this is a string containing the list of addresses.
length this is the size of the given string
index this is a pointer to the start of the list of addresses in the given string, (* index) is modified to point at the end of the parsed data.
result the result of the parse operation is stored in (* result) (see the Section called mailimf_address_list - list of addresses).
return MAILIMF_NO_ERROR on success, MAILIMF_ERROR_XXX on error.
Example 3-33. parsing a list of addresses
#include <libetpan/libetpan.h> #include <sys/stat.h> #include <sys/mman.h> int main(int argc, char ** argv) { int fd; int r; status = EXIT_FAILURE; fd = open("message.rfc2822", O_RDONLY); if (fd >= 0) { void * mem; struct stat stat_info; r = fstat(fd, &stat_info); if (r >= 0) { mem = mmap(NULL, stat_info.st_size, PROT_READ, MAP_PRIVATE); if (mem != MAP_FAILED) { struct mailimf_address_list * addr_list; size_t current_index; current_index = 0; r = mailimf_address_list_parse(mem, stat_info.st_size, ¤t_index, &addr_list); if (r == MAILIMF_NO_ERROR) { display_address_list(addr_list); /* do the things */ status = EXIT_SUCCESS; mailimf_address_list_free(addr_list); } } munmap(mem, stat_info.st_size); } close(fd); } exit(status); }
#include <libetpan/libetpan.h> int mailimf_address_parse(char * message, size_t length, size_t * index, struct mailimf_address ** result);
mailimf_address_parse() parse an address in RFC 2822 form.
message this is a string containing the address.
length this is the size of the given string.
index index this is a pointer to the start of the address in the given string, (* index) is modified to point at the end of the parsed data.
result the result of the parse operation is stored in (* result) (see the Section called mailimf_address - address).
return MAILIMF_NO_ERROR on success, MAILIMF_ERROR_XXX on error.
Example 3-34. parsing an address
#include <libetpan/libetpan.h> #include <sys/stat.h> #include <sys/mman.h> int main(int argc, char ** argv) { int fd; int r; status = EXIT_FAILURE; fd = open("message.rfc2822", O_RDONLY); if (fd >= 0) { void * mem; struct stat stat_info; r = fstat(fd, &stat_info); if (r >= 0) { mem = mmap(NULL, stat_info.st_size, PROT_READ, MAP_PRIVATE); if (mem != MAP_FAILED) { struct mailimf_address * addr; size_t current_index; current_index = 0; r = mailimf_address_parse(mem, stat_info.st_size, ¤t_index, &addr); if (r == MAILIMF_NO_ERROR) { display_address(addr); /* do the things */ status = EXIT_SUCCESS; mailimf_address_free(addr); } } munmap(mem, stat_info.st_size); } close(fd); } exit(status); }
#include <libetpan/libetpan.h> int mailimf_body_parse(char * message, size_t length, size_t * index, struct mailimf_body ** result);
mailimf_body_parse() parse text body of a message.
message this is a string containing the message body part.
length this is the size of the given string.
index this is a pointer to the start of the message text part in the given string, (* index) is modified to point at the end of the parsed data.
result the result of the parse operation is stored in (* result) (see the Section called mailimf_body - message body without headers).
return MAILIMF_NO_ERROR on success, MAILIMF_ERROR_XXX on error.
Example 3-35. parsing a message body
#include <libetpan/libetpan.h> #include <sys/stat.h> #include <sys/mman.h> int main(int argc, char ** argv) { int fd; int r; status = EXIT_FAILURE; fd = open("message.rfc2822", O_RDONLY); if (fd >= 0) { void * mem; struct stat stat_info; r = fstat(fd, &stat_info); if (r >= 0) { mem = mmap(NULL, stat_info.st_size, PROT_READ, MAP_PRIVATE); if (mem != MAP_FAILED) { struct mailimf_body * b; struct mailimf_fields * f; size_t current_index; size_t size; size = stat_info.st_size; current_index = 0; r = mailimf_fields_parse(mem, size, ¤t_index, &f); if (r == MAILIMF_NO_ERROR) { r = mailimf_crlf_parse(mem, size, ¤t_index); /* ignore parse error of crlf */ r = mailimf_body_parse(mem, size, ¤t_index, &b); if (r == MAILIMF_NO_ERROR) { display_body(b); /* do the things */ status = EXIT_SUCCESS; mailimf_body_free(b); } mailimf_fields_free(f); } } munmap(mem, stat_info.st_size); } close(fd); } exit(status); }
#include <libetpan/libetpan.h> int mailimf_envelope_and_optional_fields_parse(char * message, size_t length, size_t * index, struct mailimf_fields ** result);
mailimf_envelope_and_optional_fields_parse() returns a list of most useful headers (parsed). The other headers will be placed in the list in a non-parsed form.
message this is a string containing the header.
length this is the size of the given string
index index this is a pointer to the start of the header in the given string, (* index) is modified to point at the end of the parsed data
result the result of the parse operation is stored in (* result) (see the Section called mailimf_fields - list of header fields).
return MAILIMF_NO_ERROR on success, MAILIMF_ERROR_XXX on error.
Example 3-36. parsing commonly used fields and return other fields in a non-parsed form
#include <libetpan/libetpan.h> #include <sys/stat.h> #include <sys/mman.h> int main(int argc, char ** argv) { int fd; int r; status = EXIT_FAILURE; fd = open("message.rfc2822", O_RDONLY); if (fd >= 0) { void * mem; struct stat stat_info; r = fstat(fd, &stat_info); if (r >= 0) { mem = mmap(NULL, stat_info.st_size, PROT_READ, MAP_PRIVATE); if (mem != MAP_FAILED) { struct mailimf_fields * f; size_t current_index; current_index = 0; r = mailimf_envelope_and_optional_fields_parse(mem, stat_info.st_size, ¤t_index, &f); if (r == MAILIMF_NO_ERROR) { display_fields(m); /* do the things */ status = EXIT_SUCCESS; mailimf_fields_free(f); } } munmap(mem, stat_info.st_size); } close(fd); } exit(status); }
#include <libetpan/libetpan.h> int mailimf_envelope_fields_parse(char * message, size_t length, size_t * index, struct mailimf_fields ** result);
mailimf_envelope_fields_parse() return a list of most useful headers (parsed).
message this is a string containing the header
length this is the size of the given string
index index this is a pointer to the start of the header in the given string, (* index) is modified to point at the end of the parsed data
result the result of the parse operation is stored in (* result) (see the Section called mailimf_fields - list of header fields).
return MAILIMF_NO_ERROR on success, MAILIMF_ERROR_XXX on error.
Example 3-37. parsing commonly used fields
#include <libetpan/libetpan.h> #include <sys/stat.h> #include <sys/mman.h> int main(int argc, char ** argv) { int fd; int r; status = EXIT_FAILURE; fd = open("message.rfc2822", O_RDONLY); if (fd >= 0) { void * mem; struct stat stat_info; r = fstat(fd, &stat_info); if (r >= 0) { mem = mmap(NULL, stat_info.st_size, PROT_READ, MAP_PRIVATE); if (mem != MAP_FAILED) { struct mailimf_fields * f; size_t current_index; current_index = 0; r = mailimf_envelope_fields_parse(mem, stat_info.st_size, ¤t_index, &f); if (r == MAILIMF_NO_ERROR) { display_fields(m); /* do the things */ status = EXIT_SUCCESS; mailimf_fields_free(f); } } munmap(mem, stat_info.st_size); } close(fd); } exit(status); }
#include <libetpan/libetpan.h> int mailimf_optional_fields_parse(char * message, size_t length, size_t * index, struct mailimf_fields ** result);
mailimf_optional_fields_parse return a list of non-parsed headers.
message this is a string containing the header
length this is the size of the given string
index index this is a pointer to the start of the header in the given string, (* index) is modified to point at the end of the parsed data
result the result of the parse operation is stored in (* result) (see the Section called mailimf_fields - list of header fields).
return MAILIMF_NO_ERROR on success, MAILIMF_ERROR_XXX on error.
Example 3-38. parsing optional fields
#include <libetpan/libetpan.h> #include <sys/stat.h> #include <sys/mman.h> int main(int argc, char ** argv) { int fd; int r; status = EXIT_FAILURE; fd = open("message.rfc2822", O_RDONLY); if (fd >= 0) { void * mem; struct stat stat_info; r = fstat(fd, &stat_info); if (r >= 0) { mem = mmap(NULL, stat_info.st_size, PROT_READ, MAP_PRIVATE); if (mem != MAP_FAILED) { struct mailimf_fields * f; size_t current_index; current_index = 0; r = mailimf_optional_fields_parse(mem, stat_info.st_size, ¤t_index, &f); if (r == MAILIMF_NO_ERROR) { display_fields(m); /* do the things */ status = EXIT_SUCCESS; mailimf_fields_free(f); } } munmap(mem, stat_info.st_size); } close(fd); } exit(status); }
#include <libetpan/libetpan.h> int mailimf_fields_parse(char * message, size_t length, size_t * index, struct mailimf_fields ** result);
mailimf_fields_parse() parse headers of a message.
message this is a string containing the header
length this is the size of the given string
index index this is a pointer to the start of the header in the given string, (* index) is modified to point at the end of the parsed data
result the result of the parse operation is stored in (* result) (see the Section called mailimf_fields - list of header fields).
return MAILIMF_NO_ERROR on success, MAILIMF_ERROR_XXX on error.
Example 3-39. parsing header fields
#include <libetpan/libetpan.h> #include <sys/stat.h> #include <sys/mman.h> int main(int argc, char ** argv) { int fd; int r; status = EXIT_FAILURE; fd = open("message.rfc2822", O_RDONLY); if (fd >= 0) { void * mem; struct stat stat_info; r = fstat(fd, &stat_info); if (r >= 0) { mem = mmap(NULL, stat_info.st_size, PROT_READ, MAP_PRIVATE); if (mem != MAP_FAILED) { struct mailimf_fields * f; size_t current_index; current_index = 0; r = mailimf_fields_parse(mem, stat_info.st_size, ¤t_index, &f); if (r == MAILIMF_NO_ERROR) { display_fields(f); /* do the things */ status = EXIT_SUCCESS; mailimf_fields_free(f); } } munmap(mem, stat_info.st_size); } close(fd); } exit(status); }
#include <libetpan/libetpan.h> int mailimf_ignore_field_parse(char * message, size_t length, size_t * index);
mailimf_ignore_field_parse() skip the next header.
message this is a string containing the header
length this is the size of the given string
index index this is a pointer to the start of the field to skip in the given string, (* index) is modified to point at the end of the parsed data
return MAILIMF_NO_ERROR on success, MAILIMF_ERROR_XXX on error.
Example 3-40. skipping fields
#include <libetpan/libetpan.h> #include <sys/stat.h> #include <sys/mman.h> int main(int argc, char ** argv) { int fd; int r; status = EXIT_FAILURE; fd = open("message.rfc2822", O_RDONLY); if (fd >= 0) { void * mem; struct stat stat_info; r = fstat(fd, &stat_info); if (r >= 0) { mem = mmap(NULL, stat_info.st_size, PROT_READ, MAP_PRIVATE); if (mem != MAP_FAILED) { size_t current_index; current_index = 0; r = mailimf_ignore_field_parse(mem, stat_info.st_size, ¤t_index); if (r == MAILIMF_NO_ERROR) { /* do the things */ status = EXIT_SUCCESS; } } munmap(mem, stat_info.st_size); } close(fd); } exit(status); }
#include <libetpan/libetpan.h> int mailimf_mailbox_list_parse(char * message, size_t length, size_t * index, struct mailimf_mailbox_list ** result);
mailimf_mailbox_list_parse() parse a list of mailboxes in RFC 2822 form.
message this is a string containing the list of mailboxes.
length this is the size of the given string.
index index this is a pointer to the start of the list of mailboxes in the given string, (* index) is modified to point at the end of the parsed data.
result the result of the parse operation is stored in (* result). (see the Section called mailimf_mailbox_list - list of mailboxes)
return MAILIMF_NO_ERROR on success, MAILIMF_ERROR_XXX on error.
Example 3-41. parsing a list of mailboxes
#include <libetpan/libetpan.h> #include <sys/stat.h> #include <sys/mman.h> int main(int argc, char ** argv) { int fd; int r; status = EXIT_FAILURE; fd = open("message.rfc2822", O_RDONLY); if (fd >= 0) { void * mem; struct stat stat_info; r = fstat(fd, &stat_info); if (r >= 0) { mem = mmap(NULL, stat_info.st_size, PROT_READ, MAP_PRIVATE); if (mem != MAP_FAILED) { struct mailimf_mailbox_list * mb_list; size_t current_index; current_index = 0; r = mailimf_mailbox_list_parse(mem, stat_info.st_size, ¤t_index, &mb_list); if (r == MAILIMF_NO_ERROR) { display_mailbox_list(mb_list); /* do the things */ status = EXIT_SUCCESS; mailimf_mailbox_list_free(mb_list); } } munmap(mem, stat_info.st_size); } close(fd); } exit(status); }
#include <libetpan/libetpan.h> int mailimf_mailbox_parse(char * message, size_t length, size_t * index, struct mailimf_mailbox ** result);
mailimf_mailbox_parse parse a mailbox in RFC 2822 form.
message this is a string containing the mailbox.
length this is the size of the given string.
index index this is a pointer to the start of the mailbox in the given string, (* index) is modified to point at the end of the parsed data.
result the result of the parse operation is stored in (* result). (see the Section called mailimf_mailbox - mailbox)
return MAILIMF_NO_ERROR on success, MAILIMF_ERROR_XXX on error.
Example 3-42. parsing a mailbox
#include <libetpan/libetpan.h> #include <sys/stat.h> #include <sys/mman.h> int main(int argc, char ** argv) { int fd; int r; status = EXIT_FAILURE; fd = open("message.rfc2822", O_RDONLY); if (fd >= 0) { void * mem; struct stat stat_info; r = fstat(fd, &stat_info); if (r >= 0) { mem = mmap(NULL, stat_info.st_size, PROT_READ, MAP_PRIVATE); if (mem != MAP_FAILED) { struct mailimf_mailbox_list * mb_list; size_t current_index; current_index = 0; r = mailimf_mailbox_parse(mem, stat_info.st_size, ¤t_index, &mb_list); if (r == MAILIMF_NO_ERROR) { display_mailbox_list(mb_list); /* do the things */ status = EXIT_SUCCESS; mailimf_mailbox_free(mb_list); } } munmap(mem, stat_info.st_size); } close(fd); } exit(status); }
#include <libetpan/libetpan.h> int mailimf_message_parse(char * message, size_t length, size_t * index, struct mailimf_message ** result);
mailimf_message_parse parse message (headers and body).
message this is a string containing the message content.
param length this is the size of the given string.
param index this is a pointer to the start of the message in the given string, (* index) is modified to point at the end of the parsed data.
param result the result of the parse operation is stored in (* result) (see the Section called mailimf_message - parsed message).
Example 3-43. parsing a message
#include <libetpan/libetpan.h> #include <sys/stat.h> #include <sys/mman.h> int main(int argc, char ** argv) { int fd; int r; status = EXIT_FAILURE; fd = open("message.rfc2822", O_RDONLY); if (fd >= 0) { void * mem; struct stat stat_info; r = fstat(fd, &stat_info); if (r >= 0) { mem = mmap(NULL, stat_info.st_size, PROT_READ, MAP_PRIVATE); if (mem != MAP_FAILED) { struct mailimf_message * m; size_t current_index; current_index = 0; r = mailimf_message_parse(mem, stat_info.st_size, ¤t_index, &m); if (r == MAILIMF_NO_ERROR) { display_message(m); /* do the things */ status = EXIT_SUCCESS; mailimf_message_free(m); } } munmap(mem, stat_info.st_size); } close(fd); } exit(status); }
#include <libetpan/libetpan.h> struct mailimf_mailbox_list * mailimf_mailbox_list_new_empty(); int mailimf_mailbox_list_add(struct mailimf_mailbox_list * mailbox_list, struct mailimf_mailbox * mb); int mailimf_mailbox_list_add_parse(struct mailimf_mailbox_list * mailbox_list, char * mb_str); int mailimf_mailbox_list_add_mb(struct mailimf_mailbox_list * mailbox_list, char * display_name, char * address);
mailimf_mailbox_list_new_empty() creates a new empty list of mailboxes.
mailimf_mailbox_list_add adds a mailbox to the list of mailboxes.
mailimf_mailbox_list_add_parse adds a mailbox given in form of a string to the list of mailboxes.
mailimf_mailbox_list_add_mb adds a mailbox given in form of a couple : display name, mailbox address.
mailbox_list is the list of mailboxes.
mb is a mailbox (see the Section called mailimf_mailbox - mailbox).
mb_str is a mailbox given in the form of a string.
display_name is the display name.
address is the mailbox address.
Example 3-44. creating a list of mailboxes
#include <libetpan/libetpan.h> int main(int argc, char ** argv) { struct mailimf_mailbox_list * mb_list; struct mailimf_mailbox * mb; mb_list = mailimf_mailbox_list_new_empty(); mb = mailimf_mailbox_new(strdup("DINH Viet Hoa"), strdup("dinh.viet.hoa@free.fr")); mailimf_mailbox_list_add(mb_list, mb); mailimf_mailbox_list_add_parse(mb_list, "foo bar <foo@bar.org>"); mailimf_mailbox_list_add_mb(mb_list, strdup("bar foo"), strdup("bar@foo.com")); mailimf_mailbox_list_free(mb_list); }
#include <libetpan/libetpan.h> struct mailimf_address_list * mailimf_address_list_new_empty(); int mailimf_address_list_add(struct mailimf_address_list * address_list, struct mailimf_address * addr); int mailimf_address_list_add_parse(struct mailimf_address_list * address_list, char * addr_str); int mailimf_address_list_add_mb(struct mailimf_address_list * address_list, char * display_name, char * address);
mailimf_address_list_new_empty() creates a new empty list of addresses.
mailimf_address_list_add adds an address to the list of addresses.
mailimf_address_list_add_parse adds an address given in form of a string to the list of addresses.
mailimf_address_list_add_mb adds a mailbox given in form of a couple : display name, mailbox address.
address_list is the list of mailboxes.
addr is an address. (see the Section called mailimf_address - address).
addr_str is an address given in the form of a string.
display_name is the display name.
address is the mailbox address.
#include <libetpan/libetpan.h> struct mailimf_fields * mailimf_fields_new_empty(void); struct mailimf_field * mailimf_field_new_custom(char * name, char * value); int mailimf_fields_add(struct mailimf_fields * fields, struct mailimf_field * field); int mailimf_fields_add_data(struct mailimf_fields * fields, struct mailimf_date_time * date, struct mailimf_mailbox_list * from, struct mailimf_mailbox * sender, struct mailimf_address_list * reply_to, struct mailimf_address_list * to, struct mailimf_address_list * cc, struct mailimf_address_list * bcc, char * msg_id, clist * in_reply_to, clist * references, char * subject); struct mailimf_fields * mailimf_fields_new_with_data_all(struct mailimf_date_time * date, struct mailimf_mailbox_list * from, struct mailimf_mailbox * sender, struct mailimf_address_list * reply_to, struct mailimf_address_list * to, struct mailimf_address_list * cc, struct mailimf_address_list * bcc, char * message_id, clist * in_reply_to, clist * references, char * subject); struct mailimf_fields * mailimf_fields_new_with_data(struct mailimf_mailbox_list * from, struct mailimf_mailbox * sender, struct mailimf_address_list * reply_to, struct mailimf_address_list * to, struct mailimf_address_list * cc, struct mailimf_address_list * bcc, clist * in_reply_to, clist * references, char * subject); char * mailimf_get_message_id(void); struct mailimf_date_time * mailimf_get_current_date(void); int mailimf_resent_fields_add_data(struct mailimf_fields * fields, struct mailimf_date_time * resent_date, struct mailimf_mailbox_list * resent_from, struct mailimf_mailbox * resent_sender, struct mailimf_address_list * resent_to, struct mailimf_address_list * resent_cc, struct mailimf_address_list * resent_bcc, char * resent_msg_id); struct mailimf_fields * mailimf_resent_fields_new_with_data_all(struct mailimf_date_time * resent_date, struct mailimf_mailbox_list * resent_from, struct mailimf_mailbox * resent_sender, struct mailimf_address_list * resent_to, struct mailimf_address_list * resent_cc, struct mailimf_address_list * resent_bcc, char * resent_msg_id); struct mailimf_fields * mailimf_resent_fields_new_with_data(struct mailimf_mailbox_list * from, struct mailimf_mailbox * resent_sender, struct mailimf_address_list * resent_to, struct mailimf_address_list * resent_cc, struct mailimf_address_list * resent_bcc);
from is the parsed content of the From field (see the Section called mailimf_from - parsed content of From header).
sender is the parsed content of the Sender field (see the Section called mailimf_sender - parsed content of Sender header).
reply_to is the parsed content of the Reply-To field (see the Section called mailimf_reply_to - parsed content of Reply-To header).
to is the parsed content of the To field (see the Section called mailimf_to - parsed content of To header).
cc is the parsed content of the Cc field (see the Section called mailimf_cc - parsed content of Cc).
bcc is the parsed content of the Bcc field (see the Section called mailimf_bcc - parsed content of Bcc field).
message_id is the parsed content of the Message-ID field (see the Section called mailimf_message_id - parsed content of Message-ID header).
in_reply_to is the parsed content of the In-Reply-To field (see the Section called mailimf_in_reply_to - parsed content of In-Reply-To field).
references is the parsed content of the References field (see the Section called mailimf_references - parsed content of References field).
subject is the content of the Subject field (see the Section called mailimf_subject - parsed content of Subject field).
resent_date is the parsed content of the Resent-Date field (see the Section called mailimf_orig_date - parsed content of date header).
resent_from is the parsed content of the Resent-From field (see the Section called mailimf_from - parsed content of From header).
resent_sender is the parsed content of the Resent-Sender field (see the Section called mailimf_sender - parsed content of Sender header).
resent_to is the parsed content of the Resent-To field (see the Section called mailimf_to - parsed content of To header).
resent_cc is the parsed content of the Resent-Cc field (see the Section called mailimf_cc - parsed content of Cc).
resent_bcc is the parsed content of the Resent-Bcc field (see the Section called mailimf_bcc - parsed content of Bcc field).
resent_msg_id is the parsed content of the Resent-Message-ID field (see the Section called mailimf_message_id - parsed content of Message-ID header).
mailimf_fields_new_empty() creates a new empty set of headers.
mailimf_field_new_custom() creates a new custom header.
mailimf_fields_add() adds a header to the set of headers.
mailimf_fields_add_data() adds some headers to the set of headers.
mailimf_fields_new_with_data_all() creates a set of headers with some headers (including Date and Message-ID).
mailimf_fields_new_with_data() creates a set of headers with some headers (Date and Message-ID will be generated).
mailimf_get_message_id() generates a Message-ID. The result must be freed using free().
mailimf_get_current_date() generates a Date. The result must be freed using mailimf_date_time_free.
mailimf_resent_fields_add_data() adds some resent headers to the set of headers.
mailimf_resent_fields_new_with_data_all() creates a set of headers with some resent headers (including Resent-Date and Resent-Message-ID).
mailimf_resent_fields_new_with_data() creates a set of headers with some resent headers (Resent-Date and Resent-Message-ID will be generated)
Example 3-45. creation of header fields
#include <libetpan/libetpan.h> int main(int argc, char ** argv) { struct mailimf_fields * fields; struct mailimf_field * field; struct mailimf_date_time * date; char * msg_id; struct mailimf_mailbox_list * from; struct mailimf_address_list * to; fields = mailimf_fields_new_empty(); field = mailimf_field_new_custom(strdup("X-Mailer"), strdup("my-mailer")); mailimf_fields_add(fields, field); from = mailimf_mailbox_list_new_empty(); mailimf_mailbox_list_add_mb(from, strdup("DINH Viet Hoa"), strdup("dinh.viet.hoa@free.fr"); date = mailimf_get_current_date(); msg_id = mailimf_get_message_id(); to = mailimf_address_list_new_empty(); mailimf_address_list_add_mb(to, strdup("FOO Bar"), strdup("foo@bar.org"); mailimf_fields_add_data(fields, date, from, NULL, NULL, to, NULL, NULL, msg_id, NULL, NULL, strdup("hello")); /* do the things */ mailimf_fields_free(fields); } #include <libetpan/libetpan.h> int main(int argc, char ** argv) { struct mailimf_fields * fields; struct mailimf_mailbox_list * from; struct mailimf_address_list * to; struct mailimf_date_time * date; char * msg_id; from = mailimf_mailbox_list_new_empty(); mailimf_mailbox_list_add_mb(from, strdup("DINH Viet Hoa"), strdup("dinh.viet.hoa@free.fr"); to = mailimf_address_list_new_empty(); mailimf_address_list_add_mb(to, strdup("FOO Bar"), strdup("foo@bar.org"); date = mailimf_get_current_date(); msg_id = mailimf_get_message_id(); fields = mailimf_fields_new_with_all_data(date, from, NULL, NULL, to, NULL, NULL, msg_id, NULL, NULL, strdup("hello")); /* do the things */ mailimf_fields_free(fields); } #include <libetpan/libetpan.h> int main(int argc, char ** argv) { struct mailimf_fields * fields; struct mailimf_mailbox_list * from; struct mailimf_address_list * to; from = mailimf_mailbox_list_new_empty(); mailimf_mailbox_list_add_mb(from, strdup("DINH Viet Hoa"), strdup("dinh.viet.hoa@free.fr"); to = mailimf_address_list_new_empty(); mailimf_address_list_add_mb(to, strdup("FOO Bar"), strdup("foo@bar.org"); fields = mailimf_fields_new_with_data(from, NULL, NULL, to, NULL, NULL, NULL, NULL, strdup("hello")); /* do the things */ mailimf_fields_free(fields); }
#include <libetpan/libetpan.h> int mailimf_fields_write(FILE * f, int * col, struct mailimf_fields * fields); int mailimf_envelope_fields_write(FILE * f, int * col, struct mailimf_fields * fields); int mailimf_field_write(FILE * f, int * col, struct mailimf_field * field);
col current column is given for wrapping purpose in (* col), the resulting columns will be returned..
f is the file descriptor. It can be stdout for example.
fields is the header fields (see the Section called mailimf_fields - list of header fields).
field is a field (see the Section called mailimf_field - header field).
mailimf_fields_write outputs the set of header fields.
mailimf_envelope_fields_write outputs the set of header fields except the optional fields.
mailimf_field_write outputs a header.
Example 3-46. rendering of fields
int main(int argc, char ** argv) { struct mailimf_fields * fields; int col; /* look at the example in mailimf_fields to see how to build a mailimf_fields */ fields = build_imf_fields(); col = 0; mailimf_fields_write(stdout, &col, fields); mailimf_fields_free(fields); } int main(int argc, char ** argv) { struct mailimf_fields * fields; int col; /* look at the example in mailimf_fields to see how to build a mailimf_fields */ fields = build_imf_fields(); col = 0; mailimf_envelope_fields_write(stdout, &col, fields); mailimf_fields_free(fields); } int main(int argc, char ** argv) { struct mailimf_field * field; int col; field = mailimf_field_new_custom(strdup("X-Mailer"), strdup("my mailer")); col = 0; mailimf_field_write(stdout, &col, field); mailimf_field_free(field); }
libEtPan! implements a MIME message parser (also known as messages with attachments or multipart messages). This also allows to generate MIME messages.
| Warning |
All allocation functions will take as argument allocated data and will store these data in the structure they will allocate. Data should be persistant during all the use of the structure and will be freed by the free function of the structure allocation functions will return NULL on failure functions returning integer will be returning one of the following error code: MAILIMF_NO_ERROR, MAILIMF_ERROR_PARSE, MAILIMF_ERROR_MEMORY, MAILIMF_ERROR_INVAL, or MAILIMF_ERROR_FILE. |
You will need this module when you want to parse a MIME message.
Build your MIME message, then use mailmime_write (the Section called mailmime_write) to render a MIME message.
#include <libetpan/libetpan.h> enum { MAILMIME_COMPOSITE_TYPE_ERROR, MAILMIME_COMPOSITE_TYPE_MESSAGE, MAILMIME_COMPOSITE_TYPE_MULTIPART, MAILMIME_COMPOSITE_TYPE_EXTENSION }; struct mailmime_composite_type { int ct_type; char * ct_token; }; struct mailmime_composite_type * mailmime_composite_type_new(int ct_type, char * ct_token); void mailmime_composite_type_free(struct mailmime_composite_type * ct);
This is a MIME composite type such as message or multipart.
ct_type can have one of the 3 following values : MAILMIME_COMPOSITE_TYPE_MESSAGE when the composite MIME type is message, MAILMIME_COMPOSITE_TYPE_MULTIPART when the composite MIME type is multipart, MAILMIME_COMPOSITE_TYPE_EXTENSION for other and ct_token is set in this case. MAILMIME_COMPOSITE_TYPE_ERROR is used internally on parse error.
mailmime_composite_type_new() creates and initializes a data structure with a value. Structures given as argument are referenced by the created object and will be freed if the object is released.
mailmime_composite_type_free() frees memory used by the structure and substructures will also be released.
Example 4-1. create and display MIME composite type
#include <libetpan/libetpan.h> int main(void) { struct mailmime_composite_type * ct; ct = mailmime_composite_type_new(MAILMIME_COMPOSITE_TYPE_MULTIPART, NULL); /* do your things ... */ mailmime_composite_type_free(ct); exit(EXIT_SUCCESS); } void display_composite_type() { switch (ct->type) { case MAILMIME_COMPOSITE_TYPE_MESSAGE: printf("composite type is message\n"); break; case MAILMIME_COMPOSITE_TYPE_MULTIPART: printf("composite type is multipart\n"); break; case MAILMIME_COMPOSITE_TYPE_EXTENSION: printf("composite type: %s\n", ct->ct_token); break; } }
#include <libetpan/libetpan.h> struct mailmime_content { struct mailmime_type * ct_type; char * ct_subtype; clist * ct_parameters; /* elements are (struct mailmime_parameter *) */ }; struct mailmime_content * mailmime_content_new(struct mailmime_type * ct_type, char * ct_subtype, clist * ct_parameters); void mailmime_content_free(struct mailmime_content * content);
This is a MIME content type such as message/rfc822 or text/plain.
ct_type is the main MIME type, for example text in plain/text (see the Section called mailmime_type - MIME main type).
ct_subtype is the MIME subtype, for example plain in plain/text.
ct_parameters is the list of parameters for the given MIME type. For example, for plain/text, we can find charset=iso-8859-1, format=flowed. Each element of the list if of type struct mailmime_parameter * (see the Section called mailmime_parameter - MIME type parameter).
mailmime_content_new() creates and initializes a data structure with a value. Structures given as argument are referenced by the created object and will be freed if the object is released.
mailmime_content_free() frees memory used by the structure and substructures will also be released.
Example 4-2. Creation and display of MIME content type
#include <libetpan/libetpan.h> int main(void) { struct mailmime_content * content; struct mailmime_type * type; struct mailmime_discrete_type * dt; struct mailmime_parameter * param; clist * param_list; dt = mailmime_discrete_type_new(MAILMIME_DISCRETE_TYPE_TEXT, NULL); type = mailmime_type_new(MAILMIME_TYPE_DISCRETE_TYPE, dt, NUL); param_list = clist_new(); param = mailmime_parameter_new(strdup("charset"), strdup("iso-8859-1")); clist_append(param_list, param); content = mailmime_content_new(type, strdup("plain"), param_list); /* do your things */ exit(EXIT_SUCCESS); } void display_mime_content(struct mailmime_content * content_type) { clistiter * cur; printf("type:\n"); display_type(content_type->ct_type); printf("\n"); printf("subtype: %s\n", content_type->ct_subtype); printf("\n"); for(cur = clist_begin(content_type->ct_parameters) ; cur != NULL ; cur = clist_next(cur)) { struct mailmime_parameter * param; param = clist_content(cur); display_mime_parameter(param); printf("\n"); } printf("\n"); }
#include <libetpan/libetpan.h> enum { MAILMIME_DISCRETE_TYPE_ERROR, MAILMIME_DISCRETE_TYPE_TEXT, MAILMIME_DISCRETE_TYPE_IMAGE, MAILMIME_DISCRETE_TYPE_AUDIO, MAILMIME_DISCRETE_TYPE_VIDEO, MAILMIME_DISCRETE_TYPE_APPLICATION, MAILMIME_DISCRETE_TYPE_EXTENSION }; struct mailmime_discrete_type { int dt_type; char * dt_extension; }; struct mailmime_discrete_type * mailmime_discrete_type_new(int dt_type, char * dt_extension); void mailmime_discrete_type_free(struct mailmime_discrete_type * discrete_type);
This is a MIME discrete type such as text or image. This is also known as single part. This kind of part does not have any child.
dt_type is one of the given values : MAILMIME_DISCRETE_TYPE_TEXT if part is text, MAILMIME_DISCRETE_TYPE_IMAGE if part is an image, MAILMIME_DISCRETE_TYPE_AUDIO if part is audio data, MAILMIME_DISCRETE_TYPE_VIDEO if part is video, MAILMIME_DISCRETE_TYPE_APPLICATION if part is application data or MAILMIME_DISCRETE_TYPE_EXTENSION for other. In the case of MAILMIME_DISCRETE_TYPE_EXTENSION, dt_extension is filled in. MAILMIME_DISCRETE_TYPE_ERROR is used internally.
mailmime_discrete_type_new() creates and initializes a data structure with a value. Structures given as argument are referenced by the created object and will be freed if the object is released.
mailmime_discrete_type_free() frees memory used by the structure and substructures will also be released.
Example 4-3. Creation and display of MIME discrete type
#include <libetpan/libetpan.h> /* standard type */ int main(int argc, char ** argv) { struct mailmime_discrete_type * discrete_type; discrete_type = mailmime_discrete_type_new(MAILMIME_DISCRETE_TYPE_TEXT, NULL); /* do the things */ mailmime_discrete_type_free(discrete_type); } /* extension */ int main(int argc, char ** argv) { struct mailmime_discrete_type * discrete_type; discrete_type = mailmime_discrete_type_new(MAILMIME_DISCRETE_TYPE_EXTENSION, strdup("my-type")); /* do the things */ mailmime_discrete_type_free(discrete_type); } void display_mime_discrete_type(struct mailmime_discrete_type * discrete_type) { switch (discrete_type->dt_type) { case MAILMIME_DISCRETE_TYPE_TEXT: printf("text\n"); break; case MAILMIME_DISCRETE_TYPE_IMAGE: printf("image\n"); break; case MAILMIME_DISCRETE_TYPE_AUDIO: printf("audio\n"); break; case MAILMIME_DISCRETE_TYPE_VIDEO: printf("video\n"); break; case MAILMIME_DISCRETE_TYPE_APPLICATION: printf("application\n"); break; case MAILMIME_DISCRETE_TYPE_EXTENSION: printf("extension : %s\n", discrete_type->dt_extension); break; } }
#include <libetpan/libetpan.h> enum { MAILMIME_FIELD_NONE, MAILMIME_FIELD_TYPE, MAILMIME_FIELD_TRANSFER_ENCODING, MAILMIME_FIELD_ID, MAILMIME_FIELD_DESCRIPTION, MAILMIME_FIELD_VERSION, MAILMIME_FIELD_DISPOSITION, MAILMIME_FIELD_LANGUAGE, }; struct mailmime_field { int fld_type; union { struct mailmime_content * fld_content; struct mailmime_mechanism * fld_encoding; char * fld_id; char * fld_description; uint32_t fld_version; struct mailmime_disposition * fld_disposition; struct mailmime_language * fld_language; } fld_data; }; struct mailmime_field * mailmime_field_new(int fld_type, struct mailmime_content * fld_content, struct mailmime_mechanism * fld_encoding, char * fld_id, char * fld_description, uint32_t fld_version, struct mailmime_disposition * fld_disposition, struct mailmime_language * fld_language); void mailmime_field_free(struct mailmime_field * field);
This is a parsed MIME header field;
fld_type is the type of MIME header field. The value can be MAILMIME_FIELD_TYPE if field is Content-Type, MAILMIME_FIELD_TRANSFER_ENCODING if field is Content-Transfer-Encoding, MAILMIME_FIELD_ID if field is Content-ID, MAILMIME_FIELD_DESCRIPTION if field is Content-Description, MAILMIME_FIELD_VERSION if field is MIME-Version, MAILMIME_FIELD_DISPOSITION if field is Content-Disposition or MAILMIME_FIELD_LANGUAGE if field is Content-Language. MAILMIME_FIELD_NONE is used internally.
fld_data.fld_content is set in case of Content-Type. (see the Section called mailmime_content - MIME content type (Content-Type)).
fld_data.fld_encoding is set in case of Content-Transfer-Encoding. (see the Section called mailmime_mechanism - MIME transfer encoding mechanism (Content-Transfer-Encoding)).
fld_data.fld_id is set in case of Content-ID. This is a string.
fld_data.fld_description is set in case of Content-Description. This is a string.
fld_data.fld_version is set in case of MIME-Version. This is an integer built using the following formula : fld_version = major * 2^16 + minor. Currenly MIME-Version is always 1.0, this means that fld_version will always be 2^16 (in C language, this is 1 << 16).
fld_data.fld_disposition is set in case of Content-Disposition. (see the Section called mailmime_disposition - MIME disposition information (Content-Disposition)).
fld_data.fld_language is set in case of Content-Language. (see the Section called mailmime_language - Language of MIME part).
mailmime_field_new() creates and initializes a data structure with a value. Structures given as argument are referenced by the created object and will be freed if the object is released.
mailmime_field_free() frees memory used by the structure and substructures will also be released.
Example 4-4. Creation and display of MIME header field
#include <libetpan/libetpan.h> int main(int argc, char ** argv) { struct mailmime_field * field; struct mailmime_mechanism * encoding; encoding = mailmime_mechanism_new(MAILMIME_MECHANISM_BASE64, NULL); field = mailmime_field_new(MAILMIME_FIELD_TRANSFER_ENCODING, NULL, encoding, NULL, NULL, 0, NULL, NULL); /* do the things */ mailmime_field_free(field); } void display_mime_field(struct mailmime_field * field) { switch (field->fld_type) { case MAILMIME_FIELD_TYPE: printf("content-type:"); display_mime_content(field->fld_data.fld_content); break; case MAILMIME_FIELD_TRANSFER_ENCODING: printf("content-transfer-encoding:"); display_mime_mechanism(field->fld_data.fld_encoding); break; case MAILMIME_FIELD_ID: printf("content-id: %s\n", field->fld_data.fld_id); break; case MAILMIME_FIELD_DESCRIPTION: printf("content-description: %s\n", field->fld_data.fld_description); break; case MAILMIME_FIELD_VERSION: printf("mime-version: %i.%i\n", field->version>> 16, field->fld_data.fld_version & 0xFFFF); break; case MAILMIME_FIELD_DISPOSITION: printf("content-disposition:"); display_mime_disposition(field->fld_data.fld_disposition); break; case MAILMIME_FIELD_LANGUAGE: printf("content-language:"); display_mime_language(field->fld_data.fld_language); break; } }
#include <libetpan/libetpan.h> enum { MAILMIME_MECHANISM_ERROR, MAILMIME_MECHANISM_7BIT, MAILMIME_MECHANISM_8BIT, MAILMIME_MECHANISM_BINARY, MAILMIME_MECHANISM_QUOTED_PRINTABLE, MAILMIME_MECHANISM_BASE64, MAILMIME_MECHANISM_TOKEN }; struct mailmime_mechanism { int enc_type; char * enc_token; }; struct mailmime_mechanism * mailmime_mechanism_new(int enc_type, char * enc_token); void mailmime_mechanism_free(struct mailmime_mechanism * mechanism);
This is a MIME transfer encoding mechanism description.
enc_type is an encoding type. The value of this field can be MAILMIME_MECHANISM_7BIT if mechanism is 7bit, MAILMIME_MECHANISM_8BIT if mechanism is 8bit, MAILMIME_MECHANISM_BINARY if mechanism is binary, MAILMIME_MECHANISM_QUOTED_PRINTABLE if mechanism is quoted-printable, MAILMIME_MECHANISM_BASE64 if mechanism is base64 or MAILMIME_MECHANISM_TOKEN for other. In case of MAILMIME_MECHANISM_TOKEN, field enc_token is filled in. MAILMIME_MECHANISM_ERROR is used internally.
mailmime_mechanism_new() creates and initializes a data structure with a value. Structures given as argument are referenced by the created object and will be freed if the object is released.
mailmime_mechanism_free() frees memory used by the structure and substructures will also be released.
Example 4-5. Creation and display of MIME transfer encoding mechanism
#include <libetpan/libetpan.h> int main(int argc, char ** argv) { struct mailmime_mechanism * encoding; encoding = mailmime_mechanism_new(MAILMIME_MECHANISM_QUOTED_PRINTABLE, NULL); /* do the things */ mailmime_mechanism_free(encoding); } int main(int argc, char ** argv) { struct mailmime_mechanism * encoding; encoding = mailmime_mechanism_new(MAILMIME_MECHANISM_TOKEN, strdup("uuencoding")); /* do the things */ mailmime_mechanism_free(encoding); } void display_mime_mechanism(struct mailmime_mechanism * encoding) { switch (encoding->enc_type) { case MAILMIME_MECHANISM_7BIT: printf("7bit\n"); break; case MAILMIME_MECHANISM_8BIT: printf("8bit\n"); break; case MAILMIME_MECHANISM_BINARY: printf("binary\n"); break; case MAILMIME_MECHANISM_QUOTED_PRINTABLE: printf("quoted-printable\n"); break; case MAILMIME_MECHANISM_BASE64: printf("base64\n"); break; case MAILMIME_MECHANISM_TOKEN: printf("extension : %s\n", encoding->enc_token); break; } }
#include <libetpan/libetpan.h> struct mailmime_fields { clist * fld_list; /* list of (struct mailmime_field *) */ }; struct mailmime_fields * mailmime_fields_new(clist * fld_list); void mailmime_fields_free(struct mailmime_fields * fields);
This is the header fields of a MIME part.
fld_list is the list of the header fields. Each element of the list is a mailmime_field (See the Section called mailmime_field - MIME header field).
mailmime_fields_new() creates and initializes a data structure with a value. Structures given as argument are referenced by the created object and will be freed if the object is released.
mailmime_fields_free() frees memory used by the structure and substructures will also be released.
Example 4-6. Creation and display of MIME fields
#include <libetpan/libetpan.h> int main(int argc, char ** argv) { struct mailmime_field * field; struct mailmime_fields * fields; clist * list; struct mailmime_mechanism * encoding; struct mailmime_disposition * disposition; list = clist_new(); encoding = mailmime_mechanism_new(MAILMIME_MECHANISM_BASE64, NULL); field = mailmime_field_new(MAILMIME_FIELD_TRANSFER_ENCODING, NULL, encoding, NULL, NULL, 0, NULL, NULL); clist_append(list, field); field = mailmime_field_new(MAILMIME_FIELD_VERSION, NULL, NULL, NULL, NULL, 1 << 16, NULL, NULL); clist_append(list, field); /* look at the example in mailmime_disposition to see how to build a mailmime_disposition */ disposition = build_mime_disposition(); field = mailmime_field_new(MAILMIME_FIELD_DISPOSITION, NULL, NULL, NULL, NULL, 0, disposition, NULL); clist_append(list, field); fields = mailmime_fields_new(list); /* do the things */ mailmime_fields_free(fields); } void display_mime_fields(struct mailmime_fields * fields) { clistiter * cur; for(cur = clist_begin(fields->fld_list ; cur != NULL ; cur = clist_next(cur)) { struct mailmime_field * field; field = clist_content(cur); display_field(field); } }
struct mailmime_parameter { char * pa_name; char * pa_value; };
This is the MIME type parameter in Content-Type MIME header field. For example, this can be charset="iso-8859-1".
pa_name is the name of the parameter, for example : charset.
pa_value is the value of the parameter, for example : iso-8859-1.
mailmime_parameter_new() creates and initializes a data structure with a value. Structures given as argument are referenced by the created object and will be freed if the object is released.
mailmime_parameter_free() frees memory used by the structure and substructures will also be released.
Example 4-7. Creation and display of MIME type parameter
#include <libetpan/libetpan.h> int main(int argc, char ** argv) { struct mailmime_parameter * param; param = mailmime_parameter_new(strdup("charset"), strdup("iso-8859-1")); /* do the things */ mailmime_parameter_free(param); } void display_mime_parameter(struct mailmime_parameter * param) { printf("%s = %s\n", param->pa_name, param->pa_value); }
#include <libetpan/libetpan.h> enum { MAILMIME_TYPE_ERROR, MAILMIME_TYPE_DISCRETE_TYPE, MAILMIME_TYPE_COMPOSITE_TYPE }; struct mailmime_type { int tp_type; union { struct mailmime_discrete_type * tp_discrete_type; struct mailmime_composite_type * tp_composite_type; } tp_data; }; struct mailmime_type * mailmime_type_new(int tp_type, struct mailmime_discrete_type * tp_discrete_type, struct mailmime_composite_type * tp_composite_type); void mailmime_type_free(struct mailmime_type * type);
This is the MIME main type (no subtype, no parameter).
tp_type. The value of this field is either MAILMIME_TYPE_DISCRETE_TYPE for MIME discrete type, or MAILMIME_TYPE_COMPOSITE_TYPE for MIME composite type. MAILMIME_TYPE_ERROR is used internally.
tp_data.tp_discrete_type is set when tp_type is MAILMIME_TYPE_DISCRETE_TYPE (see the Section called mailmime_discrete_type - MIME discrete type).
tp_data.tp_composite_type is set when tp_type is MAILMIME_TYPE_COMPOSITE_TYPE (see the Section called mailmime_composite_type - Composite MIME type).
mailmime_discrete_type_new() creates and initializes a data structure with a value. Structures given as argument are referenced by the created object and will be freed if the object is released.
mailmime_discrete_type_free() frees memory used by the structure and substructures will also be released.
Example 4-8. Creation and display of MIME main type
#include <libetpan/libetpan.h> int main(int argc, char ** argv) { struct mailmime_type * type; struct mailmime_discrete_type * discrete_type; discrete_type = mailmime_discrete_type_new(MAILMIME_DISCRETE_TYPE_TEXT, NULL); type = mailmime_type_new(MAILMIME_TYPE_DISCRETE_TYPE, discrete_type, NULL); /* do the things */ mailmime_type_free(type); } int main(int argc, char ** argv) { struct mailmime_type * type; struct mailmime_composite_type * composite_type; composite_type = mailmime_composite_type_new(MAILMIME_COMPOSITE_TYPE_MULTIPART, NULL); type = mailmime_type_new(MAILMIME_TYPE_COMPOSITE_TYPE, NULL, composite_type); /* do the things */ mailmime_type_free(type); } void display_mime_type(struct mailmime_type * type) { printf("mime type:\n"); switch (type->tp_type) { case MAILMIME_TYPE_DISCRETE_TYPE: printf("discrete type:\n"); display_mime_discrete_type(type->tp_data.tp_discrete_type); break; case MAILMIME_TYPE_COMPOSITE_TYPE: printf("composite type:\n"); display_mime_composite_type(type->tp_data.tp_composite_type); break; } printf("\n"); }
#include <libetpan/libetpan.h> struct mailmime_language { clist * lg_list; /* atom (char *) */ }; struct mailmime_language * mailmime_language_new(clist * lg_list); void mailmime_language_free(struct mailmime_language * lang);
This is the language used in the MIME part.
lg_list is the list of codes of languages used in the MIME part. This is a list of strings.