/** * Retrieve server specific information */ static bool mapitest_get_server_info(struct mapitest *mt, char *opt_profname, const char *password, bool opt_dumpdata, const char *opt_debug) { TALLOC_CTX *mem_ctx; enum MAPISTATUS retval; struct emsmdb_info *info = NULL; struct mapi_session *session = NULL; /* if the user explicitly asked for just the no-server tests to be run, then we're done here */ if (mt->no_server == true) return 0; mem_ctx = talloc_named(NULL, 0, "mapitest_get_server_info"); /* if no profile was specified, get the default */ if (!opt_profname) { retval = GetDefaultProfile(mt->mapi_ctx, &opt_profname); if (retval != MAPI_E_SUCCESS) { mapi_errstr("GetDefaultProfile", retval); talloc_free(mem_ctx); return false; } } /* debug options */ SetMAPIDumpData(mt->mapi_ctx, opt_dumpdata); if (opt_debug) { SetMAPIDebugLevel(mt->mapi_ctx, atoi(opt_debug)); } retval = MapiLogonEx(mt->mapi_ctx, &session, opt_profname, password); MAPIFreeBuffer(opt_profname); talloc_free(mem_ctx); if (retval != MAPI_E_SUCCESS) { mapi_errstr("MapiLogonEx", retval); return false; } mt->session = session; mt->profile = session->profile; info = emsmdb_get_info(session); memcpy(&mt->info, info, sizeof (struct emsmdb_info)); /* extract org and org_unit from info.mailbox */ mt->org = x500_get_dn_element(mt->mem_ctx, info->szDNPrefix, "/o="); mt->org_unit = x500_get_dn_element(mt->mem_ctx, info->szDNPrefix, "/ou="); return true; }
int main(int argc, char *argv[]) { enum MAPISTATUS retval; struct mapi_context *mapi_ctx; TALLOC_CTX *mem_ctx; struct mapi_session *session = NULL; mapi_object_t obj_store; mapi_object_t obj_folder; mapi_object_t obj_table; mapi_object_t obj_message; struct mapi_SPropValue_array props_all; struct SRowSet rowset; struct SPropTagArray *SPropTagArray; mapi_id_t id_inbox; mapi_id_t *fid, *mid; char *profname; char *profdb; uint32_t Numerator; uint32_t Denominator; uint32_t i; mem_ctx = talloc_named(NULL, 0, "fetchmail"); /* Initialize MAPI */ profdb = talloc_asprintf(mem_ctx, DEFAULT_PROFDB, getenv("HOME")); retval = MAPIInitialize(&mapi_ctx, profdb); MAPI_RETVAL_IF(retval, retval, mem_ctx); /* Find Default Profile */ retval = GetDefaultProfile(mapi_ctx, &profname); MAPI_RETVAL_IF(retval, retval, mem_ctx); /* Log on EMSMDB and NSPI */ retval = MapiLogonEx(mapi_ctx, &session, profname, NULL); MAPI_RETVAL_IF(retval, retval, mem_ctx); /* Open Message Store */ mapi_object_init(&obj_store); retval = OpenMsgStore(session, &obj_store); MAPI_RETVAL_IF(retval, retval, mem_ctx); /* Find Inbox default folder */ retval = GetDefaultFolder(&obj_store, &id_inbox, olFolderInbox); MAPI_RETVAL_IF(retval, retval, mem_ctx); /* Open Inbox folder */ mapi_object_init(&obj_folder); retval = OpenFolder(&obj_store, id_inbox, &obj_folder); MAPI_RETVAL_IF(retval, retval, mem_ctx); /* Retrieve Inbox content table */ mapi_object_init(&obj_table); retval = GetContentsTable(&obj_folder, &obj_table, 0x0, NULL); MAPI_RETVAL_IF(retval, retval, mem_ctx); /* Create the MAPI table view */ SPropTagArray = set_SPropTagArray(mem_ctx, 0x2, PR_FID, PR_MID); retval = SetColumns(&obj_table, SPropTagArray); MAPIFreeBuffer(SPropTagArray); MAPI_RETVAL_IF(retval, retval, mem_ctx); talloc_free(mem_ctx); /* Get current cursor position */ retval = QueryPosition(&obj_table, &Numerator, &Denominator); MAPI_RETVAL_IF(retval, retval, mem_ctx); /* Iterate through rows */ while ((retval = QueryRows(&obj_table, Denominator, TBL_ADVANCE, &rowset)) != -1 && rowset.cRows) { for (i = 0; i < rowset.cRows; i++) { fid = (mapi_id_t *)find_SPropValue_data(&(rowset.aRow[i]), PR_FID); mid = (mapi_id_t *)find_SPropValue_data(&(rowset.aRow[i]), PR_MID); mapi_object_init(&obj_message); retval = OpenMessage(&obj_store, *fid, *mid, &obj_message, 0x0); if (retval != MAPI_E_NOT_FOUND) { retval = GetPropsAll(&obj_message, MAPI_UNICODE, &props_all); mapidump_message(&props_all, NULL, &obj_message); mapi_object_release(&obj_message); } } } /* Release MAPI objects */ mapi_object_release(&obj_table); mapi_object_release(&obj_folder); Logoff(&obj_store); /* Uninitialize MAPI */ MAPIUninitialize(mapi_ctx); return (0); }
bool MapiConnector2::login(QString profile) { if (!init()) { return false; } if (m_session) { // already logged in... return true; } if (profile.isEmpty()) { // use the default profile if none was specified by the caller profile = defaultGet(); if (profile.isEmpty()) { // there seams to be no default profile error() << "no default profile"; return false; } } // Log on if (MAPI_E_SUCCESS != MapiLogonEx(m_context, &m_session, profile.toUtf8(), NULL)) { error() << "cannot logon using profile" << profile << mapiError(); return false; } if (MAPI_E_SUCCESS != OpenMsgStore(m_session, m_store)) { error() << "cannot open message store" << mapiError(); return false; } #if (ENABLE_PUBLIC_FOLDERS) if (MAPI_E_SUCCESS != OpenPublicFolder(m_session, m_nspiStore)) { error() << "cannot open public folder" << mapiError(); return false; } #endif MapiDebug debug(this, (0 != ENABLE_MAPI_DEBUG)); // Get rid of any existing notifier and create a new one. // TODO Wait for a version of libmapi that has asingle parameter here. #if (ENABLE_NOTIFICATIONS) #if 0 if (MAPI_E_SUCCESS != RegisterNotification(m_session)) { #else if (MAPI_E_SUCCESS != RegisterNotification(m_session, 0)) { #endif error() << "cannot register for notifications" << mapiError(); return false; } delete m_notifier; m_notifier = new QSocketNotifier(m_session->notify_ctx->fd, QSocketNotifier::Read); if (!m_notifier) { error() << "cannot create notifier"; return false; } connect(m_notifier, SIGNAL(activated(int)), this, SLOT(notified(int))); #endif return true; } void MapiConnector2::notified(int fd) { QAbstractSocket socket(QAbstractSocket::UdpSocket, this); socket.setSocketDescriptor(fd); struct mapi_response *mapi_response; NTSTATUS status; QByteArray data; while (true) { data = socket.readAll(); error() << "read from socket" << data.size(); if (!data.size()) { break; } // Dummy transaction to keep the pipe up. status = emsmdb_transaction_null((struct emsmdb_context *)m_session->emsmdb->ctx, &mapi_response); if (!NT_STATUS_IS_OK(status)) { error() << "bad nt status" << status; break; } //retval = ProcessNotification(notify_ctx, mapi_response); } }