Exemple #1
0
HRESULT GetShortcutFolder(LPMAPISESSION lpSession, LPTSTR lpszFolderName, LPTSTR lpszFolderComment, ULONG ulFlags, LPMAPIFOLDER* lppShortcutFolder)
{
	HRESULT hr = hrSuccess;
	LPSPropValue lpPropValue = NULL;
	IMsgStore *lpMsgStore = NULL;
	IMAPIFolder *lpFolder = NULL;
	ULONG ulObjType = 0;

	hr = HrOpenDefaultStore(lpSession, &lpMsgStore);
	if(hr != hrSuccess)
		goto exit;

	// Get shortcut entryid
	hr = HrGetOneProp(lpMsgStore, PR_IPM_FAVORITES_ENTRYID, &lpPropValue);
	if(hr != hrSuccess) {

		if(hr == MAPI_E_NOT_FOUND && (ulFlags&MAPI_CREATE)) {
			// Propety not found, re-create the shortcut folder
			hr = CreateShortcutFolder(lpMsgStore, lpszFolderName, lpszFolderComment, ulFlags & MAPI_UNICODE, lppShortcutFolder);
		}
		goto exit;
	}

	// Open Shortcut folder
	hr = lpMsgStore->OpenEntry(lpPropValue->Value.bin.cb, (LPENTRYID)lpPropValue->Value.bin.lpb, &IID_IMAPIFolder, MAPI_BEST_ACCESS, &ulObjType, (LPUNKNOWN *)&lpFolder);
	if (hr != hrSuccess) {
		if(hr == MAPI_E_NOT_FOUND && (ulFlags&MAPI_CREATE)) {
			// Folder not found, re-create the shortcut folder
			hr = CreateShortcutFolder(lpMsgStore, lpszFolderName, lpszFolderComment, ulFlags & MAPI_UNICODE, lppShortcutFolder);
		}

		goto exit;
	}

	hr = lpFolder->QueryInterface(IID_IMAPIFolder, (void**)lppShortcutFolder);
	if (hr != hrSuccess)
		goto exit;

exit:
	if (lpPropValue)
		MAPIFreeBuffer(lpPropValue);

	if(lpFolder)
		lpFolder->Release();

	if(lpMsgStore)
		lpMsgStore->Release();

	return hr;
}
Exemple #2
0
HRESULT CMailRuleClient::DeleteMessage(
		IMsgStore *pMsgStore, 
		IMessage *pMsg, 
		ULONG cbMsg, 
		LPENTRYID lpMsg, 
		ULONG cbDestFolder, 
		LPENTRYID lpDestFolder, 
		ULONG *pulEventType, 
		MRCHANDLED *pHandled)
{
	HRESULT hr = S_OK;
	ENTRYLIST lst;
	SBinary sbin;
	IMAPIFolder *pFolder = NULL;
	
	hr = pMsgStore->OpenEntry(cbDestFolder, lpDestFolder, NULL, 0, NULL, (LPUNKNOWN *) &pFolder);
	if (FAILED(hr)) {
		DBG_TRACE(L"Failed opening message entry.", DBG_HIGH, TRUE);
		return hr;
	}
	
	lst.cValues = 1;
	sbin.cb = cbMsg;
	sbin.lpb = (LPBYTE) lpMsg;
	lst.lpbin = &sbin;
	
	hr = pFolder->DeleteMessages(&lst, NULL, NULL, 0);
	if (FAILED(hr)) {
		DBG_TRACE(L"Failed deleting messages.", DBG_HIGH, TRUE);
		*pulEventType = fnevObjectDeleted;
		*pHandled = MRC_HANDLED_DONTCONTINUE;
	}
	
	if (pFolder)
		pFolder->Release();

	DBG_TRACE(L"Message deleted.", DBG_NOTIFY, FALSE);
	
	return hr;
}
Exemple #3
0
/**
 * Creates an email in the inbox of the given store with given properties and addresslist for recipients
 *
 * @param[in]	lpMDB		The store of a user to create the mail in the inbox folder
 * @param[in]	cPropSize	The number of properties in lpPropArray
 * @param[in]	lpPropArray	The properties to set in the quota mail
 * @param[in]	lpAddrList	The recipients to save in the recipients table
 * @return MAPI error code
 */
HRESULT ECQuotaMonitor::SendQuotaWarningMail(IMsgStore* lpMDB, ULONG cPropSize, LPSPropValue lpPropArray, LPADRLIST lpAddrList)
{
	HRESULT hr = hrSuccess;
	IMessage *lpMessage = NULL;
	ULONG cbEntryID = 0;
	LPENTRYID lpEntryID = NULL;
	IMAPIFolder *lpInbox = NULL;
	ULONG ulObjType;

	/* Get the entry id of the inbox */
	hr = lpMDB->GetReceiveFolder((LPTSTR)"IPM", 0, &cbEntryID, &lpEntryID, NULL);
	if (hr != hrSuccess) {
		m_lpThreadMonitor->lpLogger->Log(EC_LOGLEVEL_FATAL, "Unable to resolve incoming folder, error code: 0x%08X", hr);
		goto exit;
	}

	/* Open the inbox */
	hr = lpMDB->OpenEntry(cbEntryID, lpEntryID, &IID_IMAPIFolder, MAPI_MODIFY, &ulObjType, (LPUNKNOWN *)&lpInbox);
	if (hr != hrSuccess || ulObjType != MAPI_FOLDER) {
		m_lpThreadMonitor->lpLogger->Log(EC_LOGLEVEL_FATAL, "Unable to open inbox folder, error code: 0x%08X", hr);
		if(ulObjType != MAPI_FOLDER)
			hr = MAPI_E_NOT_FOUND;
		goto exit;
	}

	/* Create a new message in the correct folder */
	hr = lpInbox->CreateMessage(NULL, 0, &lpMessage);
	if (hr != hrSuccess) {
		m_lpThreadMonitor->lpLogger->Log(EC_LOGLEVEL_FATAL, "Unable to create new message, error code: %08X", hr);
		goto exit;
	}

	hr = lpMessage->SetProps(cPropSize, lpPropArray, NULL);
	if(hr != hrSuccess) {
		m_lpThreadMonitor->lpLogger->Log(EC_LOGLEVEL_FATAL, "Unable to set properties, error code: 0x%08X", hr);
		goto exit;
	}

	hr = lpMessage->ModifyRecipients(MODRECIP_ADD, lpAddrList);
	if (hr != hrSuccess)
		goto exit;

	/* Save Message */
	hr = lpMessage->SaveChanges(KEEP_OPEN_READWRITE);
	if (hr != hrSuccess)
		goto exit;

	hr = HrNewMailNotification(lpMDB, lpMessage);
	if (hr != hrSuccess) {
		m_lpThreadMonitor->lpLogger->Log(EC_LOGLEVEL_WARNING, "Unable to send 'New Mail' notification, error code: 0x%08X", hr);
		goto exit;
	}

	hr = lpMDB->SaveChanges(KEEP_OPEN_READWRITE);
	if (hr != hrSuccess)
		goto exit;

exit:
	if (lpInbox)
		lpInbox->Release();

	if (lpEntryID)
		MAPIFreeBuffer(lpEntryID);

	if(lpMessage)
		lpMessage->Release();

	return hr;
}
Exemple #4
0
/**
 * Helper function to create a new shorcut folder and update the property 
 * PR_IPM_FAVORITES_ENTRYID on the store object.
 * If the folder already exist, it will used and update only the property
 *
 * @param lpMsgStore Pointer to the private store
 * @param lpszFolderName Pointer to a string containing the name for the shorcut folder. If NULL is passed, the folder has the default name 'Shortcut'.
 * @param lpszFolderComment Pointer to a string containing a comment associated with the shorcut folder. If NULL is passed, the folder has the default comment 'Shortcut folder'.
 * @param ulFlags MAPI_UNICODE if the folder strings are in unicode format, otherwise 0.
 * @param lppShortcutFolder Pointer to a pointer to the opened shortcut folder
 */
HRESULT CreateShortcutFolder(IMsgStore *lpMsgStore, LPTSTR lpszFolderName, LPTSTR lpszFolderComment, ULONG ulFlags, LPMAPIFOLDER* lppShortcutFolder)
{
	HRESULT hr = hrSuccess;
	IMAPIFolder *lpFolder = NULL;
	IMAPIFolder *lpNewFolder = NULL;
	ULONG ulObjType = 0;
	LPSPropValue lpProp = NULL;

	if (lpMsgStore == NULL || lppShortcutFolder == NULL) {
		hr = MAPI_E_INVALID_PARAMETER;
		goto exit;
	}

	if (lpszFolderName == NULL) {
		if (ulFlags & MAPI_UNICODE)
			lpszFolderName = (LPTSTR)L"Shortcut";
		else
			lpszFolderName = (LPTSTR)"Shortcut";
	}

	if (lpszFolderComment == NULL) {
		if (ulFlags & MAPI_UNICODE)
			lpszFolderComment = (LPTSTR)L"Shortcut folder";
		else
			lpszFolderComment = (LPTSTR)"Shortcut folder";
	}

	// Open root folder
	hr = lpMsgStore->OpenEntry(0, NULL, &IID_IMAPIFolder, MAPI_BEST_ACCESS, &ulObjType, (LPUNKNOWN *)&lpFolder);
	if (hr != hrSuccess)
		goto exit;

	hr = lpFolder->CreateFolder(FOLDER_GENERIC, lpszFolderName, lpszFolderComment, &IID_IMAPIFolder, ulFlags | OPEN_IF_EXISTS, &lpNewFolder);
	if (hr != hrSuccess)
		goto exit;

	hr = HrGetOneProp(lpNewFolder, PR_ENTRYID, &lpProp);
	if (hr != hrSuccess)
		goto exit;

	lpProp->ulPropTag = PR_IPM_FAVORITES_ENTRYID;

	hr = HrSetOneProp(lpMsgStore, lpProp);
	if (hr != hrSuccess)
		goto exit;

	hr = lpNewFolder->QueryInterface(IID_IMAPIFolder, (void**)lppShortcutFolder);
	if (hr != hrSuccess)
		goto exit;

exit:
	if (lpProp)
		MAPIFreeBuffer(lpProp);

	if (lpFolder)
		lpFolder->Release();

	if (lpNewFolder)
		lpNewFolder->Release();

	return hr;
}