An example that shows reading mail.
An example that shows reading mail.
#include <exception>
#include <vector>
#include <string>
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;
}
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
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
iterator end() const
Definition property_container.h:253
void fetch_all()
Fetches ALL properties of the object associated with this container.
Definition property_container.h:191
iterator begin() const
Definition property_container.h:243
property_container_iterator iterator
Definition property_container.h:162
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