Request # 17
TClientDataSet & Extended MAPI
This example shows how you can use TClientDataSet and Extended MAPI togeter.
Code snip:
procedure EnumThisFolder(const MAPIFolder: IMAPIFolder; Restriction: PSRestriction);
const
Colums: record
cValues: ULONG;
aulPropTag: array [0 .. 6] of ULONG;
end
= (cValues: 7;
aulPropTag: (PR_ENTRYID, PR_PARENT_ENTRYID, PR_SUBJECT, PR_SENDER_EMAIL_ADDRESS,
PR_MESSAGE_DELIVERY_TIME, PR_HASATTACH, PR_MESSAGE_SIZE));
var
MapiTable: IMAPITable;
SortOrderSet: TSSortOrderSet;
RowCount: ULONG;
ProgresBar: TProgressBar;
RowSet: PSRowSet;
iCount: Integer;
begin
ProgresBar := nil;
RowSet := nil;
StatusBar.Panels.Clear;
if not Assigned(MAPIFolder) then
Exit;
try
// GetContentsTable method returns a pointer to the container's contents table.
// If the MAPI_UNICODE flag is not set, the strings should be returned in the ANSI format.
hr := MAPIFolder.GetContentsTable(fMAPIUnicode, MapiTable);
// fMAPIUnicode ???
if failed(hr) then
raise Exception.Create(GetMapiError(MAPIFolder, hr));
hr := MapiTable.SetColumns(@Colums, 0);
if failed(hr) then
raise Exception.Create(GetMapiError(MapiTable, hr));
hr := MapiTable.Restrict(Restriction, TBL_BATCH);
if failed(hr) then
raise Exception.Create(GetMapiError(MapiTable, hr));
SortOrderSet.cSorts := 1;
SortOrderSet.cCategories := 0;
SortOrderSet.cExpanded := 0;
SortOrderSet.aSort[0].ulPropTag := PR_MESSAGE_DELIVERY_TIME;
SortOrderSet.aSort[0].ulOrder := TABLE_SORT_ASCEND;
// SortTable method orders the rows of the table based on sort criteria.
hr := MapiTable.SortTable(@SortOrderSet, TBL_BATCH);
if failed(hr) then
raise Exception.Create(GetMapiError(MapiTable, hr));
RowCount := 0;
hr := MapiTable.GetRowCount(0, RowCount);
if failed(hr) then
raise Exception.Create(GetMapiError(MapiTable, hr));
if RowCount > 0 then
begin
ProgresBar := TProgressBar.Create(Self);
ProgresBar.Max := RowCount;
ProgresBar.Step := 1;
ProgresBar.Parent := StatusBar;
ProgresBar.Left := StatusBar.Left + 3;
ProgresBar.Top := 3;
ProgresBar.Height := StatusBar.Height - 4;
ProgresBar.Width := 500;
while True do
begin
RowSet := nil;
hr := MapiTable.QueryRows(50, 0, RowSet);
if Assigned(RowSet) then
if RowSet.cRows = 0 then
begin
if Assigned(RowSet) then
FreePRows(RowSet);
RowSet := nil;
Break;
end
else
begin
for iCount := 0 to RowSet.cRows - 1 do
begin
ProgresBar.StepIt;
ClientDataSet.Append;
// PR_ENTRYID
{$IF NOT DEFINED(DELPHI2009)}
SetAsBytes
(TBinaryField(ClientDataSet.FieldByName('ClientDataSetEntryID')),
BinaryToBytes(PSPropValueArray(RowSet.aRow[iCount].lpProps)[0].Value.bin));
{$ELSE}
ClientDataSet.FieldByName('ClientDataSetEntryID').asBytes :=
BinaryToBytes(PSPropValueArray(RowSet.aRow[iCount].lpProps)[0].Value.bin);
{$IFEND}
// PR_PARENT_ENTRYID
{$IF NOT DEFINED(DELPHI2009)}
SetAsBytes
(TBinaryField(ClientDataSet.FieldByName('ClientDataSetFolderEntryID')),
BinaryToBytes(PSPropValueArray(RowSet.aRow[iCount].lpProps)[1].Value.bin));
{$ELSE}
ClientDataSet.FieldByName('ClientDataSetFolderEntryID').asBytes :=
BinaryToBytes(PSPropValueArray(RowSet.aRow[iCount].lpProps)[1].Value.bin);
{$IFEND}
// PR_SUBJECT
if (PSPropValueArray(RowSet.aRow[iCount].lpProps)[2].ulPropTag = PR_SUBJECT)
and Assigned(PSPropValueArray(RowSet.aRow[iCount].lpProps)[2].Value.lpsz) then
ClientDataSet.FieldByName('ClientDataSetSubject').AsString :=
MAPIUtils.GetPropString(PSPropValueArray(RowSet.aRow[iCount].lpProps)[2]);
// PR_SENDER_EMAIL_ADDRESS
if (PSPropValueArray(RowSet.aRow[iCount].lpProps)[3].ulPropTag = PR_SENDER_EMAIL_ADDRESS)
and Assigned(PSPropValueArray(RowSet.aRow[iCount].lpProps)[3].Value.lpsz) then
ClientDataSet.FieldByName('ClientDataSetSender').AsString :=
MAPIUtils.GetPropString(PSPropValueArray(RowSet.aRow[iCount].lpProps)[3]);
// PR_MESSAGE_DELIVERY_TIME
if (PSPropValueArray(RowSet.aRow[iCount].lpProps)
[4].ulPropTag = PR_MESSAGE_DELIVERY_TIME) then
ClientDataSet.FieldByName('ClientDataSetReceived').AsDateTime :=
DateTimeFromFileTime(PSPropValueArray(RowSet.aRow[iCount].lpProps)[4].Value.ft);
// PR_HASATTACH
if (PSPropValueArray(RowSet.aRow[iCount].lpProps)[5].ulPropTag = PR_HASATTACH) then
ClientDataSet.FieldByName('ClientDataSetHasAttach').AsBoolean :=
PSPropValueArray(RowSet.aRow[iCount].lpProps)[5].Value.B;
// PR_MESSAGE_SIZE
if (PSPropValueArray(RowSet.aRow[iCount].lpProps)[6].ulPropTag = PR_MESSAGE_SIZE) then
ClientDataSet.FieldByName('ClientDataSetSize').AsInteger :=
PSPropValueArray(RowSet.aRow[iCount].lpProps)[6].Value.L;
ClientDataSet.Post;
end;
if Assigned(RowSet) then
FreePRows(RowSet);
RowSet := nil;
end;
end;
end;
MapiTable := nil;
if Assigned(ProgresBar) then
FreeAndNil(ProgresBar);
StatusBar.Panels.Add;
StatusBar.Panels[0].Style := psText;
StatusBar.Panels[0].Text := ' ' + IntToStr(ClientDataSet.RecordCount) + ' Items';
StatusBar.Panels[0].Width := 130;
ClientDataSet.First;
finally
if Assigned(RowSet) then
FreePRows(RowSet);
RowSet := nil;
MapiTable := nil;
if Assigned(ProgresBar) then
FreeAndNil(ProgresBar);
end;
end;
Download Request #17 as Compiled Application
Download Project (DELPHI 10.4) ZIP file
Source Code: In package

