Add new example showing libmapi++ message handling, and
authorBrad Hards <bradh@openchange.org>
Mon, 22 Sep 2008 09:58:21 +0000 (09:58 +0000)
committerBrad Hards <bradh@openchange.org>
Mon, 22 Sep 2008 09:58:21 +0000 (09:58 +0000)
associated API documentation and build system changes.

Makefile
libmapi++/examples/messages.cpp [new file with mode: 0644]
libmapi++/libmapi++-example.doxy

index dc820f0122db3b03d911db9f8aaace5efe95d949..c22f87f26e9418f946736700807c36e2ec450fba 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -410,12 +410,17 @@ bin/libmapixx-attach: libmapi++/tests/attach_test.cpp     \
 clean:: libmapixx-attach-clean
 
 
-libmapixx-examples: libmapi++/examples/foldertree
+libmapixx-examples: libmapi++/examples/foldertree \
+                 libmapi++/examples/messages
 
 libmapixx-foldertree-clean:
        rm -f libmapi++/examples/foldertree
        rm -f libmapi++/examples/*.o
 
+libmapixx-messages-clean:
+       rm -f libmapi++/examples/messages
+       rm -f libmapi++/examples/*.o
+
 libmapi++/examples/foldertree: libmapi++/examples/foldertree.cpp       \
                  libmapi.$(SHLIBEXT).$(PACKAGE_VERSION)
        @echo "Linking foldertree example application $@"
@@ -423,6 +428,12 @@ libmapi++/examples/foldertree: libmapi++/examples/foldertree.cpp   \
 
 clean:: libmapixx-foldertree-clean
 
+libmapi++/examples/messages: libmapi++/examples/messages.cpp   \
+                 libmapi.$(SHLIBEXT).$(PACKAGE_VERSION)
+       @echo "Linking messages example application $@"
+       @$(CXX) $(CXXFLAGS) -o $@ $^ $(LIBS)
+
+clean:: libmapixx-messages-clean
 
 #################################################################
 # libmapiadmin compilation rules
diff --git a/libmapi++/examples/messages.cpp b/libmapi++/examples/messages.cpp
new file mode 100644 (file)
index 0000000..e44c536
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+   libmapi C++ Wrapper
+
+   Sample folder message 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>
+
+#include <libmapi++/libmapi++.h>
+
+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();
+
+               // We start off by fetching the inbox
+               mapi_id_t top_folder_id = msg_store.get_default_folder(olFolderInbox);
+               libmapipp::folder top_folder(msg_store, top_folder_id);
+               // Now get the messages in this folder These are returned as
+               // a std::vector of pointers to messages
+               libmapipp::folder::message_container_type messages = top_folder.fetch_messages();
+               std::cout << "Inbox contains " << messages.size() << " messages" << std::endl;
+
+               // Work through each message
+               for (unsigned int i = 0; i < messages.size(); ++i) {
+                       // Get the properties we are interested in
+                       libmapipp::property_container msg_props = messages[i]->get_property_container();
+                       // We get the "to" addressee, and the subject
+                       // You can get a lot of other properties here (e.g. sender, body, etc).
+                       msg_props << PR_DISPLAY_TO << PR_CONVERSATION_TOPIC;
+                       msg_props.fetch();
+                       // Display those properties
+                       std::cout << "|-----> " << (const char*)msg_props[PR_DISPLAY_TO]
+                                 << "\t\t| " << (const char*)msg_props[PR_CONVERSATION_TOPIC]
+                                 << 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;
+}
index a98cd448fceac69f001ced43c419d2144af044c9..ac9c59a993db158d0f9299f8ea7323c082138faf 100644 (file)
@@ -32,4 +32,20 @@ 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.
 
-*/
\ No newline at end of file
+*/
+
+/** \example messages.cpp
+
+This example displays information about the messages in the inbox, with
+output like:
+\code
+Inbox contains 2 messages
+|-----> Test User1              | Working Remotely with Windows Small Business Server
+|-----> Test User1              | Welcome to Windows Small Business Server 2003
+\endcode
+
+The example shows how to create a session, get the message_store, and open 
+the inbox folder. It then determines how many messages are in the inbox folder,
+and retrieves and prints the intended addressee and the message subject.
+
+*/