我的任務非常簡單,即檢索給定日期之間的所有郵件。使用MAPI API檢索給定日期之間的特定郵件
我知道我必須使用3210調用(或直接指定爲pHrQueryAllRows
),但它看起來太複雜了,因爲微軟提供了API。
鑑於SRestriction結構(mapidefs.h):
typedef struct _SRestriction
{
ULONG rt; /* Restriction type */
union
{
SComparePropsRestriction resCompareProps; /* first */
SAndRestriction resAnd;
SOrRestriction resOr;
SNotRestriction resNot;
SContentRestriction resContent;
SPropertyRestriction resProperty;
SBitMaskRestriction resBitMask;
SSizeRestriction resSize;
SExistRestriction resExist;
SSubRestriction resSub;
SCommentRestriction resComment;
SAnnotationRestriction resAnnotation; // OFFICEDEV: not backwards compatible with Office 11 and older
SCountRestriction resCount; // OFFICEDEV: not backwards compatible with Office 11 and older
} res;
} SRestriction;
我如何使用下面的結構來獲取最新的X和Y之間的郵件?
編輯:
SPropValue* pStartTime = nullptr;
pfnMAPIAllocateBuffer_(sizeof(SPropValue),
reinterpret_cast<LPVOID*>(&pStartTime));
ZeroMemory(pStartTime, sizeof(SPropValue));
SPropValue* pStopTime = nullptr;
pfnMAPIAllocateBuffer_(sizeof(SPropValue),
reinterpret_cast<LPVOID*>(&pStopTime));
ZeroMemory(pStopTime, sizeof(SPropValue));
SRestriction* pConditions = nullptr;
pfnMAPIAllocateBuffer_(sizeof(SRestriction) * 2,
reinterpret_cast<LPVOID*>(&pConditions));
pConditions[0].rt = RES_PROPERTY;
pConditions[0].res.resProperty.relop = RELOP_GT;
pStartTime->ulPropTag =
pConditions[0].res.resProperty.ulPropTag =
PR_MESSAGE_DELIVERY_TIME;
//////////////
SYSTEMTIME stStart = { 0 };
stStart.wSecond=0;
stStart.wMinute=0;
stStart.wHour=9;
stStart.wDay=1;
stStart.wMonth=1;
stStart.wYear=2017;
FILETIME ftStart;
SystemTimeToFileTime(&stStart, &ftStart);
pStartTime->Value.ft = ftStart;
///////////////
pConditions[0].res.resProperty.lpProp = pStartTime;
pConditions[1].rt = RES_PROPERTY;
pConditions[1].res.resProperty.relop = RELOP_LE;
pStopTime->ulPropTag =
pConditions[1].res.resProperty.ulPropTag =
PR_MESSAGE_DELIVERY_TIME;
//////////////
SYSTEMTIME stStop = { 0 };
stStop.wSecond = 0;
stStop.wMinute=12;
stStop.wHour=14;
stStop.wDay=18;
stStop.wMonth=1;
stStop.wYear=2017;
FILETIME ftStop;
SystemTimeToFileTime(&stStop, &ftStop);
pStartTime->Value.ft = ftStop;
///////////////
pConditions[1].res.resProperty.lpProp = pStopTime;
spSRestriction_.reset(new SRestriction); //#igal add deallocation
spSRestriction_->rt = RES_AND;
spSRestriction_->res.resAnd.cRes = 2;
spSRestriction_->res.resAnd.lpRes = pConditions;
這是一個工會,所以你不需要全部填寫,只需要一個字段。我認爲你需要和限制包含兩個道具限制(比開始日期和結束日期還短) –