foldertree.cpp

This example lists the top level folders in the message store, with output like:

Message store display name: Mailbox - Test User1
|-----> Calendar (0 items, 0 unread)
|-----> Contacts (0 items, 0 unread)
|-----> Deleted Items (0 items, 0 unread)
|-----> Drafts (0 items, 0 unread)
|-----> Inbox (26 items, 24 unread)
|-----> Journal (0 items, 0 unread)
|-----> Notes (0 items, 0 unread)
|-----> Outbox (9 items, 0 unread)
|-----> Sent Items (0 items, 0 unread)
|-----> Tasks (0 items, 0 unread)

The example shows how to create a session, get the message_store, get properties of the message store, and then gets the list of child folders and some associated folder properties.

/*
libmapi C++ Wrapper
Sample folder tree list application
Copyright (C) Brad Hards <bradh@frogmouth.net> 2008.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <exception>
#include <string>
int main ()
{
try {
// Initialize MAPI Session
libmapipp::session mapi_session;
// You could log in with a non-default profile here
mapi_session.login();
// Get the private (user) folders message store
libmapipp::message_store &msg_store = mapi_session.get_message_store();
// Get a property of the top level message store
msg_store_props << PR_DISPLAY_NAME; // you could use other properties here
msg_store_props.fetch();
// Display the property. You can also use a property_container_iterator
// to work through the properties, but in this case there is only one.
std::cout << "Message store display name: "
<< (const char*)msg_store_props[PR_DISPLAY_NAME]
<< std::endl;
// Fetch the folder list.
// We start off by fetching the top level folder
mapi_id_t top_folder_id = msg_store.get_default_folder(olFolderTopInformationStore);
libmapipp::folder top_folder(msg_store, top_folder_id);
// Now get the child folders of the top level folder. These are returned as
// a std::vector of pointers to folders
// Display the name, total item count and unread item count for each folder
for (unsigned int i = 0; i < child_folders.size(); ++i) {
libmapipp::property_container child_props = child_folders[i]->get_property_container();
child_props << PR_DISPLAY_NAME << PR_CONTENT_COUNT << PR_CONTENT_UNREAD;
child_props.fetch();
std::cout << "|-----> " << (const char*)child_props[PR_DISPLAY_NAME]
<< " (" << (*(int*)child_props[PR_CONTENT_COUNT]) << " items, "
<< (*(int*)child_props[PR_CONTENT_UNREAD]) << " unread)"
<< std::endl;
}
}
catch (libmapipp::mapi_exception &e) // Catch any MAPI exceptions
{
std::cout << "MAPI Exception in main: " << e.what()
<< std::endl;
}
catch (std::runtime_error &e) // Catch any other runtime exceptions
{
std::cout << "std::runtime_error exception in main: "
<< e.what() << std::endl;
}
return 0;
}
virtual property_container get_property_container()
Obtain a property_container to be used with this object.
Definition: mapi_exception.h:38
virtual const char * what() const
Definition: mapi_exception.h:48
hierarchy_container_type fetch_hierarchy()
Fetch all subfolders within this folder.
This class represents a MAPI session with the Exchange Server.
Definition: session.h:62
std::vector< folder_shared_ptr > hierarchy_container_type
Hierarchy folders.
Definition: folder.h:58
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
message_store & get_message_store()
Obtain a reference to the message_store associated with this session.
Definition: session.h:100
This class represents the Message Store in Exchange.
Definition: message_store.h:46
void login(const std::string &profile_name="", const std::string &password="")
Log-in to the Exchange Server.
uint32_t fetch()
Fetches properties with the tags supplied using operator<<.
Definition: property_container.h:178
This class represents a folder or container within Exchange.
Definition: folder.h:39
A container of properties to be used with classes derived from object.
Definition: property_container.h:159

Creative Commons License
Creative Commons Attribution icon Creative Commons Share Alike icon
This content is licensed under the Creative Commons
Attribution ShareAlike License v. 3.0:
http://creativecommons.org/licenses/by-sa/3.0/