An example that shows reading mail.
#include <exception>
#include <vector>
#include <string>
using namespace libmapipp;
using std::string;
static unsigned int get_message_count(
folder& the_folder,
session& mapi_session)
{
return messages.size();
}
static void print_folder_tree(
folder& up_folder,
session& mapi_session,
unsigned int deep = 0)
{
up_folder_property_container << PR_DISPLAY_NAME << PR_CONTAINER_CLASS;
up_folder_property_container.
fetch();
string display_name = static_cast<const char*>(up_folder_property_container[PR_DISPLAY_NAME]);
string container_class;
if (up_folder_property_container[PR_CONTAINER_CLASS])
container_class = static_cast<const char*>(up_folder_property_container[PR_CONTAINER_CLASS]);
for (unsigned int i = 0; i < deep; ++i) {
cout << "|----> ";
}
cout << display_name <<
" (id: " << up_folder.
get_id() <<
") (messages: " << get_message_count(up_folder, mapi_session) <<
")"
<< " container class: " << container_class << endl;
for (unsigned int i = 0; i < hierarchy.size(); ++i) {
print_folder_tree(*hierarchy[i], mapi_session, deep+1);
}
}
int main ()
{
try {
store_properties << PR_DISPLAY_NAME;
store_properties.
fetch();
cout <<
"Mailbox Name: " <<
static_cast<const char*
>(*store_properties.
begin()) << endl;
cout << "inbox_id: " << inbox_id << endl;
cout << "Inbox size: " << messages.size() << endl;
if (messages.size() > 0) {
message_property_container << PR_DISPLAY_TO << PR_CONVERSATION_TOPIC;
string to;
string subject;
{
if (Iter.get_tag() == PR_DISPLAY_TO)
to = (const char*) *Iter;
else if (Iter.get_tag() == PR_CONVERSATION_TOPIC)
subject = (const char*) *Iter;
}
cout << "To: " << to << endl;
cout << "Subject: " << subject << endl;
}
print_folder_tree(top_folder, mapi_session);
cout << "finished session" << endl;
}
{
cout <<
"MAPI Exception @ main: " << e.
what() << endl;
}
catch (std::runtime_error e)
{
cout << "std::runtime_error exception @ main: " << e.what() << endl;
}
return 0;
}