An example that shows reading of attachments.
An example that shows reading of attachments.
#include <iostream>
using namespace std;
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;
}
This class represents a folder or container within Exchange.
Definition folder.h:39
message_container_type fetch_messages()
Fetch all messages in this folder.
std::vector< message_shared_ptr > message_container_type
Definition folder.h:46
hierarchy_container_type fetch_hierarchy()
Fetch all subfolders within this folder.
std::vector< folder_shared_ptr > hierarchy_container_type
Hierarchy folders.
Definition folder.h:58
mapi_id_t get_id() const
Obtain folder id.
Definition folder.h:78
Definition mapi_exception.h:38
virtual const char * what() const
Definition mapi_exception.h:48
mapi_id_t get_default_folder(const uint32_t id) const
Retrieves the folder id for the specified default folder in the Message Store.
Definition message_store.h:72
This class represents a message in Exchange.
Definition message.h:45
attachment_container_type fetch_attachments()
Fetches all attachments in this message.
std::vector< attachment_shared_ptr > attachment_container_type
Definition message.h:48
virtual property_container get_property_container()
Obtain a property_container to be used with this object.
A container of properties to be used with classes derived from object.
Definition property_container.h:159
uint32_t fetch()
Fetches properties with the tags supplied using operator<<.
Definition property_container.h:178
This class represents a MAPI session with the Exchange Server.
Definition session.h:62
message_store & get_message_store()
Obtain a reference to the message_store associated with this session.
Definition session.h:100
void login(const std::string &profile_name="", const std::string &password="")
Log-in to the Exchange Server.
The libmapi++ classes and other definitions are all enclosed in the libmapipp namespace.
Definition attachment.h:32