bool MIPDirectShowCapture::initCaptureGraphBuilder() { IGraphBuilder *pGraph = NULL; ICaptureGraphBuilder2 *pBuild = NULL; HRESULT hr = CoCreateInstance(CLSID_CaptureGraphBuilder2, NULL, CLSCTX_INPROC_SERVER, IID_ICaptureGraphBuilder2, (void**)&pBuild); if (HR_FAILED(hr)) { setErrorString(MIPDIRECTSHOWCAPTURE_ERRSTR_CANTCREATECAPTUREBUILDER); return false; } hr = CoCreateInstance(CLSID_FilterGraph, 0, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void**)&pGraph); if (HR_FAILED(hr)) { pBuild->Release(); setErrorString(MIPDIRECTSHOWCAPTURE_ERRSTR_CANTCREATEMANAGER); return false; } pBuild->SetFiltergraph(pGraph); m_pBuilder = pBuild; m_pGraph = pGraph; return true; }
bool CMapiMessage::CopyBinAttachToFile(LPATTACH lpAttach, nsIFile **tmp_file) { nsCOMPtr<nsIFile> _tmp_file; nsresult rv = GetSpecialDirectoryWithFileName(NS_OS_TEMP_DIR, "mapiattach.tmp", getter_AddRefs(_tmp_file)); NS_ENSURE_SUCCESS(rv, false); rv = _tmp_file->CreateUnique(nsIFile::NORMAL_FILE_TYPE, 00600); NS_ENSURE_SUCCESS(rv, false); nsCString tmpPath; _tmp_file->GetNativePath(tmpPath); LPSTREAM lpStreamFile; HRESULT hr = CMapiApi::OpenStreamOnFile(gpMapiAllocateBuffer, gpMapiFreeBuffer, STGM_READWRITE | STGM_CREATE, const_cast<char*>(tmpPath.get()), NULL, &lpStreamFile); if (HR_FAILED(hr)) { MAPI_TRACE1("~~ERROR~~ OpenStreamOnFile failed - temp path: %s\r\n", tmpPath.get()); return false; } bool bResult = true; LPSTREAM lpAttachStream; hr = lpAttach->OpenProperty(PR_ATTACH_DATA_BIN, &IID_IStream, 0, 0, (LPUNKNOWN *)&lpAttachStream); if (HR_FAILED(hr)) { MAPI_TRACE0("~~ERROR~~ OpenProperty failed for PR_ATTACH_DATA_BIN.\r\n"); lpAttachStream = NULL; bResult = false; } else { STATSTG st; hr = lpAttachStream->Stat(&st, STATFLAG_NONAME); if (HR_FAILED(hr)) { MAPI_TRACE0("~~ERROR~~ Stat failed for attachment stream\r\n"); bResult = false; } else { hr = lpAttachStream->CopyTo(lpStreamFile, st.cbSize, NULL, NULL); if (HR_FAILED(hr)) { MAPI_TRACE0("~~ERROR~~ Attach Stream CopyTo temp file failed.\r\n"); bResult = false; } } } if (lpAttachStream) lpAttachStream->Release(); lpStreamFile->Release(); if (!bResult) _tmp_file->Remove(false); else CallQueryInterface(_tmp_file, tmp_file); return bResult; }
bool MIPDirectShowCapture::listGUIDS(std::list<GUID> &guids) { guids.clear(); HRESULT hr; IAMStreamConfig *pConfig = 0; hr = m_pBuilder->FindInterface(&PIN_CATEGORY_CAPTURE, 0, m_pCaptDevice, IID_IAMStreamConfig, (void**)&pConfig); if (HR_FAILED(hr)) { setErrorString(MIPDIRECTSHOWCAPTURE_ERRSTR_CANTGETDEVICECONFIG); return false; } int count = 0; int s = 0; hr = pConfig->GetNumberOfCapabilities(&count, &s); if (HR_FAILED(hr)) { pConfig->Release(); setErrorString(MIPDIRECTSHOWCAPTURE_ERRSTR_CANTGETDEVICECAPS); return false; } if (s != sizeof(VIDEO_STREAM_CONFIG_CAPS)) { pConfig->Release(); setErrorString(MIPDIRECTSHOWCAPTURE_ERRSTR_INVALIDCAPS); return false; } for (int i = 0; i < count; i++) { VIDEO_STREAM_CONFIG_CAPS caps; AM_MEDIA_TYPE *pMediaType; hr = pConfig->GetStreamCaps(i, &pMediaType, (BYTE*)&caps); if (HR_SUCCEEDED(hr)) { if (pMediaType->majortype == MEDIATYPE_Video) { GUID subType = pMediaType->subtype; guids.push_back(subType); // uint8_t *pSubType = (uint8_t *)&subType; // // printf("0x%02x%02x%02x%02x %c%c%c%c\n",(int)pSubType[0],(int)pSubType[1],(int)pSubType[2],(int)pSubType[3], // (char)pSubType[0],(char)pSubType[1],(char)pSubType[2],(char)pSubType[3]); } } } return true; }
bool MIPDirectShowCapture::getCaptureDevice(int deviceNumber) { ICreateDevEnum *pDevEnum = 0; IEnumMoniker *pEnum = 0; HRESULT hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER, IID_ICreateDevEnum, (void **)(&pDevEnum)); if (HR_FAILED(hr)) { setErrorString(MIPDIRECTSHOWCAPTURE_ERRSTR_CANTCREATEDEVICEENUMERATOR); return false; } hr = pDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory, &pEnum, 0); if (HR_FAILED(hr)) { pDevEnum->Release(); setErrorString(MIPDIRECTSHOWCAPTURE_ERRSTR_CANTCAPTUREENUMERATOR); return false; } if (pEnum == 0) { pDevEnum->Release(); setErrorString(MIPDIRECTSHOWCAPTURE_ERRSTR_CANTFINDCAPTUREDEVICE); return false; } IMoniker *pMoniker = NULL; while (pEnum->Next(1, &pMoniker, NULL) == S_OK) { if (deviceNumber == 0) { hr = pMoniker->BindToObject(0, 0, IID_IBaseFilter, (void**)&m_pCaptDevice); pMoniker->Release(); if (HR_SUCCEEDED(hr)) { pEnum->Release(); pDevEnum->Release(); return true; } else { m_pCaptDevice = 0; pEnum->Release(); pDevEnum->Release(); setErrorString(MIPDIRECTSHOWCAPTURE_ERRSTR_CANTBINDCAPTUREDEVICE); return false; } } else deviceNumber--; } pEnum->Release(); pDevEnum->Release(); setErrorString(MIPDIRECTSHOWCAPTURE_ERRSTR_CANTFINDCAPTUREDEVICE); return false; }
CMsgStore * CMapiApi::FindMessageStore( ULONG cbEid, LPENTRYID lpEid) { if (!m_lpSession) { MAPI_TRACE0( "FindMessageStore called before session is open\n"); m_lastError = -1; return( NULL); } ULONG result; HRESULT hr; CMsgStore * pStore; for (int i = 0; i < m_pStores->Count(); i++) { pStore = (CMsgStore *) m_pStores->ElementAt( i); hr = m_lpSession->CompareEntryIDs( cbEid, lpEid, pStore->GetCBEntryID(), pStore->GetLPEntryID(), 0, &result); if (HR_FAILED( hr)) { MAPI_TRACE2( "CompareEntryIDs failed: 0x%lx, %d\n", (long)hr, (int)hr); m_lastError = hr; return( NULL); } if ( result) { return( pStore); } } pStore = new CMsgStore( cbEid, lpEid); AddMessageStore( pStore); return( pStore); }
LPSPropValue CMapiApi::GetMapiProperty( LPMAPIPROP pProp, ULONG tag) { if (!pProp) return( NULL); int sz = CbNewSPropTagArray( 1); SPropTagArray *pTag = (SPropTagArray *) new char[sz]; pTag->cValues = 1; pTag->aulPropTag[0] = tag; LPSPropValue lpProp = NULL; ULONG cValues = 0; HRESULT hr = pProp->GetProps( pTag, 0, &cValues, &lpProp); delete [] pTag; if (HR_FAILED( hr) || (cValues != 1)) { if (lpProp) MAPIFreeBuffer( lpProp); return( NULL); } else { if (PROP_TYPE( lpProp->ulPropTag) == PT_ERROR) { if (lpProp->Value.l == MAPI_E_NOT_FOUND) { MAPIFreeBuffer( lpProp); lpProp = NULL; } } } return( lpProp); }
BOOL nsWabAddressBook::LoadWabLibrary(void) { if (mLibrary) { ++ mLibUsage ; return TRUE ; } // We try to fetch the location of the WAB DLL from the registry TCHAR wabDLLPath [MAX_PATH] ; DWORD keyType = 0 ; ULONG byteCount = sizeof(wabDLLPath) ; HKEY keyHandle = NULL ; wabDLLPath [MAX_PATH - 1] = 0 ; if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, WAB_DLL_PATH_KEY, 0, KEY_READ, &keyHandle) == ERROR_SUCCESS) { RegQueryValueEx(keyHandle, "", NULL, &keyType, (LPBYTE) wabDLLPath, &byteCount) ; } if (keyHandle) { RegCloseKey(keyHandle) ; } mLibrary = LoadLibrary( (lstrlen(wabDLLPath)) ? wabDLLPath : WAB_DLL_NAME ); if (!mLibrary) { return FALSE ; } ++ mLibUsage ; mWABOpen = reinterpret_cast<LPWABOPEN>(GetProcAddress(mLibrary, "WABOpen")) ; if (!mWABOpen) { return FALSE ; } HRESULT retCode = mWABOpen(&mRootBook, &mRootSession, NULL, 0) ; if (HR_FAILED(retCode)) { PRINTF(("Cannot initialize WAB %08x.\n", retCode)) ; return FALSE ; } return TRUE ; }
BOOL CMapiFolderContents::GetNext( ULONG *pcbEid, LPENTRYID *ppEid, ULONG *poType, BOOL *pDone) { *pDone = FALSE; if (m_failure) return( FALSE); if (!m_lpFolder) { if (!SetUpIter()) { m_failure = TRUE; return( FALSE); } if (!m_count) { *pDone = TRUE; return( TRUE); } } int cNumRows = 0; LPSRowSet lpRow = NULL; HRESULT hr = m_lpTable->QueryRows( 1, 0, &lpRow); if(HR_FAILED( hr)) { m_lastError = hr; m_failure = TRUE; MAPI_TRACE2( "CMapiFolderContents - QueryRows failed: 0x%lx, %d\n", (long)hr, (int)hr); return( FALSE); } if(lpRow) { cNumRows = lpRow->cRows; if (cNumRows) { LPENTRYID lpEID = (LPENTRYID) lpRow->aRow[0].lpProps[ieidPR_ENTRYID].Value.bin.lpb; ULONG cbEID = lpRow->aRow[0].lpProps[ieidPR_ENTRYID].Value.bin.cb; ULONG oType = lpRow->aRow[0].lpProps[ieidPR_OBJECT_TYPE].Value.ul; if (m_lastCbEid != cbEID) { if (m_lastLpEid) delete m_lastLpEid; m_lastLpEid = new BYTE[cbEID]; m_lastCbEid = cbEID; } memcpy( m_lastLpEid, lpEID, cbEID); *ppEid = (LPENTRYID) m_lastLpEid; *pcbEid = cbEID; *poType = oType; } else *pDone = TRUE; CMapiApi::FreeProws( lpRow); } else *pDone = TRUE; return( TRUE); }
LPSPropValue CWAB::GetUserProperty( LPMAILUSER pUser, ULONG tag) { if (!pUser) return( NULL); ULONG uTag = tag; /* Getting Unicode does not help with getting the right international charset. Windoze bloze. */ /* if (PROP_TYPE( uTag) == PT_STRING8) { uTag = CHANGE_PROP_TYPE( tag, PT_UNICODE); } */ int sz = CbNewSPropTagArray( 1); SPropTagArray *pTag = (SPropTagArray *) new char[sz]; pTag->cValues = 1; pTag->aulPropTag[0] = uTag; LPSPropValue lpProp = NULL; ULONG cValues = 0; HRESULT hr = pUser->GetProps( pTag, 0, &cValues, &lpProp); if (HR_FAILED( hr) || (cValues != 1)) { if (lpProp) m_lpWABObject->FreeBuffer( lpProp); lpProp = NULL; if (uTag != tag) { pTag->cValues = 1; pTag->aulPropTag[0] = tag; cValues = 0; hr = pUser->GetProps( pTag, 0, &cValues, &lpProp); if (HR_FAILED( hr) || (cValues != 1)) { if (lpProp) m_lpWABObject->FreeBuffer( lpProp); lpProp = NULL; } } } delete [] pTag; return( lpProp); }
BOOL CMapiMessage::IterateAttachTable( void) { LPMAPITABLE lpTable = m_pAttachTable; ULONG rowCount; HRESULT hr = lpTable->GetRowCount( 0, &rowCount); if (!rowCount) { return( TRUE); } hr = lpTable->SetColumns( (LPSPropTagArray)&ptaEid, 0); if (FAILED(hr)) { MAPI_TRACE2( "SetColumns for attachment table failed: 0x%lx, %d\r\n", (long)hr, (int)hr); return( FALSE); } hr = lpTable->SeekRow( BOOKMARK_BEGINNING, 0, NULL); if (FAILED(hr)) { MAPI_TRACE2( "SeekRow for attachment table failed: 0x%lx, %d\r\n", (long)hr, (int)hr); return( FALSE); } int cNumRows = 0; LPSRowSet lpRow; BOOL bResult = TRUE; do { lpRow = NULL; hr = lpTable->QueryRows( 1, 0, &lpRow); if(HR_FAILED(hr)) { MAPI_TRACE2( "QueryRows for attachment table failed: 0x%lx, %d\n", (long)hr, (int)hr); bResult = FALSE; break; } if (lpRow) { cNumRows = lpRow->cRows; if (cNumRows) { DWORD aNum = lpRow->aRow[0].lpProps[ieidPR_ATTACH_NUM].Value.ul; m_attachNums.AppendElement(aNum); MAPI_TRACE1( "\t\t****Attachment found - #%d\r\n", (int)aNum); } CMapiApi::FreeProws( lpRow); } } while ( SUCCEEDED(hr) && cNumRows && lpRow); return( bResult); }
BOOL CMapiApi::GetLargeStringProperty( LPMAPIPROP pProp, ULONG tag, nsCString& val) { LPSTREAM lpStream; HRESULT hr = pProp->OpenProperty( tag, &IID_IStream, 0, 0, (LPUNKNOWN *)&lpStream); if (HR_FAILED( hr)) return( FALSE); STATSTG st; BOOL bResult = TRUE; hr = lpStream->Stat( &st, STATFLAG_NONAME); if (HR_FAILED( hr)) bResult = FALSE; else { if (!st.cbSize.QuadPart) st.cbSize.QuadPart = 1; char *pVal = new char[ (int) st.cbSize.QuadPart + 1]; // val.SetCapacity( (int) st.cbSize.QuadPart); if (pVal) { ULONG sz; hr = lpStream->Read( pVal, (ULONG) st.cbSize.QuadPart, &sz); if (HR_FAILED( hr)) { bResult = FALSE; *pVal = 0; sz = 0; } else pVal[(int) st.cbSize.QuadPart] = 0; val = pVal; delete [] pVal; } else bResult = FALSE; } lpStream->Release(); return( bResult); }
BOOL CMsgStore::Open( LPMAPISESSION pSession, LPMDB *ppMdb) { if ( m_lpMdb) { if (ppMdb) *ppMdb = m_lpMdb; return( TRUE); } BOOL bResult = TRUE; HRESULT hr = pSession->OpenMsgStore( NULL, m_cbEid, (LPENTRYID)m_lpEid, NULL, MDB_NO_MAIL, &m_lpMdb); // MDB pointer if (HR_FAILED( hr)) { m_lpMdb = NULL; MAPI_TRACE2( "OpenMsgStore failed: 0x%lx, %d\n", (long)hr, (int)hr); bResult = FALSE; } if (ppMdb) *ppMdb = m_lpMdb; return( bResult); }
LPSPropValue CWAB::GetListProperty( LPDISTLIST pUser, ULONG tag) { if (!pUser) return( NULL); int sz = CbNewSPropTagArray( 1); SPropTagArray *pTag = (SPropTagArray *) new char[sz]; pTag->cValues = 1; pTag->aulPropTag[0] = tag; LPSPropValue lpProp = NULL; ULONG cValues = 0; HRESULT hr = pUser->GetProps( pTag, 0, &cValues, &lpProp); delete [] pTag; if (HR_FAILED( hr) || (cValues != 1)) { if (lpProp) m_lpWABObject->FreeBuffer( lpProp); return( NULL); } return( lpProp); }
nsresult nsOutlookMail::CreateList(const PRUnichar * pName, nsIAddrDatabase *pDb, LPMAPIPROP pUserList, nsIImportFieldMap *pFieldMap) { // If no name provided then we're done. if (!pName || !(*pName)) return NS_OK; nsresult rv = NS_ERROR_FAILURE; // Make sure we have db to work with. if (!pDb) return rv; nsCOMPtr <nsIMdbRow> newListRow; rv = pDb->GetNewListRow(getter_AddRefs(newListRow)); NS_ENSURE_SUCCESS(rv, rv); nsAutoCString column; LossyCopyUTF16toASCII(nsDependentString(pName), column); rv = pDb->AddListName(newListRow, column.get()); NS_ENSURE_SUCCESS(rv, rv); HRESULT hr; LPSPropValue value = NULL; ULONG valueCount = 0; LPSPropTagArray properties = NULL; m_mapi.MAPIAllocateBuffer(CbNewSPropTagArray(1), (void **)&properties); properties->cValues = 1; properties->aulPropTag [0] = m_mapi.GetEmailPropertyTag(pUserList, 0x8054); hr = pUserList->GetProps(properties, 0, &valueCount, &value); m_mapi.MAPIFreeBuffer(properties); if (HR_FAILED(hr)) return NS_ERROR_FAILURE; if (!value) return NS_ERROR_NOT_AVAILABLE; // XXX from here out, value must be freed with MAPIFreeBuffer SBinaryArray *sa=(SBinaryArray *)&value->Value.bin; if (!sa || !sa->lpbin) { m_mapi.MAPIFreeBuffer(value); return NS_ERROR_NULL_POINTER; } LPENTRYID lpEid; ULONG cbEid; int32_t idx; LPMESSAGE lpMsg; nsCString type; LPSPropValue pVal; nsString subject; uint32_t total; total=sa->cValues; for (idx = 0; idx < sa->cValues; idx++) { lpEid= (LPENTRYID) sa->lpbin[idx].lpb; cbEid = sa->lpbin[idx].cb; if (!m_mapi.OpenEntry(cbEid, lpEid, (LPUNKNOWN *) &lpMsg)) { IMPORT_LOG1("*** Error opening messages in mailbox: %S\n", pName); m_mapi.MAPIFreeBuffer(value); return NS_ERROR_FAILURE; } // This is a contact, add it to the address book! subject.Truncate(); pVal = m_mapi.GetMapiProperty(lpMsg, PR_SUBJECT); if (pVal) m_mapi.GetStringFromProp(pVal, subject); nsCOMPtr <nsIMdbRow> newRow; nsCOMPtr <nsIMdbRow> oldRow; pDb->GetNewRow(getter_AddRefs(newRow)); if (newRow) { if (BuildCard(subject.get(), pDb, newRow, lpMsg, pFieldMap)) { nsCOMPtr <nsIAbCard> userCard; nsCOMPtr <nsIAbCard> newCard; userCard = do_CreateInstance(NS_ABMDBCARD_CONTRACTID, &rv); NS_ENSURE_SUCCESS(rv, rv); pDb->InitCardFromRow(userCard,newRow); //add card to db bool bl=false; pDb->FindRowByCard(userCard,getter_AddRefs(oldRow)); if (oldRow) newRow = oldRow; else pDb->AddCardRowToDB(newRow); //add card list pDb->AddListCardColumnsToRow(userCard, newListRow,idx+1, getter_AddRefs(newCard), true, nullptr, nullptr); } } } m_mapi.MAPIFreeBuffer(value); rv = pDb->AddCardRowToDB(newListRow); NS_ENSURE_SUCCESS(rv, rv); rv = pDb->SetListAddressTotal(newListRow, total); rv = pDb->AddListDirNode(newListRow); return rv; }
void CMapiApi::GetStoreInfo( CMapiFolder *pFolder, long *pSzContents) { HRESULT hr; LPMDB lpMdb; if (pSzContents) *pSzContents = 0; if (!OpenStore( pFolder->GetCBEntryID(), pFolder->GetEntryID(), &lpMdb)) return; LPSPropValue pVal; /* pVal = GetMapiProperty( lpMdb, PR_DISPLAY_NAME); ReportStringProp( " Message store name:", pVal); pVal = GetMapiProperty( lpMdb, PR_MDB_PROVIDER); ReportUIDProp( " Message store provider:", pVal); pVal = GetMapiProperty( lpMdb, PR_COMMENT); ReportStringProp( " Message comment:", pVal); pVal = GetMapiProperty( lpMdb, PR_ACCESS_LEVEL); ReportLongProp( " Message store Access Level:", pVal); pVal = GetMapiProperty( lpMdb, PR_STORE_SUPPORT_MASK); ReportLongProp( " Message store support mask:", pVal); pVal = GetMapiProperty( lpMdb, PR_STORE_STATE); ReportLongProp( " Message store state:", pVal); pVal = GetMapiProperty( lpMdb, PR_OBJECT_TYPE); ReportLongProp( " Message store object type:", pVal); pVal = GetMapiProperty( lpMdb, PR_VALID_FOLDER_MASK); ReportLongProp( " Message store valid folder mask:", pVal); pVal = GetMapiProperty( lpMdb, 0x8001001e); ReportStringProp( " Message prop 0x8001001e:", pVal); // This key appears to be the OMI Account Manager account that corresponds // to this message store. This is important for IMAP accounts // since we may not want to import messages from an IMAP store! // Seems silly if you ask me! // In order to test this, we'll need the registry key to look under to determine // if it contains the "IMAP Server" value, if it does then we are an // IMAP store, if not, then we are a non-IMAP store - which may always mean // a regular store that should be imported. pVal = GetMapiProperty( lpMdb, 0x80000003); ReportLongProp( " Message prop 0x80000003:", pVal); // ListProperties( lpMdb); */ pVal = GetMapiProperty( lpMdb, PR_IPM_SUBTREE_ENTRYID); if (pVal) { ULONG cbEntry; LPENTRYID pEntry; LPMAPIFOLDER lpSubTree = NULL; if (GetEntryIdFromProp( pVal, cbEntry, pEntry)) { // Open up the folder! ULONG ulObjType; hr = lpMdb->OpenEntry( cbEntry, pEntry, NULL, 0, &ulObjType, (LPUNKNOWN *) &lpSubTree); MAPIFreeBuffer( pEntry); if (SUCCEEDED( hr) && lpSubTree) { // Find out if there are any contents in the // tree. LPMAPITABLE lpTable; hr = lpSubTree->GetHierarchyTable( 0, &lpTable); if (HR_FAILED(hr)) { MAPI_TRACE2( "GetStoreInfo: GetHierarchyTable failed: 0x%lx, %d\n", (long)hr, (int)hr); } else { ULONG rowCount; hr = lpTable->GetRowCount( 0, &rowCount); lpTable->Release(); if (SUCCEEDED( hr) && pSzContents) *pSzContents = (long) rowCount; } lpSubTree->Release(); } } } }
BOOL CMapiApi::IterateStores( CMapiFolderList& stores) { stores.ClearAll(); if (!m_lpSession) { MAPI_TRACE0( "IterateStores called before session is open\n"); m_lastError = -1; return( FALSE); } HRESULT hr; /* -- Some Microsoft sample code just to see if things are working --- *//* ULONG cbEIDStore; LPENTRYID lpEIDStore; hr = HrMAPIFindDefaultMsgStore( m_lpSession, &cbEIDStore, &lpEIDStore); if (HR_FAILED(hr)) { MAPI_TRACE0( "Default message store not found\n"); // MessageBox(NULL,"Message Store Not Found",NULL,MB_OK); } else { LPMDB lpStore; MAPI_TRACE0( "Default Message store FOUND\n"); hr = m_lpSession->OpenMsgStore( NULL, cbEIDStore, lpEIDStore, NULL, MDB_NO_MAIL | MDB_NO_DIALOG, &lpStore); if (HR_FAILED(hr)) { MAPI_TRACE1( "Unable to open default message store: 0x%lx\n", hr); } else { MAPI_TRACE0( "Default message store OPENED\n"); lpStore->Release(); } } */ LPMAPITABLE lpTable; hr = m_lpSession->GetMsgStoresTable( 0, &lpTable); if (FAILED(hr)) { MAPI_TRACE0( "GetMsgStoresTable failed\n"); m_lastError = hr; return( FALSE); } ULONG rowCount; hr = lpTable->GetRowCount( 0, &rowCount); MAPI_TRACE1( "MsgStores Table rowCount: %ld\n", rowCount); hr = lpTable->SetColumns( (LPSPropTagArray)&ptaTbl, 0); if (FAILED(hr)) { lpTable->Release(); MAPI_TRACE2( "SetColumns failed: 0x%lx, %d\n", (long)hr, (int)hr); m_lastError = hr; return( FALSE); } hr = lpTable->SeekRow( BOOKMARK_BEGINNING, 0, NULL); if (FAILED(hr)) { lpTable->Release(); MAPI_TRACE2( "SeekRow failed: 0x%lx, %d\n", (long)hr, (int)hr); m_lastError = hr; return( FALSE); } int cNumRows = 0; LPSRowSet lpRow; BOOL keepGoing = TRUE; BOOL bResult = TRUE; do { lpRow = NULL; hr = lpTable->QueryRows( 1, 0, &lpRow); if(HR_FAILED(hr)) { MAPI_TRACE2( "QueryRows failed: 0x%lx, %d\n", (long)hr, (int)hr); bResult = FALSE; m_lastError = hr; break; } if(lpRow) { cNumRows = lpRow->cRows; if (cNumRows) { LPCTSTR lpStr = (LPCTSTR) lpRow->aRow[0].lpProps[itblPR_DISPLAY_NAME].Value.LPSZ; LPENTRYID lpEID = (LPENTRYID) lpRow->aRow[0].lpProps[itblPR_ENTRYID].Value.bin.lpb; ULONG cbEID = lpRow->aRow[0].lpProps[itblPR_ENTRYID].Value.bin.cb; // In the future, GetStoreInfo needs to somehow return // whether or not the store is from an IMAP server. // Currently, GetStoreInfo opens the store and attempts // to get the hierarchy tree. If the tree is empty or // does not exist, then szContents will be zero. We'll // assume that any store that doesn't have anything in // it's hierarchy tree is not a store we want to import - // there would be nothing to import from anyway! // Currently, this does exclude IMAP server accounts // which is the desired behaviour. int strLen = strlen(lpStr); PRUnichar * pwszStr = (PRUnichar *) nsMemory::Alloc((strLen + 1) * sizeof(WCHAR)); if (!pwszStr) { // out of memory FreeProws( lpRow); lpTable->Release(); return FALSE; } ::MultiByteToWideChar(CP_ACP, 0, lpStr, strlen(lpStr) + 1, pwszStr, (strLen + 1) * sizeof(WCHAR)); CMapiFolder *pFolder = new CMapiFolder( pwszStr, cbEID, lpEID, 0, MAPI_STORE); nsMemory::Free(pwszStr); long szContents = 1; GetStoreInfo( pFolder, &szContents); MAPI_TRACE1( " DisplayName: %s\n", lpStr); if (szContents) { stores.AddItem( pFolder); } else { delete pFolder; MAPI_TRACE0( " ^^^^^ Not added to store list\n"); } keepGoing = TRUE; } FreeProws( lpRow); } } while ( SUCCEEDED(hr) && cNumRows && lpRow && keepGoing); lpTable->Release(); return( bResult); }
BOOL CMapiApi::IterateHierarchy( CMapiHierarchyIter *pIter, LPMAPIFOLDER pFolder, ULONG flags) { // flags can be CONVENIENT_DEPTH or 0 // CONVENIENT_DEPTH will return all depths I believe instead // of just children HRESULT hr; LPMAPITABLE lpTable; hr = pFolder->GetHierarchyTable( flags, &lpTable); if (HR_FAILED(hr)) { m_lastError = hr; MAPI_TRACE2( "IterateHierarchy: GetContentsTable failed: 0x%lx, %d\n", (long)hr, (int)hr); return( FALSE); } ULONG rowCount; hr = lpTable->GetRowCount( 0, &rowCount); if (!rowCount) { lpTable->Release(); return( TRUE); } hr = lpTable->SetColumns( (LPSPropTagArray)&ptaEid, 0); if (HR_FAILED(hr)) { m_lastError = hr; lpTable->Release(); MAPI_TRACE2( "IterateHierarchy: SetColumns failed: 0x%lx, %d\n", (long)hr, (int)hr); return( FALSE); } hr = lpTable->SeekRow( BOOKMARK_BEGINNING, 0, NULL); if (HR_FAILED(hr)) { m_lastError = hr; lpTable->Release(); MAPI_TRACE2( "IterateHierarchy: SeekRow failed: 0x%lx, %d\n", (long)hr, (int)hr); return( FALSE); } int cNumRows = 0; LPSRowSet lpRow; BOOL keepGoing = TRUE; BOOL bResult = TRUE; do { lpRow = NULL; hr = lpTable->QueryRows( 1, 0, &lpRow); if(HR_FAILED(hr)) { MAPI_TRACE2( "QueryRows failed: 0x%lx, %d\n", (long)hr, (int)hr); m_lastError = hr; bResult = FALSE; break; } if(lpRow) { cNumRows = lpRow->cRows; if (cNumRows) { LPENTRYID lpEntry = (LPENTRYID) lpRow->aRow[0].lpProps[ieidPR_ENTRYID].Value.bin.lpb; ULONG cb = lpRow->aRow[0].lpProps[ieidPR_ENTRYID].Value.bin.cb; ULONG oType = lpRow->aRow[0].lpProps[ieidPR_OBJECT_TYPE].Value.ul; if (pIter) keepGoing = pIter->HandleHierarchyItem( oType, cb, lpEntry); else keepGoing = HandleHierarchyItem( oType, cb, lpEntry); } FreeProws( lpRow); } } while ( SUCCEEDED(hr) && cNumRows && lpRow && keepGoing); lpTable->Release(); if (bResult && !keepGoing) bResult = FALSE; return( bResult); }
BOOL CMapiApi::IterateContents( CMapiContentIter *pIter, LPMAPIFOLDER pFolder, ULONG flags) { // flags can be 0 or MAPI_ASSOCIATED // MAPI_ASSOCIATED is usually used for forms and views HRESULT hr; LPMAPITABLE lpTable; hr = pFolder->GetContentsTable( flags, &lpTable); if (FAILED(hr)) { MAPI_TRACE2( "GetContentsTable failed: 0x%lx, %d\n", (long)hr, (int)hr); return( FALSE); } ULONG rowCount; hr = lpTable->GetRowCount( 0, &rowCount); if (!rowCount) { MAPI_TRACE0( " Empty Table\n"); } hr = lpTable->SetColumns( (LPSPropTagArray)&ptaEid, 0); if (FAILED(hr)) { lpTable->Release(); MAPI_TRACE2( "SetColumns failed: 0x%lx, %d\n", (long)hr, (int)hr); return( FALSE); } hr = lpTable->SeekRow( BOOKMARK_BEGINNING, 0, NULL); if (FAILED(hr)) { lpTable->Release(); MAPI_TRACE2( "SeekRow failed: 0x%lx, %d\n", (long)hr, (int)hr); return( FALSE); } int cNumRows = 0; LPSRowSet lpRow; BOOL keepGoing = TRUE; BOOL bResult = TRUE; do { lpRow = NULL; hr = lpTable->QueryRows( 1, 0, &lpRow); if(HR_FAILED(hr)) { MAPI_TRACE2( "QueryRows failed: 0x%lx, %d\n", (long)hr, (int)hr); bResult = FALSE; break; } if(lpRow) { cNumRows = lpRow->cRows; if (cNumRows) { LPENTRYID lpEID = (LPENTRYID) lpRow->aRow[0].lpProps[ieidPR_ENTRYID].Value.bin.lpb; ULONG cbEID = lpRow->aRow[0].lpProps[ieidPR_ENTRYID].Value.bin.cb; ULONG oType = lpRow->aRow[0].lpProps[ieidPR_OBJECT_TYPE].Value.ul; keepGoing = HandleContentsItem( oType, cbEID, lpEID); MAPI_TRACE1( " ObjectType: %ld\n", oType); } FreeProws( lpRow); } } while ( SUCCEEDED(hr) && cNumRows && lpRow && keepGoing); lpTable->Release(); return( bResult); }
bool CMapiMessage::AddAttachment(DWORD aNum) { LPATTACH lpAttach = NULL; HRESULT hr = m_lpMsg->OpenAttach(aNum, NULL, 0, &lpAttach); if (HR_FAILED(hr)) { MAPI_TRACE2("\t\t****Attachment error, unable to open attachment: %d, 0x%lx\r\n", idx, hr); return false; } bool bResult = false; attach_data *data = new attach_data; ULONG aMethod; if (data) { bResult = true; // 1. Get the file that contains the attachment data LPSPropValue pVal = CMapiApi::GetMapiProperty(lpAttach, PR_ATTACH_METHOD); if (pVal) { aMethod = CMapiApi::GetLongFromProp(pVal); switch (aMethod) { case ATTACH_BY_VALUE: MAPI_TRACE1("\t\t** Attachment #%d by value.\r\n", aNum); bResult = CopyBinAttachToFile(lpAttach, getter_AddRefs(data->tmp_file)); data->delete_file = true; break; case ATTACH_BY_REFERENCE: case ATTACH_BY_REF_RESOLVE: case ATTACH_BY_REF_ONLY: pVal = CMapiApi::GetMapiProperty(lpAttach, PR_ATTACH_PATHNAME_W); if (pVal) { nsCString path; CMapiApi::GetStringFromProp(pVal, path); nsresult rv; data->tmp_file = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv); if (NS_FAILED(rv) || !data->tmp_file) { MAPI_TRACE0("*** Error creating file spec for attachment\n"); bResult = false; } else data->tmp_file->InitWithNativePath(path); } MAPI_TRACE2("\t\t** Attachment #%d by ref: %s\r\n", aNum, m_attachPath.get()); break; case ATTACH_EMBEDDED_MSG: MAPI_TRACE1("\t\t** Attachment #%d by Embedded Message??\r\n", aNum); // Convert the embedded IMessage from PR_ATTACH_DATA_OBJ to rfc822 attachment // (see http://msdn.microsoft.com/en-us/library/cc842329.aspx) // This is a recursive call. bResult = CopyMsgAttachToFile(lpAttach, getter_AddRefs(data->tmp_file)); data->delete_file = true; break; case ATTACH_OLE: MAPI_TRACE1("\t\t** Attachment #%d by OLE - yuck!!!\r\n", aNum); break; default: MAPI_TRACE2("\t\t** Attachment #%d unknown attachment method - 0x%lx\r\n", aNum, aMethod); bResult = false; } } else bResult = false; if (bResult) bResult = data->tmp_file; if (bResult) { bool isFile = false; bool exists = false; data->tmp_file->Exists(&exists); data->tmp_file->IsFile(&isFile); if (!exists || !isFile) { bResult = false; MAPI_TRACE0("Attachment file does not exist\n"); } } if (bResult) bResult = GetURL(data->tmp_file, getter_AddRefs(data->orig_url)); if (bResult) { // Now we have the file; proceed to the other properties data->encoding = NS_strdup(ENCODING_BINARY); nsString fname, fext; pVal = CMapiApi::GetMapiProperty(lpAttach, PR_ATTACH_LONG_FILENAME_W); if (!pVal) pVal = CMapiApi::GetMapiProperty(lpAttach, PR_ATTACH_FILENAME_W); CMapiApi::GetStringFromProp(pVal, fname); pVal = CMapiApi::GetMapiProperty(lpAttach, PR_ATTACH_EXTENSION_W); CMapiApi::GetStringFromProp(pVal, fext); MAPI_TRACE2("\t\t\t--- File name: %s, extension: %s\r\n", fname.get(), fext.get()); if (fext.IsEmpty()) { int idx = fname.RFindChar(L'.'); if (idx != -1) fext = Substring(fname, idx); } else if (fname.RFindChar(L'.') == -1) { fname += L"."; fname += fext; } if (fname.IsEmpty()) { // If no description use "Attachment i" format. fname = L"Attachment "; fname.AppendInt(static_cast<uint32_t>(aNum)); } data->real_name = ToNewUTF8String(fname); nsCString tmp; // We have converted it to the rfc822 document if (aMethod == ATTACH_EMBEDDED_MSG) { data->type = NS_strdup(MESSAGE_RFC822); } else { pVal = CMapiApi::GetMapiProperty(lpAttach, PR_ATTACH_MIME_TAG_A); CMapiApi::GetStringFromProp(pVal, tmp); MAPI_TRACE1("\t\t\t--- Mime type: %s\r\n", tmp.get()); if (tmp.IsEmpty()) { uint8_t *pType = NULL; if (!fext.IsEmpty()) { pType = CMimeTypes::GetMimeType(fext); } if (pType) data->type = NS_strdup((PC_S8)pType); else data->type = NS_strdup(APPLICATION_OCTET_STREAM); } else data->type = ToNewCString(tmp); } pVal = CMapiApi::GetMapiProperty(lpAttach, PR_ATTACH_CONTENT_ID_A); CMapiApi::GetStringFromProp(pVal, tmp); if (!tmp.IsEmpty()) data->cid = ToNewCString(tmp); } if (bResult) { // Now we need to decide if this attachment is embedded or not. // At first, I tried to simply check for the presence of the Content-Id. // But it turned out that this method is unreliable, since there exist cases // when an attachment has a Content-Id while isn't embedded (even in a message // with a plain-text body!). So next I tried to look for <img> tags that contain // the found Content-Id. But this is unreliable, too, because there exist cases // where other places of HTML reference the embedded messages (e.g. it may be // a background of a table cell, or some CSS; further, it is possible that the // reference to an embedded object is not in the main body, but in another // embedded object - like body references a CSS attachment that in turn references // a picture as a background of its element). From the other hand, it's unreliable // to relax the search criteria to any occurence of the Content-Id string in the body - // partly because the string may be simply in a text or other non-referencing part, // partly because of the abovementioned possibility that the reference is outside // the body at all. // There exist the PR_ATTACH_FLAGS property of the attachment. The MS documentation // tells about two possible flags in it: ATT_INVISIBLE_IN_HTML and ATT_INVISIBLE_IN_RTF. // There is at least one more undocumented flag: ATT_MHTML_REF. Some sources in Internet // suggest simply check for the latter flag to distinguish between the embedded // and ordinary attachments. But my observations indicate that even if the flags // don't include ATT_MHTML_REF, the attachment is still may be embedded. // However, my observations always show that the message is embedded if the flags // is not 0. // So now I will simply test for the non-zero flags to decide whether the attachment // is embedded or not. Possible advantage is reliability (I hope). // Another advantage is that it's much faster than search the body for Content-Id. DWORD flags = 0; pVal = CMapiApi::GetMapiProperty(lpAttach, PR_ATTACH_FLAGS); if (pVal) flags = CMapiApi::GetLongFromProp(pVal); if (m_bodyIsHtml && data->cid && (flags != 0)) // this is the embedded attachment m_embattachments.push_back(data); else // this is ordinary attachment m_stdattachments.push_back(data); } else { delete data; } } lpAttach->Release(); return bResult; }
nsresult nsOEAddressIterator::EnumList(const char16_t * pName, LPENTRYID pEid, ULONG cbEid, LPMAPITABLE lpTable) { // If no name provided then we're done. if (!pName || !(*pName)) return NS_OK; nsresult rv = NS_ERROR_FAILURE; HRESULT hr = E_FAIL; // Make sure we have db to work with. if (!m_database) return rv; nsCOMPtr <nsIMdbRow> listRow; rv = m_database->GetNewListRow(getter_AddRefs(listRow)); NS_ENSURE_SUCCESS(rv, rv); rv = m_database->AddListName(listRow, NS_ConvertUTF16toUTF8(pName).get()); NS_ENSURE_SUCCESS(rv, rv); rv = m_database->AddCardRowToDB(listRow); NS_ENSURE_SUCCESS(rv, rv); rv = m_database->AddListDirNode(listRow); NS_ENSURE_SUCCESS(rv, rv); LPSRowSet lpRowAB = NULL; ULONG lpcbEID = 0; LPENTRYID lpEID = NULL; ULONG rowCount = 0; int cNumRows = 0; int numListElems = 0; nsAutoString uniStr; hr = lpTable->GetRowCount(0, &rowCount); // hr = lpTable->SeekRow(BOOKMARK_BEGINNING, 0, NULL); if(HR_FAILED(hr)) return NS_ERROR_FAILURE; // Read all the rows of the table one by one do { hr = lpTable->QueryRows(1, 0, &lpRowAB); if(HR_FAILED(hr)) break; if(lpRowAB) { cNumRows = lpRowAB->cRows; if (cNumRows) { LPTSTR lpsz = lpRowAB->aRow[0].lpProps[ieidPR_DISPLAY_NAME].Value.lpszA; LPENTRYID lpEID = (LPENTRYID) lpRowAB->aRow[0].lpProps[ieidPR_ENTRYID].Value.bin.lpb; ULONG cbEID = lpRowAB->aRow[0].lpProps[ieidPR_ENTRYID].Value.bin.cb; // There are 2 kinds of objects - the MAPI_MAILUSER contact object // and the MAPI_DISTLIST contact object // For distribution lists, we will only consider MAILUSER // objects since we can't nest lists yet. if(lpRowAB->aRow[0].lpProps[ieidPR_OBJECT_TYPE].Value.l == MAPI_MAILUSER) { LPMAILUSER pUser = m_pWab->GetUser(cbEID, lpEID); LPSPropValue pProp = m_pWab->GetUserProperty(pUser, PR_EMAIL_ADDRESS); nsString eMail; nsCOMPtr <nsIMdbRow> cardRow; m_pWab->GetValueString(pProp, eMail); SanitizeValue(eMail); FindListRow(eMail, getter_AddRefs(cardRow)); if (cardRow) { nsCOMPtr <nsIAbCard> userCard; nsCOMPtr <nsIAbCard> newCard; userCard = do_CreateInstance(NS_ABMDBCARD_CONTRACTID, &rv); NS_ENSURE_SUCCESS(rv, rv); m_database->InitCardFromRow(userCard,cardRow); m_database->AddListCardColumnsToRow(userCard, listRow, ++numListElems, getter_AddRefs(newCard), true, nullptr, nullptr); } m_pWab->FreeProperty(pProp); m_pWab->ReleaseUser(pUser); } } m_pWab->FreeProws(lpRowAB); } } while (SUCCEEDED(hr) && cNumRows && lpRowAB); m_database->SetListAddressTotal(listRow, numListElems); return rv; }
bool MIPDirectShowCapture::setFormat(int w, int h, real_t rate) { HRESULT hr; IAMStreamConfig *pConfig = 0; hr = m_pBuilder->FindInterface(&PIN_CATEGORY_CAPTURE, 0, m_pCaptDevice, IID_IAMStreamConfig, (void**)&pConfig); if (HR_FAILED(hr)) { setErrorString(MIPDIRECTSHOWCAPTURE_ERRSTR_CANTGETDEVICECONFIG); return false; } int count = 0; int s = 0; hr = pConfig->GetNumberOfCapabilities(&count, &s); if (HR_FAILED(hr)) { pConfig->Release(); setErrorString(MIPDIRECTSHOWCAPTURE_ERRSTR_CANTGETDEVICECAPS); return false; } if (s != sizeof(VIDEO_STREAM_CONFIG_CAPS)) { pConfig->Release(); setErrorString(MIPDIRECTSHOWCAPTURE_ERRSTR_INVALIDCAPS); return false; } for (int i = 0; i < count; i++) { VIDEO_STREAM_CONFIG_CAPS caps; AM_MEDIA_TYPE *pMediaType; hr = pConfig->GetStreamCaps(i, &pMediaType, (BYTE*)&caps); if (HR_SUCCEEDED(hr)) { if ((pMediaType->majortype == MEDIATYPE_Video) && (pMediaType->subtype == m_selectedGuid) && (pMediaType->formattype == FORMAT_VideoInfo) && (pMediaType->cbFormat >= sizeof (VIDEOINFOHEADER)) && (pMediaType->pbFormat != 0)) { VIDEOINFOHEADER *pVih = (VIDEOINFOHEADER*)pMediaType->pbFormat; pVih->bmiHeader.biWidth = w; pVih->bmiHeader.biHeight = h; pVih->bmiHeader.biSizeImage = DIBSIZE(pVih->bmiHeader); pVih->AvgTimePerFrame = (REFERENCE_TIME)(10000000.0/rate); hr = pConfig->SetFormat(pMediaType); if (HR_SUCCEEDED(hr)) { CoTaskMemFree(pMediaType->pbFormat); pConfig->Release(); return true; } } if (pMediaType->pbFormat != 0) CoTaskMemFree(pMediaType->pbFormat); } } pConfig->Release(); setErrorString(MIPDIRECTSHOWCAPTURE_ERRSTR_CANTSETCAPS); return false; }
bool MIPDirectShowCapture::open(int width, int height, real_t frameRate, int deviceNumber) { if (m_pGraph != 0) { setErrorString(MIPDIRECTSHOWCAPTURE_ERRSTR_ALREADYOPEN); return false; } if (!initCaptureGraphBuilder()) return false; if (!getCaptureDevice(deviceNumber)) { clearNonZero(); return false; } std::list<GUID> guids; std::list<GUID>::const_iterator guidIt; if (!listGUIDS(guids)) { clearNonZero(); setErrorString(MIPDIRECTSHOWCAPTURE_ERRSTR_CANTLISTGUIDS); return false; } bool haveI420 = false; bool haveYUY2 = false; for (guidIt = guids.begin() ; guidIt != guids.end() ; guidIt++) { if (*guidIt == EMIP_MEDIASUBTYPE_I420) haveI420 = true; if (*guidIt == MEDIASUBTYPE_YUY2) haveYUY2 = true; } if (haveI420) { //std::cout << "Trying I420" << std::endl; m_selectedGuid = EMIP_MEDIASUBTYPE_I420; m_subType = MIPRAWVIDEOMESSAGE_TYPE_YUV420P; } else if (haveYUY2) { //std::cout << "Trying YUY2" << std::endl; m_selectedGuid = MEDIASUBTYPE_YUY2; m_subType = MIPRAWVIDEOMESSAGE_TYPE_YUYV; } else { clearNonZero(); setErrorString(MIPDIRECTSHOWCAPTURE_ERRSTR_CANTSELECTYUV420PORYUY2); return false; } HRESULT hr; hr = CoCreateInstance(CLSID_NullRenderer, NULL, CLSCTX_INPROC_SERVER, IID_IBaseFilter,(void **)(&m_pNullRenderer)); if (HR_FAILED(hr)) { clearNonZero(); setErrorString(MIPDIRECTSHOWCAPTURE_ERRSTR_CANTCREATENULLRENDERER); return false; } hr = CoCreateInstance(CLSID_SampleGrabber, NULL, CLSCTX_INPROC_SERVER, IID_IBaseFilter,(void **)(&m_pSampGrabFilter)); if (HR_FAILED(hr)) { clearNonZero(); setErrorString(MIPDIRECTSHOWCAPTURE_ERRSTR_CANTCREATEGRABFILTER); return false; } hr = m_pSampGrabFilter->QueryInterface(IID_ISampleGrabber, (void**)&m_pGrabber); if (HR_FAILED(hr)) { clearNonZero(); setErrorString(MIPDIRECTSHOWCAPTURE_ERRSTR_CANTCREATEGRABIFACE); return false; } AM_MEDIA_TYPE mt; ZeroMemory(&mt, sizeof(AM_MEDIA_TYPE)); mt.majortype = MEDIATYPE_Video; mt.subtype = m_selectedGuid; hr = m_pGrabber->SetMediaType(&mt); if (HR_FAILED(hr)) { clearNonZero(); setErrorString(MIPDIRECTSHOWCAPTURE_ERRSTR_CANTSELECTYUV420PORYUY2); return false; } m_pGrabCallback = new GrabCallback(this); hr = m_pGrabber->SetCallback(m_pGrabCallback, 1); if (HR_FAILED(hr)) { clearNonZero(); setErrorString(MIPDIRECTSHOWCAPTURE_ERRSTR_CANTSETCALLBACK); return false; } hr = m_pGraph->AddFilter(m_pCaptDevice, L"Capture Filter"); if (HR_FAILED(hr)) { clearNonZero(); setErrorString(MIPDIRECTSHOWCAPTURE_ERRSTR_CANTADDCAPTUREFILTER); return false; } if (!setFormat(width, height, frameRate)) { clearNonZero(); return false; } hr = m_pGraph->AddFilter(m_pNullRenderer, L"Null Renderer"); if (HR_FAILED(hr)) { clearNonZero(); setErrorString(MIPDIRECTSHOWCAPTURE_ERRSTR_CANTADDNULLRENDERER); return false; } hr = m_pGraph->AddFilter(m_pSampGrabFilter, L"Sample Grabber"); if (HR_FAILED(hr)) { clearNonZero(); setErrorString(MIPDIRECTSHOWCAPTURE_ERRSTR_CANTADDSAMPLEGRABBER); return false; } hr = m_pBuilder->RenderStream(&PIN_CATEGORY_CAPTURE, &MEDIATYPE_Video, m_pCaptDevice, m_pSampGrabFilter, m_pNullRenderer); if (HR_FAILED(hr)) { clearNonZero(); setErrorString(MIPDIRECTSHOWCAPTURE_ERRSTR_CANTBUILDGRAPH); return false; } hr = m_pGrabber->GetConnectedMediaType(&mt); if (HR_FAILED(hr)) { clearNonZero(); setErrorString(MIPDIRECTSHOWCAPTURE_ERRSTR_CANTGETFRAMESIZE); return false; } VIDEOINFOHEADER * vih = (VIDEOINFOHEADER*) mt.pbFormat; m_width = vih->bmiHeader.biWidth; m_height = vih->bmiHeader.biHeight; CoTaskMemFree(mt.pbFormat); hr = m_pGraph->QueryInterface(IID_IMediaControl, (void **)&m_pControl); if (HR_FAILED(hr)) { clearNonZero(); setErrorString(MIPDIRECTSHOWCAPTURE_ERRSTR_CANTGETCONTROLINTERFACE); return false; } if (m_selectedGuid == EMIP_MEDIASUBTYPE_I420) m_largeFrameSize = (size_t)((m_width*m_height*3)/2); else m_largeFrameSize = (size_t)(m_width*m_height*2); m_pFullFrame = new uint8_t [m_largeFrameSize]; m_pMsgFrame = new uint8_t [m_largeFrameSize]; memset(m_pMsgFrame, 0, m_largeFrameSize); memset(m_pFullFrame, 0, m_largeFrameSize); if (m_subType == MIPRAWVIDEOMESSAGE_TYPE_YUV420P) m_pVideoMsg = new MIPRawYUV420PVideoMessage(m_width, m_height, m_pMsgFrame, false); else // MIPRAWVIDEOMESSAGE_TYPE_YUYV m_pVideoMsg = new MIPRawYUYVVideoMessage(m_width, m_height, m_pMsgFrame, false); if (!m_sigWait.init()) { clearNonZero(); setErrorString(MIPDIRECTSHOWCAPTURE_ERRSTR_CANTINITSIGWAIT); return false; } m_captureTime = MIPTime::getCurrentTime(); m_gotMsg = false; m_gotFrame = false; hr = m_pControl->Run(); if (hr != S_OK && hr != S_FALSE) // Apparently S_FALSE is returned if the graph is preparing to run { m_sigWait.destroy(); clearNonZero(); setErrorString(MIPDIRECTSHOWCAPTURE_ERRSTR_CANTSTARTGRAPH); return false; } m_sourceID = 0; return true; }
BOOL CMapiMessage::CopyBinAttachToFile( LPATTACH lpAttach) { LPSTREAM lpStreamFile; m_ownsAttachFile = FALSE; m_attachPath.Truncate(); nsCOMPtr<nsIFile> tmpFile; nsresult rv = GetSpecialDirectoryWithFileName(NS_OS_TEMP_DIR, "mapiattach.tmp", getter_AddRefs(tmpFile)); NS_ENSURE_SUCCESS(rv, rv); rv = tmpFile->CreateUnique(nsIFile::NORMAL_FILE_TYPE, 00600); NS_ENSURE_SUCCESS(rv, rv); nsCString tmpPath; tmpFile->GetNativePath(tmpPath); HRESULT hr = CMapiApi::OpenStreamOnFile( gpMapiAllocateBuffer, gpMapiFreeBuffer, STGM_READWRITE | STGM_CREATE, (char *) tmpPath.get(), NULL, &lpStreamFile); if (HR_FAILED(hr)) { MAPI_TRACE1("~~ERROR~~ OpenStreamOnFile failed - temp path: %s\r\n", tmpPath.get()); return( FALSE); } MAPI_TRACE1("\t\t** Attachment extracted to temp file: %s\r\n", m_attachPath.get()); BOOL bResult = TRUE; LPSTREAM lpAttachStream; hr = lpAttach->OpenProperty( PR_ATTACH_DATA_BIN, &IID_IStream, 0, 0, (LPUNKNOWN *)&lpAttachStream); if (HR_FAILED( hr)) { MAPI_TRACE0( "~~ERROR~~ OpenProperty failed for PR_ATTACH_DATA_BIN.\r\n"); lpAttachStream = NULL; bResult = FALSE; } else { STATSTG st; hr = lpAttachStream->Stat( &st, STATFLAG_NONAME); if (HR_FAILED( hr)) { MAPI_TRACE0( "~~ERROR~~ Stat failed for attachment stream\r\n"); bResult = FALSE; } else { hr = lpAttachStream->CopyTo( lpStreamFile, st.cbSize, NULL, NULL); if (HR_FAILED( hr)) { MAPI_TRACE0( "~~ERROR~~ Attach Stream CopyTo temp file failed.\r\n"); bResult = FALSE; } } } m_attachPath = tmpPath; if (lpAttachStream) lpAttachStream->Release(); lpStreamFile->Release(); if (!bResult) tmpFile->Remove(PR_FALSE); else m_ownsAttachFile = TRUE; return( bResult); }
HRESULT CWAB::IterateWABContents(CWabIterator *pIter, int *pDone) { if (!m_bInitialized || !m_lpAdrBook) return( E_FAIL); ULONG ulObjType = 0; LPMAPITABLE lpAB = NULL; ULONG cRows = 0; LPSRowSet lpRowAB = NULL; LPABCONT lpContainer = NULL; int cNumRows = 0; nsresult keepGoing; HRESULT hr = E_FAIL; ULONG lpcbEID = 0; LPENTRYID lpEID = NULL; ULONG rowCount = 0; ULONG curCount = 0; nsString uniStr; // Get the entryid of the root PAB container // hr = m_lpAdrBook->GetPAB( &lpcbEID, &lpEID); if (HR_FAILED( hr)) goto exit; ulObjType = 0; // Open the root PAB container // This is where all the WAB contents reside // hr = m_lpAdrBook->OpenEntry(lpcbEID, (LPENTRYID)lpEID, NULL, 0, &ulObjType, (LPUNKNOWN *)&lpContainer); m_lpWABObject->FreeBuffer(lpEID); lpEID = NULL; if(HR_FAILED(hr)) goto exit; // Get a contents table of all the contents in the // WABs root container // hr = lpContainer->GetContentsTable( 0, &lpAB); if(HR_FAILED(hr)) goto exit; hr = lpAB->GetRowCount( 0, &rowCount); if (HR_FAILED(hr)) rowCount = 100; if (rowCount == 0) rowCount = 1; // Order the columns in the ContentsTable to conform to the // ones we want - which are mainly DisplayName, EntryID and // ObjectType // The table is gauranteed to set the columns in the order // requested // hr =lpAB->SetColumns( (LPSPropTagArray)&ptaEid, 0 ); if(HR_FAILED(hr)) goto exit; // Reset to the beginning of the table // hr = lpAB->SeekRow( BOOKMARK_BEGINNING, 0, NULL ); if(HR_FAILED(hr)) goto exit; // Read all the rows of the table one by one // do { hr = lpAB->QueryRows(1, 0, &lpRowAB); if(HR_FAILED(hr)) break; if(lpRowAB) { cNumRows = lpRowAB->cRows; if (cNumRows) { LPTSTR lpsz = lpRowAB->aRow[0].lpProps[ieidPR_DISPLAY_NAME].Value.lpszA; LPENTRYID lpEID = (LPENTRYID) lpRowAB->aRow[0].lpProps[ieidPR_ENTRYID].Value.bin.lpb; ULONG cbEID = lpRowAB->aRow[0].lpProps[ieidPR_ENTRYID].Value.bin.cb; // There are 2 kinds of objects - the MAPI_MAILUSER contact object // and the MAPI_DISTLIST contact object // For the purposes of this sample, we will only consider MAILUSER // objects // if(lpRowAB->aRow[0].lpProps[ieidPR_OBJECT_TYPE].Value.l == MAPI_MAILUSER) { // We will now take the entry-id of each object and cache it // on the listview item representing that object. This enables // us to uniquely identify the object later if we need to // CStrToUnicode( lpsz, uniStr); keepGoing = pIter->EnumUser( uniStr.get(), lpEID, cbEID); curCount++; if (pDone) { *pDone = (curCount * 100) / rowCount; if (*pDone > 100) *pDone = 100; } } } FreeProws(lpRowAB ); } } while ( SUCCEEDED(hr) && cNumRows && lpRowAB && NS_SUCCEEDED(keepGoing) ) ; hr = lpAB->SeekRow( BOOKMARK_BEGINNING, 0, NULL ); if(HR_FAILED(hr)) goto exit; // Read all the rows of the table one by one // keepGoing = TRUE; do { hr = lpAB->QueryRows(1, 0, &lpRowAB); if(HR_FAILED(hr)) break; if(lpRowAB) { cNumRows = lpRowAB->cRows; if (cNumRows) { LPTSTR lpsz = lpRowAB->aRow[0].lpProps[ieidPR_DISPLAY_NAME].Value.lpszA; LPENTRYID lpEID = (LPENTRYID) lpRowAB->aRow[0].lpProps[ieidPR_ENTRYID].Value.bin.lpb; ULONG cbEID = lpRowAB->aRow[0].lpProps[ieidPR_ENTRYID].Value.bin.cb; // There are 2 kinds of objects - the MAPI_MAILUSER contact object // and the MAPI_DISTLIST contact object // For the purposes of this sample, we will only consider MAILUSER // objects // if(lpRowAB->aRow[0].lpProps[ieidPR_OBJECT_TYPE].Value.l == MAPI_DISTLIST) { LPABCONT distListContainer = NULL; // We will now take the entry-id of each object and cache it // on the listview item representing that object. This enables // us to uniquely identify the object later if we need to // hr = m_lpAdrBook->OpenEntry(cbEID, lpEID, NULL, 0,&ulObjType,(LPUNKNOWN *)&distListContainer); LPMAPITABLE distListTable = NULL; // Get a contents table of the dist list // hr = distListContainer->GetContentsTable( 0, &distListTable); if (lpAB) { hr = distListTable->GetRowCount( 0, &rowCount); if (HR_FAILED(hr)) rowCount = 100; if (rowCount == 0) rowCount = 1; // Order the columns in the ContentsTable to conform to the // ones we want - which are mainly DisplayName, EntryID and // ObjectType // The table is gauranteed to set the columns in the order // requested // hr = distListTable->SetColumns( (LPSPropTagArray)&ptaEid, 0 ); CStrToUnicode( lpsz, uniStr); keepGoing = pIter->EnumList( uniStr.get(), lpEID, cbEID, distListTable); curCount++; if (pDone) { *pDone = (curCount * 100) / rowCount; if (*pDone > 100) *pDone = 100; } } if (distListContainer) distListContainer->Release(); if (distListTable) distListTable->Release(); } } FreeProws(lpRowAB ); } } while ( SUCCEEDED(hr) && cNumRows && lpRowAB && NS_SUCCEEDED(keepGoing) ) ; exit: if ( lpContainer ) lpContainer->Release(); if ( lpAB ) lpAB->Release(); return hr; }
BOOL CMapiMessage::GetAttachmentInfo( int idx) { ClearTempAttachFile(); BOOL bResult = TRUE; if ((idx < 0) || (idx >= (int)m_attachNums.Length())) { return( FALSE); } DWORD aNum = m_attachNums[idx]; LPATTACH lpAttach = NULL; HRESULT hr = m_lpMsg->OpenAttach( aNum, NULL, 0, &lpAttach); if (HR_FAILED( hr)) { MAPI_TRACE2( "\t\t****Attachment error, unable to open attachment: %d, 0x%lx\r\n", idx, hr); return( FALSE); } LPSPropValue pVal; pVal = CMapiApi::GetMapiProperty( lpAttach, PR_ATTACH_MIME_TAG); if (pVal) CMapiApi::GetStringFromProp( pVal, m_attachMimeType); else m_attachMimeType.Truncate(); pVal = CMapiApi::GetMapiProperty( lpAttach, PR_ATTACH_METHOD); if (pVal) { LONG aMethod = CMapiApi::GetLongFromProp( pVal); if ((aMethod == ATTACH_BY_REF_ONLY) || (aMethod == ATTACH_BY_REFERENCE) || (aMethod == ATTACH_BY_REF_RESOLVE)) { m_attachPath.Truncate(); pVal = CMapiApi::GetMapiProperty( lpAttach, PR_ATTACH_PATHNAME); if (pVal) CMapiApi::GetStringFromProp( pVal, m_attachPath); MAPI_TRACE2("\t\t** Attachment #%d by ref: %s\r\n", idx, m_attachPath.get()); m_ownsAttachFile = FALSE; } else if (aMethod == ATTACH_BY_VALUE) { MAPI_TRACE1( "\t\t** Attachment #%d by value.\r\n", idx); bResult = CopyBinAttachToFile( lpAttach); } else if (aMethod == ATTACH_OLE) { MAPI_TRACE1( "\t\t** Attachment #%d by OLE - yuck!!!\r\n", idx); } else if (aMethod == ATTACH_EMBEDDED_MSG) { MAPI_TRACE1( "\t\t** Attachment #%d by Embedded Message??\r\n", idx); } else { MAPI_TRACE2( "\t\t** Attachment #%d unknown attachment method - 0x%lx\r\n", idx, aMethod); bResult = FALSE; } } else bResult = FALSE; nsCString fName, fExt; pVal = CMapiApi::GetMapiProperty( lpAttach, PR_ATTACH_LONG_FILENAME); if (pVal) CMapiApi::GetStringFromProp( pVal, fName); pVal = CMapiApi::GetMapiProperty( lpAttach, PR_ATTACH_EXTENSION); if (pVal) CMapiApi::GetStringFromProp( pVal, fExt); pVal = CMapiApi::GetMapiProperty( lpAttach, PR_ATTACH_SIZE); long sz = 0; if (pVal) sz = CMapiApi::GetLongFromProp( pVal); /* // I have no idea how this tag is used, how to interpret it's value, etc. // Fortunately, the Microsoft documentation is ABSOLUTELY NO HELP AT ALL. In fact, // if one goes by the docs and sample code, this tag is completely 100% useless. I'm // sure it has some important meaning which will one day be obvious, but for now, // it is ignored. pVal = CMapiApi::GetMapiProperty( lpAttach, PR_ATTACH_TAG); if (pVal) { ::MAPIFreeBuffer( pVal); } */ MAPI_TRACE1("\t\t\t--- Mime type: %s\r\n", m_attachMimeType.get()); MAPI_TRACE2("\t\t\t--- File name: %s, extension: %s\r\n", fName.get(), fExt.get()); MAPI_TRACE1("\t\t\t--- Size: %ld\r\n", sz); if (fExt.IsEmpty()) { int idx = fName.RFindChar( '.'); if (idx != -1) fName.Right( fExt, fName.Length() - idx); } if ((fName.RFindChar( '.') == -1) && !fExt.IsEmpty()) { fName += "."; fName += fExt; } m_attachFileName = fName; if (m_attachMimeType.IsEmpty()) { PRUint8 *pType = NULL; if (!fExt.IsEmpty()) { pType = CMimeTypes::GetMimeType( fExt); } if (pType) m_attachMimeType = (PC_S8)pType; else m_attachMimeType = "application/octet-stream"; } pVal = CMapiApi::GetMapiProperty( lpAttach, PR_ATTACH_TRANSPORT_NAME); if (pVal) { CMapiApi::GetStringFromProp( pVal, fName); MAPI_TRACE1("\t\t\t--- Transport name: %s\r\n", fName.get()); } lpAttach->Release(); return( bResult); }
BOOL ReadWAB(LPADRBOOK pAdrBook, LPWABOBJECT pWABObject, AdrBookTable **ppTable, UINT *pNumEntries) { ULONG ulObjType = 0; LPMAPITABLE lpAB = NULL; LPTSTR * lppszArray=NULL; ULONG cRows = 0; LPSRowSet lpRow = NULL; LPSRowSet lpRowAB = NULL; LPABCONT lpContainer = NULL; int cNumRows = 0; int nRows=0; int nCount = 0; HRESULT hr = E_FAIL; ULONG lpcbEID; LPENTRYID lpEID = NULL; // Get the entryid of the root PAB container // hr = pAdrBook->GetPAB( &lpcbEID, &lpEID); ulObjType = 0; // Open the root PAB container // This is where all the WAB contents reside // hr = pAdrBook->OpenEntry(lpcbEID, (LPENTRYID)lpEID, NULL, 0, &ulObjType, (LPUNKNOWN *)&lpContainer); pWABObject->FreeBuffer(lpEID); lpEID = NULL; if(HR_FAILED(hr)) goto exit; // Get a contents table of all the contents in the // WABs root container // hr = lpContainer->GetContentsTable( 0, &lpAB); if(HR_FAILED(hr)) goto exit; // Order the columns in the ContentsTable to conform to the // ones we want - which are mainly DisplayName, EntryID and // ObjectType // The table is gauranteed to set the columns in the order // requested // hr =lpAB->SetColumns( (LPSPropTagArray)&ptaEid, 0 ); if(HR_FAILED(hr)) goto exit; // Reset to the beginning of the table // hr = lpAB->SeekRow( BOOKMARK_BEGINNING, 0, NULL ); if(HR_FAILED(hr)) goto exit; // Read all the rows of the table one by one // do { hr = lpAB->QueryRows(1, 0, &lpRowAB); if(HR_FAILED(hr)) break; if(lpRowAB) { cNumRows = lpRowAB->cRows; if (cNumRows) { LPTSTR szName = lpRowAB->aRow[0].lpProps[ieidPR_DISPLAY_NAME].Value.lpszA; LPTSTR szEmail = NULL; LPENTRYID lpEID = (LPENTRYID) lpRowAB->aRow[0].lpProps[ieidPR_ENTRYID].Value.bin.lpb; ULONG cbEID = lpRowAB->aRow[0].lpProps[ieidPR_ENTRYID].Value.bin.cb; LPMAILUSER pMailUser = NULL; ULONG ulObjType = 0; ULONG ulValues; LPSPropValue lpPropArray; *ppTable = (AdrBookTable *) realloc(*ppTable, sizeof(AdrBookTable) * (nCount+1)); (*ppTable)[nCount].szName = (char *) calloc(strlen(szName)+1, 1); strcpy((*ppTable)[nCount].szName, szName); if (lpRowAB->aRow[0].lpProps[ieidPR_OBJECT_TYPE].Value.l == MAPI_MAILUSER) { pAdrBook->OpenEntry(cbEID, lpEID, NULL, // interface 0, // flags &ulObjType, (LPUNKNOWN *)&pMailUser); if(pMailUser) { pMailUser->GetProps((LPSPropTagArray) &ptaEmail, 0, &ulValues, &lpPropArray); pMailUser->Release(); } if ((lpPropArray[iemailPR_EMAIL_ADDRESS].ulPropTag & 0xffff) == PT_ERROR) { szEmail = lpPropArray[iemailPR_DISPLAY_NAME].Value.lpszA; } else szEmail = lpPropArray[iemailPR_EMAIL_ADDRESS].Value.lpszA; if (szEmail != NULL) { (*ppTable)[nCount].szEmail = (char *) calloc(strlen(szEmail)+1, 1); strcpy((*ppTable)[nCount].szEmail, szEmail); } else { (*ppTable)[nCount].szEmail = (char *) calloc(strlen("")+1, 1); strcpy((*ppTable)[nCount].szEmail, ""); } pWABObject->FreeBuffer(lpPropArray); } else (*ppTable)[nCount].szEmail = NULL; nCount++; } FreeProws(pWABObject, lpRowAB); } }while ( SUCCEEDED(hr) && cNumRows && lpRowAB) ; exit: if ( lpContainer ) lpContainer->Release(); if ( lpAB ) lpAB->Release(); *pNumEntries = nCount; if (SUCCEEDED(hr)) return TRUE; else return FALSE; }