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); }