- Created session::login() members.
- test applications use default profile.
*/
#include <libmapi++/message_store.h>
+#include <libmapi++/profile.h>
namespace libmapipp {
return retval;
}
-session::session(const std::string& profile_name, const std::string& profiledb, const std::string& password, bool debug)
-throw(std::runtime_error, mapi_exception) : m_session(NULL), m_memory_ctx(talloc_init("libmapi++")), m_message_store(new message_store(*this))
+session::session(const std::string& profiledb, bool debug)throw(std::runtime_error, mapi_exception)
+: m_session(NULL), m_memory_ctx(talloc_init("libmapi++")), m_message_store(new message_store(*this))
{
mapi_exception::fill_status_map();
delete m_message_store;
throw std::runtime_error("libmapipp::session(): Failed to get $HOME env variable");
}
- }
- else {
+ } else {
profile_path = profiledb;
}
}
if (debug) global_mapi_ctx->dumpdata = true;
+}
- if (MapiLogonEx(&m_session, profile_name.c_str(), (password != "") ? password.c_str() : 0 ) != MAPI_E_SUCCESS) {
+void session::login(const std::string& profile_name, const std::string& password) throw (mapi_exception)
+{
+ m_profile_name = profile_name;
+ if (m_profile_name == "") { // if profile is not set, try to get default profile
+ try {
+ m_profile_name = profile::get_default_profile();
+ } catch(mapi_exception e) {
+ uninitialize();
+ throw;
+ }
+ }
+
+ if (MapiLogonEx(&m_session, m_profile_name.c_str(), (password != "") ? password.c_str() : 0 ) != MAPI_E_SUCCESS) {
uninitialize();
throw mapi_exception(GetLastError(), "session::session : MapiLogonEx");
}
try {
m_message_store->open();
- }
- catch (mapi_exception e) {
+ } catch (mapi_exception e) {
throw;
}
}
libmapi C++ Wrapper
MAPI Exception Class
- Copyright (C) Alan Alvarez 2007.
+ Copyright (C) Alan Alvarez 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
#include <libmapi++/message.h>
#include <libmapi++/attachment.h>
#include <libmapi++/property_container.h>
+#include <libmapi++/profile.h>
#endif /* ! __LIBMAPIPP_H */
bool static set_default(const char* profname)
{
- return (setDefaultProfile(profname) == MAPI_E_SUCCESS);
+ return (SetDefaultProfile(profname) == MAPI_E_SUCCESS);
}
bool static set_default(const std::string& profname)
return set_default(profname.c_str());
}
+ std::string static get_default_profile() throw (mapi_exception)
+ {
+ const char* profname = NULL;
+ if (GetDefaultProfile(&profname) != MAPI_E_SUCCESS)
+ throw mapi_exception(GetLastError(), "profile::get_default_profile : GetDefaultProfile()");
+
+ return std::string(profname);
+ }
+
~profile()
{
if (m_profile)
public:
/**
* \brief Constructor
- * \param profile_name The name of the profile
* \param profiledb An absolute path specifying where the profile database is.\n
* If none or "" is specified the default location will be used (~/.openchange.profiles.ldb).
+ *
+ * \param debug Whether to output debug information to stdout
+ */
+ session(const std::string& profiledb = "", const bool debug = false) throw(std::runtime_error, mapi_exception);
+ /**
+ * \brief Log-in to the Exchange Server
+ * \param profile_name The name of the profile, if left blank the default profile will be used.
* \param password The password to use to login with.\n
- * It is possible to omit this if the password is stored in the profile.
- *
- * \param debug Whether to output debug information to stdout
+ * It is possible to omit this if the password is stored in the profile database.
*/
- session(const std::string& profile_name, const std::string& profiledb = "", const std::string& password = "", bool debug = false)
- throw(std::runtime_error, mapi_exception);
+ void login(const std::string& profile_name = "", const std::string& password = "") throw(mapi_exception);
static std::string get_default_profile_path();
+ std::string get_profile_name() const { return m_profile_name; }
+
/** \brief Returns a reference to the message_store associated with this session
* \return The message_store associated with this session.
*/
mapi_session *m_session;
TALLOC_CTX *m_memory_ctx;
message_store *m_message_store;
+ std::string m_profile_name;
void uninitialize() throw();
};
int main()
{
try {
- session mapi_session("FIXME");
+ session mapi_session;
+
+ mapi_session.login();
// Get Default Top Information Store folder ID
mapi_id_t top_folder_id = mapi_session.get_message_store().get_default_folder(olFolderTopInformationStore);
{
try {
// Initialize MAPI Session
- session mapi_session("FIXME");
+ session mapi_session;
+
+ mapi_session.login();
property_container store_properties = mapi_session.get_message_store().get_property_container();
store_properties << PR_DISPLAY_NAME;
return (const void *)(struct SBinary_short *)&lpProp->value.bin;
case PT_MV_STRING8:
return (const void *)(struct mapi_SLPSTRArray *)&lpProp->value.MVszA;
+ case PT_MV_BINARY:
+ return (const void *)(struct mapi_SBinaryArray *)&lpProp->value.MVbin;
default:
return NULL;
}