An example that shows reading of attachments.
#include <iostream>
using namespace std;
using namespace libmapipp;
static uint32_t get_attachment_count(
message& mapi_message)
{
return attachment_container.size();
}
static void print_messages_with_attachments(
folder& up_folder)
{
for (folder::message_container_type::iterator Iter = messages.begin(); Iter != messages.end(); ++Iter) {
uint32_t attachment_count = get_attachment_count(*(*Iter));
if (attachment_count) {
cout << "Message (" << (*Iter)->get_id() << ") has " << attachment_count << " attachments." << endl;
}
}
}
static void print_folder_tree(
folder& up_folder,
session& mapi_session,
unsigned int deep = 0)
{
up_folder_property_container << PR_DISPLAY_NAME << PR_CONTENT_COUNT;
up_folder_property_container.
fetch();
string display_name = static_cast<const char*>(up_folder_property_container[PR_DISPLAY_NAME]);
const uint32_t message_count = *(static_cast<const uint32_t*>(up_folder_property_container[PR_CONTENT_COUNT]));
for (unsigned int i = 0; i < deep; ++i) {
cout << "|----> ";
}
cout << display_name <<
" (id: " << up_folder.
get_id() <<
") (messages: " << message_count <<
")" << endl;
print_messages_with_attachments(up_folder);
for (unsigned int i = 0; i < hierarchy.size(); ++i) {
print_folder_tree(*hierarchy[i], mapi_session, deep+1);
}
}
int main()
{
try {
print_folder_tree(top_folder, mapi_session);
}
{
cout <<
"MAPI Exception @ main: " << e.
what() << endl;
}
catch (std::runtime_error e)
{
cout << "std::runtime_error exception @ main: " << e.what() << endl;
}
return 0;
}