使用MAPI API检索给定日期之间的特定邮件

问题描述:

我的任务非常简单,即检索给定日期之间的所有邮件。使用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; 
+1

这是一个工会,所以你不需要全部填写,只需要一个字段。我认为你需要和限制包含两个道具限制(比开始日期和结束日期还短) –

RES_AND(2,(RES_PROPERTY,RELOP_GT)(RES_PROPERTY,RELOP_LE))。 该值将存储在每个RES_PROPERTY SRestriction的SRestriction.lpProp.Value.ft中。

就可以看到Outlook或用户创建各种SRestriction条件OutlookSpy - 您可以选择在Outlook中的文件夹树视图中的“搜索文件夹”节点下在Outlook中看到搜索文件夹,并点击IMAPIFolder按钮OutlookSpy功能区并转至GetSearchCriteria选项卡(该选项卡仅在搜索文件夹中可见)。

+0

我在哪里填写实际日期?并以什么格式? –

+0

查看上面更新的答案 –

+0

在OutLookSpy中找不到该选项,SRestriction选项也适用于某个文件夹下的邮件或所有邮件? –