HOWTO: Change the Aging Properties on a Folder
ID: Q194955
|
The information in this article applies to:
-
Extended Messaging Application Programming Interface (MAPI), version 1.0
SUMMARY
The Aging Properties determine the length of time an item will stay in a
particular folder before it is archived. The two properties that can be set
to control this are PR_AGING_PERIOD and PR_AGING_GRANULARITY.
PR_AGING_PERIOD contains a number that indicates the number of units to
set. PR_AGING_GRANULARITY contains a constant indicating the units for the
period. For example, if you want to set the length of time to 14 days, you
would set the PR_AGING_PERIOD to 14 and the PR_AGING_GRANULARITY to 2
(representing days; see below for a list of the constants).
Here are the define statements for the properties and the constants:
#define PR_AGING_PERIOD PROP_TAG(PT_LONG,0x36EC)
#define PR_AGING_GRANULARITY PROP_TAG(PT_LONG,0x36EE)
#define AG_MONTHS 0
#define AG_WEEKS 1
#define AG_DAYS 2
MORE INFORMATION
The code below demonstrates how to set the aging properties on the Inbox
Folder. It is important to remember to enable archiving on the Inbox folder
in order for these property changes to take effect.
This sample depends on the file RulesCls.dll, which can be built from
source files included on the Microsoft Platform SDK (Software Development
Kit).
The additional libraries required to make the code compile are:
- kernel32.lib
- user32.lib
- msvcrt.lib
- mapi32.lib
- edkdebug.Lib
- edkmapi.lib
- rulecls.lib
- edkutils.lib
- addrlkup.lib
- edkguid.lib
- version.lib
- advapi32.lib
#include <edk.h>
#include <mapidefs.h>
#define PR_AGING_PERIOD PROP_TAG(PT_LONG,0x36EC)
#define PR_AGING_GRANULARITY PROP_TAG(PT_LONG,0x36EE)
#define AG_MONTHS 0
#define AG_WEEKS 1
#define AG_DAYS 2
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR pszCmd,
int nCmdShow)
{
LPMAPISESSION lpSession = NULL;
LPMDB lpStore = NULL;
HRESULT hr = NULL;
CHAR szFolder[MAX_PATH + 1] = {0};
LPMAPIFOLDER lpFolder = NULL;
ULONG cbEIDFolder = 0;
LPENTRYID lpEIDFolder = NULL;
LPMAPITABLE lpTable = NULL;
ULONG cbEntryID = 0;
LPENTRYID lpEntryID = NULL;
ULONG ulFlags = MAPI_BEST_ACCESS;
ULONG ulObjType = 0;
LPSRestriction lpRes = NULL;
ULONG lpulCount = NULL;
LPSRowSet lpRows = NULL;
LPMAPIPROP lpMAPIProp = NULL;
MessageBox ( 0L, "Begin changing aging properties.",
"Windows", MB_OK );
hr = MAPIInitialize(NULL);
if (FAILED(hr))
{
return 1;
}
hr = MAPILogonEx(0, "", NULL,
MAPI_LOGON_UI | MAPI_NEW_SESSION | MAPI_EXPLICIT_PROFILE ,
&lpSession);
if (FAILED(hr))
{
MessageBox(NULL,"MAPI Logon failed",NULL,MB_OK);
goto cleanup;
}
hr = HrOpenExchangePrivateStore(lpSession,&lpStore);
if (FAILED(hr))
{
MessageBox(NULL,"Message Store Not Opened",NULL,MB_OK);
goto cleanup;
}
strcpy(szFolder, "Top of Information Store\\Inbox");
hr = HrMAPIFindFolderEx(lpStore, '\\', szFolder,
&cbEIDFolder, &lpEIDFolder);
if (FAILED(hr))
{
MessageBox(NULL,"Inbox Not Found",NULL,MB_OK);
goto cleanup;
}
hr = HrMAPIOpenFolderEx (lpStore,'\\',szFolder,&lpFolder);
if (FAILED(hr))
{
MessageBox(NULL,"Inbox Could Not Be Opened",NULL,MB_OK);
goto cleanup;
}
hr = lpFolder->GetContentsTable(MAPI_ASSOCIATED,&lpTable);
if (FAILED(hr))
{
MessageBox(NULL,"GetContentsTable Failed",NULL,MB_OK);
goto cleanup;
}
{
SizedSPropTagArray(2, Columns) =
{
2, // number of properties
{
PR_ENTRYID, PR_MESSAGE_CLASS
}
};
hr = lpTable->SetColumns( (LPSPropTagArray)&Columns, NULL );
if (FAILED(hr))
{
MessageBox(NULL,"SetColumns Failed",NULL,MB_OK);
goto cleanup;
}
}
hr = HrStringToRestriction(
"PR_MESSAGE_CLASS = \"IPC.MS.Outlook.AgingProperties\"",
NULL, &lpRes);
if (FAILED(hr))
{
MessageBox(NULL,"HrStringToRestriction Failed",NULL,MB_OK);
goto cleanup;
}
if (FAILED(hr = lpTable->Restrict(lpRes,0L)))
{
MessageBox(NULL,"Restrict Failed",NULL,MB_OK);
goto cleanup;
}
if (FAILED(hr = lpTable->GetRowCount(0,&lpulCount)))
{
MessageBox(NULL,"GetRowCount Failed",NULL,MB_OK);
goto cleanup;
}
if (lpulCount > 0)
{
if (FAILED(hr = lpTable->QueryRows(lpulCount,
TBL_NOADVANCE, &lpRows)))
{
MessageBox(NULL,"QueryRows Failed",NULL,MB_OK);
goto cleanup;
}
cbEntryID = lpRows->aRow[0].lpProps[0].Value.bin.cb;
lpEntryID = (LPENTRYID) lpRows->aRow[0].lpProps[0].Value.bin.lpb;
if (FAILED(hr = lpFolder->OpenEntry(cbEntryID,
(LPENTRYID) lpEntryID, NULL,
MAPI_MODIFY, &ulObjType,
(LPUNKNOWN *) &lpMAPIProp)))
{
MessageBox(NULL,"OpenEntry Failed",NULL,MB_OK);
goto cleanup;
}
SPropValue spvProp = {0};
spvProp.ulPropTag = PR_AGING_PERIOD;
spvProp.Value.l = 14;
if (FAILED(hr = HrSetOneProp(lpMAPIProp,&spvProp)))
{
MessageBox(NULL,"HrSetOneProp Failed",NULL,MB_OK);
goto cleanup;
}
spvProp.ulPropTag = PR_AGING_GRANULARITY;
spvProp.Value.l = AG_DAYS;
if (FAILED(hr = HrSetOneProp(lpMAPIProp,&spvProp)))
{
MessageBox(NULL,"HrSetOneProp Failed",NULL,MB_OK);
goto cleanup;
}
if (FAILED(hr = lpMAPIProp->SaveChanges(KEEP_OPEN_READWRITE)))
{
MessageBox(NULL,"SaveChanges Failed",NULL,MB_OK);
goto cleanup;
}
}
cleanup:
if ( S_OK == hr )
MessageBox ( 0L, "Finished saving changes to aging properties.",
"Windows", MB_OK );
if (lpRows)
FREEPROWS(lpRows);
if (lpSession)
{
lpSession->Logoff(0, 0, 0);
ULRELEASE(lpSession);
}
MAPIUninitialize();
return 0;
}
Additional query words:
Keywords : kbnokeyword kbMsg kbMAPI100
Version : WINDOWS:1.0
Platform : WINDOWS
Issue type : kbhowto
|