2017-01-02 17 views
0

我的任務非常簡單,即檢索給定日期之間的所有郵件。使用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

這是一個工會,所以你不需要全部填寫,只需要一個字段。我認爲你需要和限制包含兩個道具限制(比開始日期和結束日期還短) –

回答

0

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選項也適用於某個文件夾下的郵件或所有郵件? –

相關問題