MAPIFolder::~MAPIFolder() { if (m_folder != NULL) UlRelease(m_folder); if (m_EntryID.lpb != NULL) MAPIFreeBuffer(m_EntryID.lpb); if(m_pContentsTable != NULL) UlRelease(m_pContentsTable); if(m_pHierarchyTable!=NULL) UlRelease(m_pHierarchyTable); m_pHierarchyTable=NULL; m_pContentsTable = NULL; m_folder = NULL; m_EntryID.lpb = NULL; m_EntryID.cb = 0; }
/* Wrapper around UlRelease with error checking. */ static void ul_release (LPVOID punk, const char *func, int lnr) { ULONG res; if (!punk) return; res = UlRelease (punk); if (opt.enable_debug & DBG_MEMORY) log_debug ("%s:%s:%d: UlRelease(%p) had %lu references\n", SRCNAME, func, lnr, punk, res); }
void MAPITableIterator::Initialize(LPMAPITABLE pTable, LPMAPIFOLDER pFolder, MAPISession &session, ULONG ulItemTypeMask) { UNREFERENCED_PARAMETER(ulItemTypeMask); HRESULT hr = S_OK; m_session = &session; if (m_pParentFolder != NULL) { UlRelease(m_pParentFolder); m_pParentFolder = NULL; } if (m_pRows != NULL) FreeProws(m_pRows); m_pParentFolder = pFolder; m_pTable = pTable; hr = m_pTable->SetColumns(GetProps(), 0); if (FAILED(hr)) { throw GenericException(hr, L"MAPITableIterator::Initialize():SetColumns Failed.",ERR_SET_RESTRICTION, __LINE__, __FILE__); } if (GetSortOrder() != NULL) { if (FAILED(hr = m_pTable->SortTable(GetSortOrder(), 0))) { throw GenericException(hr, L"MAPITableIterator::Initialize():SortTable Failed.",ERR_SET_RESTRICTION, __LINE__, __FILE__); } } if (FAILED(hr = m_pTable->GetRowCount(0, &m_totalRows))) { throw GenericException(hr, L"MAPITableIterator::Initialize():GetRowCount Failed.",ERR_SET_RESTRICTION, __LINE__, __FILE__); } if (FAILED(hr = m_pTable->QueryRows(m_batchSize, 0, &m_pRows))) { throw GenericException(hr, L"MAPITableIterator::Initialize():QueryRows Failed.",ERR_SET_RESTRICTION, __LINE__, __FILE__); } }
void MAPIFolder::Initialize(LPMAPIFOLDER pFolder, LPTSTR displayName, LPSBinary pEntryId) { HRESULT hr=S_OK; if (m_folder != NULL) UlRelease(m_folder); if (m_EntryID.lpb != NULL) FreeEntryID(m_EntryID); if(m_pContentsTable != NULL) UlRelease(m_pContentsTable); if(m_pHierarchyTable!=NULL) UlRelease(m_pHierarchyTable); m_folder = pFolder; m_displayname = displayName; //replace later by "/" allow "/" /* size_t npos= m_displayname.find(L"/"); if ((npos != std::wstring::npos) && (npos>0)) { m_displayname.replace(npos,1,CONST_FORWDSLASH); } */ //parse whole string for forward slash not just one occurence std::wstring::size_type i = m_displayname.find(L"/"); while (i != std::wstring::npos && i < m_displayname.size()) { m_displayname.replace(i, wcslen(L"/"),CONST_FORWDSLASH); i += wcslen(L"/"); i = m_displayname.find( L"/", i); } CopyEntryID(*pEntryId, m_EntryID); //Get folder hierarchy table if (FAILED(hr = m_folder->GetHierarchyTable(fMapiUnicode, &m_pHierarchyTable))) { throw MAPIFolderException(E_FAIL, L"GetFolderIterator(): GetHierarchyTable Failed.", ERR_MAPI_FOLDER, __LINE__, __FILE__); } try{ //get folders content tabel if (FAILED(hr = m_folder->GetContentsTable(fMapiUnicode, &m_pContentsTable))) { throw MAPIFolderException(hr, L"Initialize(): GetContentsTable Failed.", ERR_MAPI_FOLDER, __LINE__, __FILE__); } } catch(...) { throw MAPIFolderException(hr, L"Initialize(): GetContentsTable Failed.", ERR_MAPI_FOLDER, __LINE__, __FILE__); } ULONG ulItemMask =ZCM_ALL; //disable restriction for only mails on IPF.Note folders. //Lets migrate everything in it for now. /* //find container class wstring wstrCntrClass = L""; if(S_OK==ContainerClass(wstrCntrClass)) { if (_tcsicmp(wstrCntrClass.c_str(), _TEXT("IPF.NOTE")) == 0) ulItemMask = ZCM_MAIL; } */ //Apply restrictions. Zimbra::MAPI::MIRestriction restriction; FILETIME tmpTime = { 0, 0 }; if (FAILED(hr = m_pContentsTable->Restrict(restriction.GetRestriction(ulItemMask, tmpTime), 0))) { throw MAPIFolderException(hr, L"MAPIFolder::Initialize():Restrict Failed.", ERR_MAPI_FOLDER, __LINE__, __FILE__); } if (m_session) { wstring wstrFolderPath = FindFolderPath(); m_folderpath = wstrFolderPath; } }