我的任务很简单,检索给定日期之间的所有邮件。
我知道我必须使用IMAPITable::Restrict
调用(或直接将其指定给pHrQueryAllRows
),但考虑到Microsoft提供的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;
答案 0 :(得分:0)
RES_AND(2,(RES_PROPERTY,RELOP_GT)(RES_PROPERTY,RELOP_LE))。 对于每个RES_PROPERTY SR限制,该值将存储在SRestriction.lpProp.Value.ft中。
您可以看到Outlook或用户在OutlookSpy中创建的各种SRestriction
条件 - 您可以在&#34;搜索文件夹&#34;中选择Outlook中的一个可见搜索文件夹。 Outlook中的文件夹树视图中的节点,然后单击OutlookSpy功能区上的IMAPIFolder按钮并转到GetSearchCriteria
选项卡(该选项卡仅在搜索文件夹中可见)。