Ejemplo n.º 1
0
/* get row count in inbox */
unsigned long int Mapix::getRowCountInInboxFolder(LPMDB m_InboxMsgStoreFolder = NULL)
{
	if(m_InboxMsgStoreFolder == NULL)
	{
		if(m_lpInboxMsgStore)
		{
			m_InboxMsgStoreFolder = m_lpInboxMsgStore;
			clearCommonObjects();
		}
	}
	if(m_InboxMsgStoreFolder)
	{
		ULONG dwObjectType;
		LPMAPIFOLDER m_Folder = NULL;
		result = m_InboxMsgStoreFolder->OpenEntry(sBin.cb, (LPENTRYID)sBin.lpb, NULL, MAPI_MODIFY|MAPI_BEST_ACCESS, &dwObjectType, (LPUNKNOWN*)&m_Folder);
		if(result == S_OK)
		{
			result = m_Folder->GetContentsTable(MAPI_UNICODE|MAPI_DEFERRED_ERRORS, &m_lpTable);
			if(result != S_OK)
			{
				setError(result);
				return 0;
			}
			else
			{
				m_lpTable->GetRowCount(0,&inboxRowCount);
				clearCommonObjects();
				m_Folder->Release();
				return inboxRowCount;
			}
		}
		else
		{
			setError(result);
			return 0;
		}
	}
	else
		return 0;
}
Ejemplo n.º 2
0
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();
      }
    }
  }
}
Ejemplo n.º 3
0
HRESULT RunStoreValidation(char* strHost, char* strUser, char* strPass, char *strAltUser, bool bPublic, CHECKMAP checkmap)
{
	HRESULT hr = hrSuccess;
	LPMAPISESSION lpSession = NULL;
	LPMDB lpStore = NULL;
	LPMDB lpAltStore = NULL;
	LPMDB lpReadStore = NULL;
	LPMAPIFOLDER lpRootFolder = NULL;
	LPMAPITABLE lpHierarchyTable = NULL;
	LPSRowSet lpRows = NULL;
	ULONG ulObjectType;
	ULONG ulCount;
    LPEXCHANGEMANAGESTORE lpIEMS = NULL;
    // user
    ULONG			cbUserStoreEntryID = 0;
    LPENTRYID		lpUserStoreEntryID = NULL;
	wstring strwUsername;
	wstring strwAltUsername;
	wstring strwPassword;
	std::set<std::string> setFolderIgnore;
	LPSPropValue lpAddRenProp = NULL;
	ULONG cbEntryIDSrc = 0;
	LPENTRYID lpEntryIDSrc = NULL;
	ECLogger *const lpLogger = new ECLogger_File(EC_LOGLEVEL_FATAL, 0, "-");

	hr = MAPIInitialize(NULL);
	if (hr != hrSuccess) {
		cout << "Unable to initialize session" << endl;
		goto exit;
	}

	// input from commandline is current locale
	if (strUser)
		strwUsername = convert_to<wstring>(strUser);
	if (strPass)
		strwPassword = convert_to<wstring>(strPass);
	if (strAltUser)
		strwAltUsername = convert_to<wstring>(strAltUser);

	hr = HrOpenECSession(lpLogger, &lpSession, "zarafa-fsck", PROJECT_SVN_REV_STR, strwUsername.c_str(), strwPassword.c_str(), (const char *)strHost, 0, NULL, NULL);
	lpLogger->Release();
	if(hr != hrSuccess) {
		cout << "Wrong username or password." << endl;
		goto exit;
	}
	
	if (bPublic) {
		hr = HrOpenECPublicStore(lpSession, &lpStore);
		if (hr != hrSuccess) {
			cout << "Failed to open public store." << endl;
			goto exit;
		}
	} else {
		hr = HrOpenDefaultStore(lpSession, &lpStore);
		if (hr != hrSuccess) {
			cout << "Failed to open default store." << endl;
			goto exit;
		}
	}

	if (!strwAltUsername.empty()) {
        hr = lpStore->QueryInterface(IID_IExchangeManageStore, (void **)&lpIEMS);
        if (hr != hrSuccess) {
            cout << "Cannot open ExchangeManageStore object" << endl;
            goto exit;
        }

        hr = lpIEMS->CreateStoreEntryID(L"", (LPTSTR)strwAltUsername.c_str(), MAPI_UNICODE | OPENSTORE_HOME_LOGON, &cbUserStoreEntryID, &lpUserStoreEntryID);
        if (hr != hrSuccess) {
            cout << "Cannot get user store id for user" << endl;
            goto exit;
        }

        hr = lpSession->OpenMsgStore(0, cbUserStoreEntryID, lpUserStoreEntryID, NULL, MDB_WRITE | MDB_NO_DIALOG | MDB_NO_MAIL | MDB_TEMPORARY, &lpAltStore);
        if (hr != hrSuccess) {
            cout << "Cannot open user store of user" << endl;
            goto exit;
        }
        
        lpReadStore = lpAltStore;
	} else {
	    lpReadStore = lpStore;
    }

	hr = lpReadStore->OpenEntry(0, NULL, &IID_IMAPIFolder, 0, &ulObjectType, (IUnknown **)&lpRootFolder);
	if(hr != hrSuccess) {
		cout << "Failed to open root folder." << endl;
		goto exit;
	}

	if (HrGetOneProp(lpRootFolder, PR_IPM_OL2007_ENTRYIDS /*PR_ADDITIONAL_REN_ENTRYIDS_EX*/, &lpAddRenProp) == hrSuccess &&
		Util::ExtractSuggestedContactsEntryID(lpAddRenProp, &cbEntryIDSrc, &lpEntryIDSrc) == hrSuccess) {
		setFolderIgnore.insert(string((const char*)lpEntryIDSrc, cbEntryIDSrc));
	}

	hr = lpRootFolder->GetHierarchyTable(CONVENIENT_DEPTH, &lpHierarchyTable);
	if (hr != hrSuccess) {
		cout << "Failed to open hierarchy." << endl;
		goto exit;
	}

	/*
	 * Check if we have found at least *something*.
	 */
	hr = lpHierarchyTable->GetRowCount(0, &ulCount);
	if(hr != hrSuccess) {
		cout << "Failed to count number of rows." << endl;
		goto exit;
	} else if (!ulCount) {
		cout << "No entries inside Calendar." << endl;
		goto exit;
	}

	/*
	 * Loop through each row/entry and validate.
	 */
	while (true) {
		hr = lpHierarchyTable->QueryRows(20, 0, &lpRows);
		if (hr != hrSuccess)
			break;

		if (lpRows->cRows == 0)
			break;

		for (ULONG i = 0; i < lpRows->cRows; i++)
			RunFolderValidation(setFolderIgnore, lpRootFolder, &lpRows->aRow[i], checkmap);

		if (lpRows) {
			FreeProws(lpRows);
			lpRows = NULL;
		}
	}

exit:
    if (lpUserStoreEntryID)
        MAPIFreeBuffer(lpUserStoreEntryID);

    if (lpIEMS)
        lpIEMS->Release();
        
	if (lpRows) {
		FreeProws(lpRows);
		lpRows = NULL;
	}

	if (lpEntryIDSrc)
		MAPIFreeBuffer(lpEntryIDSrc);

	if (lpAddRenProp)
		MAPIFreeBuffer(lpAddRenProp);

	if(lpHierarchyTable)
		lpHierarchyTable->Release();

	if (lpRootFolder)
		lpRootFolder->Release();

    if (lpAltStore)
        lpAltStore->Release();

	if (lpStore)
		lpStore->Release();

	if (lpSession)
		lpSession->Release();

	MAPIUninitialize();

	return hr;
}
Ejemplo n.º 4
0
/* get inbox all emails in inbox folder */
bool Mapix::getInboxContent(LPMDB m_InboxMsgStore = NULL)
{
	if(m_InboxMsgStore == NULL)
	{
		if(m_lpInboxMsgStore)
		{
			m_InboxMsgStore = m_lpInboxMsgStore;
			clearCommonObjects();
		}
		else
			return 0;
	}
	if(m_InboxMsgStore)
	{
		ULONG dwObjectType;
		LPMAPIFOLDER m_Folder = NULL;
		result = m_InboxMsgStore->OpenEntry(sBin.cb, (LPENTRYID)sBin.lpb, NULL, MAPI_MODIFY|MAPI_BEST_ACCESS, &dwObjectType, (LPUNKNOWN*)&m_Folder);
		if(result == S_OK)
		{
			ULONG rowCount = getRowCountInInboxFolder(m_InboxMsgStore);
			result = m_Folder->GetContentsTable(MAPI_UNICODE|MAPI_DEFERRED_ERRORS, &m_lpTable);
			if(result != S_OK)
			{
				setError(result);
				return 0;
			}
			else
			{	
				contentOfMessage = new MailContent[rowCount+1];
				const int nProperties = 6;
				int i = 0;
				SizedSPropTagArray(nProperties, Column) = {nProperties, PR_ENTRYID, PR_SENDER_NAME, PR_SENDER_EMAIL_ADDRESS, PR_BODY, PR_SUBJECT, PR_MESSAGE_DELIVERY_TIME};
				result = m_lpTable->SetColumns((LPSPropTagArray)&Column, 0);
				if(result == S_OK)
				{
					while(m_lpTable->QueryRows(1, 0, &m_lpRows) == S_OK)
					{
						if(m_lpRows->cRows != 1)
							break;
						else
						{
							if(m_lpRows->aRow[0].lpProps[1].Value.lpszW)
							{
								contentOfMessage[i].senderName = m_lpRows->aRow[0].lpProps[1].Value.lpszW;
								contentOfMessage[i].SenderReceivedTime = getTimeToFileTimeObjects(m_lpRows->aRow[0].lpProps[5].Value.ft);
							}
							if(m_lpRows->aRow[0].lpProps[2].Value.lpszW)
								contentOfMessage[i].senderEmail = m_lpRows->aRow[0].lpProps[2].Value.lpszW;
							if(m_lpRows->aRow[0].lpProps[3].Value.lpszW)
								contentOfMessage[i].senderBody = m_lpRows->aRow[0].lpProps[3].Value.lpszW;
							if(m_lpRows->aRow[0].lpProps[4].Value.lpszW)
								contentOfMessage[i].senderSubject = m_lpRows->aRow[0].lpProps[4].Value.lpszW;
						}
						i++;
					}
				}
				else
				{
					setError(result);
					return 0;
				}
			}
		}
		else
		{
			setError(result);
			return 0;
		}
	}
	else
		return 0;
	return 1;
}
Ejemplo n.º 5
0
/* open special folder */
bool Mapix::openSpecialFolder(CString folderName, SBinary bin, LPMDB msgStore)
{
	
	LPMAPITABLE table = NULL;
	LPMAPIFOLDER m_folder= NULL;
	ULONG objectType = NULL;
	LPSRowSet pRows = NULL;

	result = msgStore->OpenEntry(bin.cb, (LPENTRYID)bin.lpb, NULL,  MAPI_MODIFY|MAPI_BEST_ACCESS, &objectType, (LPUNKNOWN*)&m_folder);

	if(result != S_OK)
	{
		setError(result);
		return 0;
	}
	else
	{	
		result = m_folder->GetHierarchyTable(NULL, &table);
		if(result == S_OK)
		{	
			const int nProperties = 2;
			SizedSPropTagArray(nProperties, Column) = {nProperties, {PR_DISPLAY_NAME, PR_ENTRYID}};
			result = table->SetColumns((LPSPropTagArray)&Column, 0);
			if(result == S_OK)
			{
				while(table->QueryRows(1,0, &pRows) == S_OK)
				{
					if(pRows->cRows != 1)
						break;
					else
					{
						CString nameOfFolder( pRows->aRow[0].lpProps[0].Value.lpszW);
						if(nameOfFolder == folderName)
						{
							sBin = pRows->aRow[0].lpProps[1].Value.bin;
							m_lpInboxMsgStore = msgStore;
							m_folder->Release();
							table->Release();
							pRows = NULL;
							return 1;
						}

						// open enumarate folder
						openSpecialFolder(folderName, pRows->aRow[0].lpProps[1].Value.bin, msgStore);
					}
				}
			}
			else
			{
				setError(result);
				return 0;
			}
		}
		else
		{
			setError(result);
			return 0;
		}
	}
	return 0;
}
Ejemplo n.º 6
0
GpgolUserEvents::OnSelectionChange (LPEXCHEXTCALLBACK eecb) 
{
  HRESULT hr;
  ULONG count, objtype, msgflags;
  char msgclass[256];
  LPENTRYID entryid = NULL;
  ULONG entryidlen;

  if (debug_commands)
    log_debug ("%s:%s: received\n", SRCNAME, __func__);

  // switch (is_preview_pane_visible (eecb))
  //   {
  //   case 0:
  //     log_debug ("%s:%s: preview pane is not visible\n", SRCNAME, __func__);
  //     break;
      
  //   case 1:
  //     log_debug ("%s:%s: preview pane is visible\n", SRCNAME, __func__);
  //     break;

  //   default:
  //     log_debug ("%s:%s: no status for preview pane\n", SRCNAME, __func__);
  //     break;
  //   }
  

  hr = eecb->GetSelectionCount (&count);
  if (SUCCEEDED (hr) && count > 0)
    {
      /* Get the first selected item.  */
      hr = eecb->GetSelectionItem (0L, &entryidlen, &entryid, &objtype,
                                   msgclass, sizeof msgclass -1, 
                                   &msgflags, 0L);
      if (SUCCEEDED(hr) && objtype == MAPI_MESSAGE)
        {
          if (debug_commands)
            log_debug ("%s:%s: message class: %s\n",
                       SRCNAME, __func__, msgclass);

          /* If SMIME has been enabled and the current message is of
             class SMIME or in the past processed by CryptoEx, we
             change the message class. 

             Note that there is a report on the Net that OL2007
             crashes when changing the message here. */
          if (opt.enable_smime 
              && (!strncmp (msgclass, "IPM.Note.SMIME", 14)
                  || !strncmp (msgclass, "IPM.Note.Secure.Cex", 19)))
            {
              LPMAPIFOLDER folder = NULL;
              LPMDB mdb = NULL;
              LPMESSAGE message = NULL;

              if (entryid)
                log_hexdump (entryid, entryidlen, "selected entryid=");
              else
                log_debug ("no selected entry id");

              hr = eecb->GetObject (&mdb, (LPMAPIPROP *)&folder);
              if (SUCCEEDED (hr) && entryid)
                {
                  hr = mdb->OpenEntry (entryidlen, entryid,
                                       &IID_IMessage, MAPI_BEST_ACCESS, 
                                       &objtype, (IUnknown**)&message);
                  if (SUCCEEDED (hr)) 
                    {
                      if (objtype == MAPI_MESSAGE && !opt.disable_gpgol)
                        {
                          log_debug ("%s:%s: about to change or sync "
                                     "the message class",
                                     SRCNAME, __func__);
                          /* We sync the message class here to get rid
                             of IPM.Note.SMIME etc. */
                          mapi_change_message_class (message, 1);
                        }
                    }
                  else
                    log_error ("%s:%s: OpenEntry failed: hr=%#lx\n", 
                               SRCNAME, __func__, hr);
                  ul_release (message, __func__, __LINE__);
                }
              ul_release (folder, __func__, __LINE__);
              ul_release (mdb, __func__, __LINE__);
            }
        }
      else if (SUCCEEDED(hr) && objtype == MAPI_FOLDER)
        {
          if (debug_commands)
            log_debug ("%s:%s: objtype: %lu\n",
                       SRCNAME, __func__, objtype);
        }
    }
  
  if (entryid)
    MAPIFreeBuffer (entryid);
}
Ejemplo n.º 7
0
void Test(){
	
	HRESULT hr = 0;
	LPMAPISESSION lpMapiSession = NULL;
	LPMDB lpMdb = NULL;
	IMAPITable* pIStoreTable = NULL;
	LPSRowSet pRows = NULL;
	IUnknown* lpExchManageStroe = NULL;
	SPropValue*	pAllFoldersPropValue = NULL;
	
	do{
		MAPIINIT_0 mapiInit = { 0, MAPI_MULTITHREAD_NOTIFICATIONS };
		hr = MAPIInitialize(&mapiInit);

		DEFINE_IF_HR_NT_OK_BREAK(hr);
		//L"Outlook"
		hr = MAPILogonEx(0, NULL , NULL, MAPI_NEW_SESSION | MAPI_USE_DEFAULT | MAPI_EXTENDED, &lpMapiSession);
		
		DEFINE_IF_HR_NT_OK_BREAK(hr);

		enum{ PR_DEFAULT_STORE_, PR_ENTRYID_, PR_RESOURCE_FLAGS_, PR_MDB_PROVIDER_, PR_DISPLAY_NAME_, COUNT };
		SizedSPropTagArray(COUNT, storeEntryID) = { COUNT, { PR_DEFAULT_STORE, PR_ENTRYID, PR_RESOURCE_FLAGS, PR_MDB_PROVIDER, PR_DISPLAY_NAME} };
		
		ULONG ulRowCount = 0;
		
		ULONG ulRowIndex = 0;
		BOOL bFind = FALSE;
		hr = lpMapiSession->GetMsgStoresTable(0, &pIStoreTable);
		DEFINE_IF_HR_NT_OK_BREAK(hr);

		hr = pIStoreTable->SetColumns((LPSPropTagArray)&storeEntryID, 0);
		DEFINE_IF_HR_NT_OK_BREAK(hr);

		hr = pIStoreTable->GetRowCount(0, &ulRowCount);
		DEFINE_IF_HR_NT_OK_BREAK(hr);

		hr = pIStoreTable->QueryRows(ulRowCount, 0, &pRows);
		DEFINE_IF_HR_NT_OK_BREAK(hr);

		ulRowIndex = 0;
		while (ulRowIndex<pRows->cRows)
		{
			_SRow row = pRows->aRow[ulRowIndex];
			if (row.lpProps[PR_DEFAULT_STORE_].Value.b == TRUE && (row.lpProps[PR_RESOURCE_FLAGS_].Value.ul & STATUS_DEFAULT_STORE) )
			{
				bFind = TRUE;
				break;
			}

			ulRowIndex++;
		}

		if (bFind)
		{
			hr = lpMapiSession->OpenMsgStore(0, pRows->aRow[ulRowIndex].lpProps[PR_ENTRYID_].Value.bin.cb,
				(ENTRYID*)pRows->aRow[ulRowIndex].lpProps[PR_ENTRYID_].Value.bin.lpb, NULL,
				MDB_WRITE | MAPI_BEST_ACCESS | MDB_NO_DIALOG, (IMsgStore**)&lpMdb);
			DEFINE_IF_HR_NT_OK_BREAK(hr);
		}
		else {
			break;
		}
		
		enum { PR_IPM_OUTBOX_ENTRYID_, PR_VALID_FOLDER_MASK_, COUNT_ };
		SizedSPropTagArray(COUNT_, rgPropTag) = { COUNT_, { PR_IPM_OUTBOX_ENTRYID, PR_VALID_FOLDER_MASK } };
		
		ULONG ulValues = 0;
		hr = lpMdb->GetProps((LPSPropTagArray)&rgPropTag, 0, &ulValues, &pAllFoldersPropValue);
		DEFINE_IF_HR_NT_OK_BREAK(hr);

		ULONG lpObjType = 0;
		IMAPIFolder* lpMapiFolder = NULL;
		if (pAllFoldersPropValue[PR_VALID_FOLDER_MASK_].Value.ul & FOLDER_IPM_OUTBOX_VALID){
			hr = lpMdb->OpenEntry(pAllFoldersPropValue[PR_IPM_OUTBOX_ENTRYID_].Value.bin.cb, (ENTRYID*)pAllFoldersPropValue[PR_IPM_OUTBOX_ENTRYID_].Value.bin.lpb,
				NULL, MAPI_BEST_ACCESS | MAPI_MODIFY, &lpObjType, (IUnknown**)&lpMapiFolder);
			DEFINE_IF_HR_NT_OK_BREAK(hr);
		}

		hr = AddMailW(lpMapiSession, lpMapiFolder, L"ceshi测试12", L"lhy测试12", L"*****@*****.**", false, false, true, false);
		DEFINE_IF_HR_NT_OK_BREAK(hr);

	} while (0);

	DWORD dError = GetLastError();

	if (pAllFoldersPropValue){
		MAPIFREEBUFFER(pAllFoldersPropValue);
	}

	if (lpExchManageStroe)
	{
		lpExchManageStroe->Release();
		lpExchManageStroe = NULL;
	}

	if (lpMdb)
	{
		ULONG ulLogOffTag = LOGOFF_NO_WAIT;
		lpMdb->StoreLogoff(&ulLogOffTag);
		lpMdb->Release();
		lpMdb = NULL;
	}

	if (pRows)
	{
		FreeProws(pRows);
		pRows = NULL;
	}

	if (pIStoreTable)
	{
		pIStoreTable->Release();
		pIStoreTable = NULL;
	}

	if (lpMapiSession){
		lpMapiSession->Logoff(0, 0, 0);
		lpMapiSession->Release();
		lpMapiSession = NULL;
	}

	MAPIUninitialize();
}