LazyMAPI

MAPIUtils

unit: MAPIUtils.pas
file path: ..\Library\
version: 2014.хх
uses
ActiveX, Classes, Types, ComCtrls, Windows, SysUtils, Dialogs, DB, ExtendedMAPI, IMIEMTypes

Declarations:

PDTCTLArray = ^TDTCTLArray;
  TDTCTLArray = array [0 .. MaxLongint div SizeOf(DTCTL) - 1] of DTCTL;
 
  POPTIONDATAArray = ^TOPTIONDATAArray;
  TOPTIONDATAArray = array [0 .. MaxLongint div SizeOf(TOPTIONDATA) - 1] of TOPTIONDATA;
 
  PSPropValueArray = ^TSPropValueArray;
  LPSPropValueArray = PSPropValueArray;
  TSPropValueArray = array [0 .. MaxLongint div SizeOf(TSPropValue) - 1] of TSPropValue;
 
  PSSortOrderArray = ^TSSortOrderArray;
  TSSortOrderArray = array [0 .. MaxLongint div SizeOf(TSSortOrder) - 1] of TSSortOrder;
 
  PPSPropValueArray = ^T_PSPropValueArray;
  T_PSPropValueArray = array [0 .. MaxLongint div SizeOf(PSPropValue) - 1] of PSPropValue;
 
  TSRestrictionArray = array [0 .. MaxLongint div SizeOf(TSRestriction) - 1] of TSRestriction;
  PSRestrictionArray = ^TSRestrictionArray;
 
  PMapiNamedList = ^TMapiNamedList;
  TMapiNamedList = array [0 .. MaxLongint div SizeOf(TMAPINAMEID) - 1] of TMAPINAMEID;
 
  PPMapiNamedList = ^TPMapiNamedList;
  TPMapiNamedList = array [0 .. MaxLongint div SizeOf(PMAPINAMEID) - 1] of PMAPINAMEID;
 
  PSBinArray = ^TSBinArray;
  TSBinArray = array [0 .. MaxLongint div SizeOf(TSBinary) - 1] of TSBinary;
 
  TPSBinArray = array [0 .. MaxLongint div SizeOf(PSBinary) - 1] of PSBinary;
  PPSBinArray = ^TPSBinArray;
 
  TADRENTRYArray = array [0 .. MaxLongint div SizeOf(TADRENTRY) - 1] of TADRENTRY;
  PADRENTRYArray = ^TADRENTRYArray;
 
  TPADRENTRYArray = array [0 .. MaxLongint div SizeOf(PADRENTRY) - 1] of PADRENTRY;
  PPADRENTRYArray = ^TPADRENTRYArray;
 
  TSRowSetArray = array [0 .. MaxLongint div SizeOf(TSRowSet) - 1] of TSRowSet;
  PSRowSetArray = ^TSRowSetArray;
 
  TSRowSArray = array [0 .. MaxLongint div SizeOf(TSRow) - 1] of TSRow;
  PSRowSArray = ^TSRowSArray;
 
  TNOTIFICATIONArray = array [0 .. MaxLongint div SizeOf(TNOTIFICATION) - 1] of TNOTIFICATION;
  PNOTIFICATIONArray = ^TNOTIFICATIONArray;
 
  _TSingleArray = array [0 .. High(Integer) div SizeOf(single) - 1] of single;
  _PSingleArray = ^_TSingleArray;
 
  _TDoubleArray = array [0 .. High(Integer) div SizeOf(double) - 1] of double;
  _PDoubleArray = ^_TDoubleArray;
 
  _TCurrencyArray = array [0 .. High(Integer) div SizeOf(currency) - 1] of currency;
  _PCurrencyArray = ^_TCurrencyArray;
 
  _CardinalArray = array [0 .. MaxLongint div SizeOf(Cardinal) - 1] of Cardinal;
  _PCardinalArray = ^_CardinalArray;
 
  _TFileTimeArray = array [0 .. High(Integer) div SizeOf(TFileTime) - 1] of TFileTime;
  _PFileTimeArray = ^_TFileTimeArray;
 
  _TInt64Array = array [0 .. High(Integer) div SizeOf(int64) - 1] of int64;
  _PInt64Array = ^_TInt64Array;
 
  _SmallIntArray = array [0 .. High(Integer) div SizeOf(SmallInt) - 1] of SmallInt;
  _PSmallIntArray = ^_SmallIntArray;
 
  TAnsiCharArray = packed array [0 .. (MaxLongint div SizeOf(PAnsiChar)) - 1] of PAnsiChar;
  PAnsiCharArray = ^TAnsiCharArray;
 
  TWideCharArray = packed array [0 .. (MaxLongint div SizeOf(PWideChar)) - 1] of PWideChar;
  PWideCharArray = ^TWideCharArray;
 
  _TGUIDArray = array [0 .. High(Integer) div SizeOf(TGUID) - 1] of TGUID;
  _PGUIDArray = ^_TGUIDArray;
 
 
  // Exchange Server Version Info  
  TExchangeInfo = packed record // EXCHANGE_STORE_VERSION_NUM
    wMajorVersion, wMinorVersion, wRelease, wBuild: word;
  end;
 
  PExchangeInfo = ^TExchangeInfo;
 
 
{$IF NOT DECLARED(TCPInfoEx)}
  PCPInfoExA = ^TCPInfoExA;
  PCPInfoExW = ^TCPInfoExW;
{$IFDEF UNICODE}
  PCPInfoEx = PCPInfoExW;
{$ELSE}
  PCPInfoEx = PCPInfoExA;
{$ENDIF UNICODE}
 
// Contains information about a code page. This structure is used by the GetCPInfoEx function.
  _cpinfoExA = record
    MaxCharSize: UINT; { max length (bytes) of a char }
    DefaultChar: array [0 .. MAX_DEFAULTCHAR - 1] of Byte; { default character }
    LeadByte: array [0 .. MAX_LEADBYTES - 1] of Byte; { lead byte ranges }
    UnicodeDefaultChar: WideChar;
    CodePage: UINT;
    CodePageName: array [0 .. MAX_PATH - 1] of AnsiChar;
  end;
 
  _cpinfoExW = record
    MaxCharSize: UINT; { max length (bytes) of a char }
    DefaultChar: array [0 .. MAX_DEFAULTCHAR - 1] of Byte; { default character }
    LeadByte: array [0 .. MAX_LEADBYTES - 1] of Byte; { lead byte ranges }
    UnicodeDefaultChar: WideChar;
    CodePage: UINT;
    CodePageName: array [0 .. MAX_PATH - 1] of WideChar;
  end;
{$IFDEF UNICODE}
 
  _cpinfoEx = _cpinfoExW;
{$ELSE}
  _cpinfoEx = _cpinfoExA;
{$ENDIF UNICODE}
  TCPInfoExA = _cpinfoExA;
  TCPInfoExW = _cpinfoExW;
{$IFDEF UNICODE}
  TCPInfoEx = TCPInfoExW;
{$ELSE}
  TCPInfoEx = TCPInfoExA;
{$ENDIF UNICODE}
  CPINFOExA = _cpinfoExA;
  CPINFOExW = _cpinfoExW;
{$IFDEF UNICODE}
  CPINFOEx = CPINFOExW;
{$ELSE}
  CPINFOEx = CPINFOExA;
{$ENDIF UNICODE}
{$IFEND}

 

Available functions:

function GetResourceFlags - Returns string representation of PR_RESOURCE_FLAGS (a bitmask of flags for message services and providers)


function _WrapText  - Add LineBreaks at position MaxCol


procedure BinaryToHex - Converts a binary value into its hexadecimal representation
function BinaryToHex - Converts a binary value into its hexadecimal representation

procedure EntryIdToString - Deprecated - use BinaryToHex

function EntryIdToString - Deprecated - use BinaryToHex


procedure StringToEntryId - Converts a hexadecimal string into binary value

function StringToEntryId - Converts a hexadecimal string into binary value


function CreateOneOff - Creates an entry identifier for an one-off address

function IsOneOffEntryId - Determines is PR_ENTRYID hold an one-off address

function GetOneOffAddress - Returns a decoded one-off address from PR_ENTRYID


function IsWrappedDLEntryId - Determines is PR_ENTRYID holds a wrapped entry identifier of a member of a personal distribution list
function GetUnWrappedDLEntryId - Returns an UnWrapped EntryID of a member of a personal distribution list


function IsContactEntryId - Determines is PR_ENTRYID holds entry identifier of a Contact item

function IsGalEntryID - Determines is PR_ENTRYID holds entry identifier of a Global Address List item


function EncodeOneOffTemplate - Assembles an one-of address from name, address, address type
procedure DecodeOneOffTemplate - Dessembles an one-off address to name, address, address type


function GetExchSiteName - Retrieves Exchange server Site name from user Home-MTA attribute

function GetExchServerName - Retrieves Exchange Server name from user Home-MTA attribute


function CloneTSBinary - Returns a copy of TSBinary using Delphi memory functions

procedure FreeTSBinary - Releases TSBinary structure previously allocated with Delphi memory function
function MAPICloneTSBinary - Returns a copy of TSBinary using MAPI memory functions
procedure FreeMAPITSBinary - Releases TSBinary structure previously allocated with MAPI memory function


function IsSameBinary - Compares two TSBinary structure, whether they are the same
function IsSameNamedProp - Compares two TMAPINAMEID structures, whether they are the same


function GetMAPIError - Returns detailed information about an error, typically generated by MAPI
function SzDecodeMAPIError - Returns a string representation of a basic MAPI error. Deprecated. Use GetMAPIError.
function SzDecodeScode - Alias for SzDecodeMAPIError. Deprecated. Use GetMAPIError.


function SzGetPropTag - Returns a string representation of a PropTag

function SzGetPropType - Returns a string representation of a PropType


function DecodeMAPIInterfaces - Returns a string representation of the known MAPI interfaces


function GetSystemMAPIFolders - Returns entry identifier for Inbox, Outbox, Deleted Items, Sent Items


procedure AppendPropTag - Appends a new PropTag to PSPropTagArray
function DeletePropTag - Deletes a PropTag from PSPropTagArray

function PropTagsToArray - Converts PSPropTagArray to array of Cardinal


function HrOpenSingleProvider - Gets the IProfSect object for a single provider from the ProviderTable in the IProviderAdmin object


function GetMAPIStatus - Gets the IMAPIStatus object from MAPI Session


procedure StringsFromVariant - Converts an array (variant) of strings to TStrings
function StringsToVariant - Converts TStrings to an array (variant) of strings


function CopyProp - Copies the properties defined by an array of SPropValue structures to a new destination.
function CopyOneProp - Copies a single SPropValue structure to a new destination
function DuplicateOneProp - Copies a single SPropValue structure to a new destination


function FindExchangeVersion - Returns Microsoft Exchange Server version

function IsOldExchange - Determines if Microsoft Exchange Server version is < Exchange Server 2000
function IsOldExchStore - Determines if Microsoft Exchange Server Message Store version is < 2000
function IsStoreOffline - Determines if Microsoft Exchange Server Message Store is in "Off Line (Cached)" mode


function GetMAPIVersion - Returns Extended MAPI version

function GetOutlookVersionAsString - Returns Outlook version as string, e.g. '15.0.4551.1004'

function GetOutlookVersion - Returns Outlook version


function FIsExchangeStore - Indicates whether the IMsgStore is Microsoft Exchange Store
function FIsExchangeUserStore - Indicates whether the IMsgStore is Personal Exchange Store

function FIsExchangeDelegateStore - Indicates whether the IMsgStore is Personal Shared (Delegated) Exchange Store

function FIsPublicStore - Indicates whether the IMsgStore is Microsoft Exchange Public Store


function HrMAPIOpenInbox - Returns IPM Inbox folder


function PropIDIndex - Returns position of PropTag (PropID) in the PSPropTagArray

function IsPropIDExist - Indicates whether the PropTag (PropID) exists in PSPropTagArray
function ConcatSPropTagArrays - Takes two PSPropTagArray and combines them


function WideStringToAnsiString - Converts Unicode string to Ansi string using specified code page

function PWideCharToAnsiString - Converts PWideChar to Ansi string using specified code page

function AnsiToUnicode - Converts Ansi string to Unicode string using specified code page

function PAnsiCharToUnicode - Converts PAnsiChar to Unicode string using specified code page


function GetPropString - Returns property value from TSPropValue as string, when PROP_TYPE is PT_STRING8 or PT_UNICODE


function BinaryToStream - Converts PT_BINARY value to IStream or TStream


procedure IStreamToStream - Converts IStream to TStream

procedure StreamToIStream - Converts TStream to IStream


function BytesToHex - Converts TBytes to string
function BytesToHexStr - obsolete, use BytesToHex


function BinaryToBytes - Converts TSBinary to TBytes

procedure BytesToBinary - Converts TBytes to TSBinary


function MemoryStreamToBytes - Converts TMemoryStream to TBytes


function IsSupportsRTF - Checks whether the message or store supports RTF text


function IsSupportsUNICODE - Checks whether the message or store supports UNICODE text/string


function IsSameBytes - Compares two TBytes, whether they are the same
function IsSameTBytes - deprecated, use IsSameBytes


function MAPICopyRestriction - Copies PSRestriction to new PSRestriction

function MapiCopyPropSet - Copies PSPropValue to new PSPropValue array


function FindStringValue - Converts value from TSPropValue as string, when PROP_TYPE is PT_STRING8 or PT_UNICODE


procedure MessageToStream - Converts an IMessage to TStream.


procedure IStorageToStream - Converts an IStorage to TStream.


procedure IStorageFromStream - Creates an IStorage from TStream


function IsOutlook64 - Checks whether the installed Microsoft Office Outlook (version 2010 and above is 64 bit)


function GetResourceFlags(const Flags: Cardinal): TStrings;

description
   Returns string representation of PR_RESOURCE_FLAGS (a bitmask of flags for message services and providers)

parameters
 Flags: Cardinal

Usage:
  ShowMessage(GetResourceFlags(GetPropLong(MsgStore, PR_RESOURCE_FLAGS)).Text);

Top


function _WrapText(const Line: string; const MaxCol: Integer = 80): string;

description
  Add LineBreaks at position MaxCol

parameters
  Line - string, text that will be formated
  MaxCol - Integer, position where CR (#13) will be set

Usage:
 
ShowMessage(_WrapText(GetMAPIError(nil, hr)));

Top


procedure BinaryToHex(cb: ULONG; P: PBYTE; out HexStr: String); overload;
function BinaryToHex(const Binary: TSBinary): String; overload;

description
 Converts a binary value into its hexadecimal representation

parameters
 cb:ULONG - number of bytes
 P: PBYTE - pointer to byte array
 Binary: TSBinary - Describes a property of type PT_BINARY

Usage:

 
 hr := HrGetOneProp(MAILObj, PR_ENTRYID, PropValue);
  if hr=S_OK then
  begin
    TempStr := '';
    BinaryToHex(PropValue.Value.bin.cb, PropValue.Value.bin.lpb, TempStr);
    ShowMessage(TempStr);
  end;

or

 hr := HrGetOneProp(MAILObj, PR_ENTRYID, PropValue);
 if hr=S_OK then
    ShowMessage(BinaryToHex(PropValue.Value.bin)); 

Top


procedure StringToEntryId(const StrEntryId: String; out cbeid: ULONG; out peid: PENTRYID); overload;
function StringToEntryId(const EntryId: AnsiString): TSBinary; overload;

description
 Converts a hexadecimal string into binary value

parameters
 StrEntryId:String - hexadecimal string
 cbeid:ULONG - output - number of bytes
 peid: PENTRYID - output - pointer to byte array
 EntryId - AnsiString - hexadecimal string

Usage:

var
 cbEntryID, ObjType: ULONG;
 EntryID: PENTRYID;
 MAPIObject: IMAPIProp;
const
 StrText = '00000000A6B1B1D69264CA45B42DEB71AEC647FB82800000';

 begin
    StringToENTRYID(StrText, cbEntryID, EntryID);
    hr := FAdrBook.OpenEntry(cbEntryID, EntryID, @IID_IMAPIProp, MAPI_BEST_ACCESS, ObjType, IUnknown(MAPIObject));
end;

Top


function CreateOneOff(DisplayName, AdrType, Address: PAnsiChar; Flags: word; out EntryId: PSBinary): Boolean; overload;
function CreateOneOff(const DisplayName, AdrType, Address: WideString; const wFlags: word = MAPI_ONE_OFF_NO_RICH_INFO or MAPI_ONE_OFF_UNICODE): TBytes; overload;

description
 Creates an entry identifier for an one-off address

parameters
 DisplayName, AdrType, Address: PAnsiChar/WideString
 EntryId: PSBinary - out - Pointer to one-off ENTRYID

Usage:

if CreateOneOff(PAnsiChar('IMIBO INFO'), PAnsiChar('SMTP'), PAnsiChar('info@imibo.com'), MAPI_ONE_OFF_NO_RICH_INFO, EntryId) then
begin
  PSPropValueArray(RecipProp)[0].ulPropTag := PR_SENDER_ENTRYID;
  @PSpropValueArray(RecipProp)[0].Value.bin:=EntryId;
  etc....
end;

Top


function IsOneOffEntryId(const EntryId: TBytes): Boolean;

description
 Determines is PR_ENTRYID hold an one-off address

parameters
 EntryId: TBytes - PR_ENTRYID value as TBytes

Usage:

var
  EntryID: TBytes;
begin
  EntryID:=GetPropBinaryAsBytes(MAPIMessage, PR_SENDER_ENTRYID);

  // EntryID = 00000000812B1FA4BEA310199D6E00DD010F5402000000.......63006F006D000000


  if IsOneOffEntryId(EntryID) then
    ShowMessage(GetOneOffAddress(EntryID));   // 'IMIBO INFO [SMTP:info@imibo.com]'  
end;

Top


function GetOneOffAddress(const EntryId: TBytes): WideString;

description
 Returns a decoded one-off address from PR_ENTRYID.
 If PR_ENTRYID is not one-off entry identifier, returns an empty string

parameters
 EntryId: TBytes - PR_ENTRYID value as TBytes

Usage:

var
  EntryID: TBytes;
begin
  EntryID:=GetPropBinaryAsBytes(MAPIMessage, PR_SENDER_ENTRYID);

  // EntryID = 00000000812B1FA4BEA310199D6E00DD010F5402000000.......63006F006D000000


  if IsOneOffEntryId(EntryID) then
    ShowMessage(GetOneOffAddress(EntryID));   // 'IMIBO INFO [SMTP:info@imibo.com]'  
end;

Top


function IsWrappedDLEntryId(const EntryId: TBytes): Boolean;

description
 Determines is PR_ENTRYID holds a wrapped entry identifier of a member of a personal distribution list

parameters
 EntryId: TBytes - PR_ENTRYID value as TBytes

Top


function GetUnWrappedDLEntryId(const WrappedEntryId: TBytes; out UnWrappedEntryId: TBytes; out EntryIdType: TPDLMemberType; out SelectedType: TPDLMemberAddrType): Boolean

description
 Returns an UnWrapped EntryID of a member of a personal distribution list

parameters
 WrappedEntryId: TBytes - wrapped Entry ID
 UnWrappedEntryId: TBytes - unwrapped Entry ID
 EntryIdType: TPDLMemberType - member type of Private Distribution List, as one-off, contact, GAL user, etc
 SelectedType: TPDLMemberAddrType -  Adress Type for Member of Private Distribution List

Top


function IsContactEntryId(const EntryId: TBytes): Boolean;

description
 Determines is PR_ENTRYID holds entry identifier of a Contact item

parameters
 EntryId: TBytes - PR_ENTRYID value as TBytes

Top


function IsGalEntryID(const EntryId: TBytes): Boolean;

description
 Determines is PR_ENTRYID holds entry identifier of a Global Address List item

parameters
 EntryId: TBytes - PR_ENTRYID value as TBytes

Top


function EncodeOneOffTemplate(const Address: WideString; const DisplayName: WideString = ''; const AddressType: WideString = 'SMTP'): WideString;

description
 Assembles an one-of address from name, address, address type. Result is DisplayName [AddressType:Address]

Top


procedure DecodeOneOffTemplate(const OneOffAddress: WideString; out DisplayName, AddressType, Address: WideString);

description
 Dessembles an one-off address to name, address, address type

Top


function GetExchSiteName(UserDN: PChar): PChar; overload;
function GetExchSiteName(const UserDN: String): string; overload;

description
 Retrieves Exchange server Site name from user Home-MTA attribute
 
parameters
 
UserDN:PChar - Points to a null-terminated string containing the PR_EMS_AB_HOME_MTA atribute
 UserDN: String -  String containing the PR_EMS_AB_HOME_MTA atribute

Top


function GetExchServerName(UserDN: PChar): PChar; overload;
function GetExchServerName(const UserDN: String): string; overload;

description
 Retrieves Exchange Server name from user Home-MTA attribute
 
parameters
 
UserDN:PChar - Points to a null-terminated string containing the PR_EMS_AB_HOME_MTA atribute
 UserDN: String -  String containing the PR_EMS_AB_HOME_MTA atribute

Top


function CloneTSBinary(const Source: TSBinary): TSBinary;

description
 Returns a copy of TSBinary using Delphi memory functions
 
parameters
 Source
:TSBinary - Source SBinary

Top


procedure FreeTSBinary(var Value: TSBinary);

description
 Releases TSBinary structure previously allocated with Delphi memory function
 
parameters
 Value
:TSBinary

Top


function MAPICloneTSBinary(const Source: TSBinary): TSBinary;

description
 Returns a copy of TSBinary using MAPI memory functions
 
parameters
 Source
:TSBinary

Top


procedure FreeMAPITSBinary(var Value: TSBinary);

description
 Releases TSBinary structure previously allocated with MAPI memory function
 
parameters
 Value
:TSBinary

Top


function IsSameBinary(Binary1, Binary2: TSBinary): Boolean; overload;
function IsSameBinary(cb1: Cardinal; pb1: Pointer; cb2: Cardinal; pb2: Pointer): Boolean; overload;

description
 Compares two TSBinary structure, whether they are the same
 
parameters
 Binary1, Binary2:TSBinary - TSBinary structures to be compared
 cb1:Cardinal - Count of bytes refered to pb1 pointer
 pb1:Pointer - Memory to be compared
 cb2:Cardinal - Count of bytes refered to pb2 pointer
 pb2:Pointer - Memory to be compared

Top


function IsSameNamedProp(Named1, Named2: TMAPINAMEID): Boolean;

description
 Compares two TMAPINAMEID structures, whether they are the same
 
parameters
 Named1, Named2:TMAPINAMEID- TMAPINAMEID structures to be compared

Top


function GetMAPIError(const MAPIInterface: IUnknown; hr: HRESULT): string;

description
 Returns detailed information about an error, typically generated by MAPI
 
parameters
 MAPIInterface: IUnknown - MAPI interface whose function is generated error. Can be nil
 hr: HRESULT - Error code

usage:
  // Query Rows
    hr := MAPITable.QueryRows(RowCount, 0, Rows);
    if failed(hr) then
      raise Exception.Create(GetMapiError(MAPITable, hr));

Top


function SzGetPropTag(PropTag: ULONG): String;

description
 Returns a string representation of a PropTag

parameters
 PropTag: ULONG -  PropTag

usage:

for iCount := 0 to cValues - 1 do
    begin
      ListItem := ListViewProp.Items.Add;
      ListItem.Caption := SzGetPropTag(PSPropValueArray(PropValues)[iCount].ulPropTag);
      ListItem.SubItems.Add(SzGetPropType(PSPropValueArray(PropValues)[iCount].ulPropTag));
      ListItem.Data := Pointer(PSPropValueArray(PropValues)[iCount].ulPropTag);
    end;

Top


function SzGetPropType(PropTag: ULONG): String;

description
 Returns a string representation of a PropType

parameters
 PropTag: ULONG -  PropTag

usage:

for iCount := 0 to cValues - 1 do
    begin
      ListItem := ListViewProp.Items.Add;
      ListItem.Caption := SzGetPropTag(PSPropValueArray(PropValues)[iCount].ulPropTag);
      ListItem.SubItems.Add(SzGetPropType(PSPropValueArray(PropValues)[iCount].ulPropTag));
      ListItem.Data := Pointer(PSPropValueArray(PropValues)[iCount].ulPropTag);
    end;

Top


function SzDecodeMAPIError(hr: HRESULT): String;

description
 Returns a string representation of a basic MAPI error
 
parameters
 hr: HRESULT - Error code

Top


function DecodeMAPIInterfaces(Value: PGUID): String;

description
 Returns a string representation of the known MAPI interfaces

parameters
 Value: PGUID - Pointer to TGUID

Top


function GetSystemMAPIFolders(const MDB: IMsgStore; Create: Boolean; out InBoxFolder, OutBoxFolder, DeletedItemsFolder, SentItemsFolder, IPMSubtree: PSBinary):HRESULT;

description
 Returns entry identifier for Inbox, Outbox, Deleted Items, Sent Items

parameters
 MDB: IMsgStore - The Message store
 Create: Boolean - The folders should be verified before creation, even if message store properties indicate that they are valid. The full set of IPM folders should be created in the message store's root folder.
  InBoxFolder, OutBoxFolder, DeletedItemsFolder, SentItemsFolder, IPMSubtree: PSBinary - Pointer to TSBinary containing PR_ENTRYID value for the folder. Used memory in these variables must be released by function MapiFreeBuffer.

usages:

  procedure OpenPST;
   ...
   ...

    hr := HrMAPIFindDefaultMsgStore(FMAPISession, StoreEID.cb, PENTRYID(StoreEID.lpb));
    if failed(hr) then exit;

    hr := FMAPISession.OpenMsgStore(Application.Handle, StoreEID.cb, PENTRYID(StoreEID.lpb), nil, MAPI_BEST_ACCESS, FMDB);
    if failed(hr) then exit;

    hr := GetSystemMAPIFolders(FMDB, FCreate, FInBoxEID, FOutBoxEID, FTrashBoxEID, FSentBoxEID, FRootEID);
    if failed(hr) then exit;
...
...
end;

Top


procedure AppendPropTag(var PropTagArray: PSPropTagArray; const NewPropTag: Cardinal);

description
 Appends a new PropTag to PSPropTagArray

parameters
   PropTagArray: PSPropTagArray - Existing PSPropTagArray to which will be added a new PropTag
   NewPropTag: Cardinal - A new PropTag to be added

usages:

 if not FContainsProp(PR_STORE_SUPPORT_MASK, PropTagArray) then
   AppendPropTag(PropTagArray, PR_STORE_SUPPORT_MASK);

Top


function DeletePropTag(var PropTagArray: PSPropTagArray; const PropTag: Cardinal): Boolean;

description
 Deletes a PropTag from PSPropTagArray

parameters
   PropTagArray: PSPropTagArray - Existing PSPropTagArray from which will be deleted a PropTag
   PropTag: Cardinal - PropTag to be deleted

Top


function PropTagsToArray(PropTagArray: PSPropTagArray): TCardinalDynArray;

description
 Converts PSPropTagArray to array of Cardinal

parameters
   PropTagArray: PSPropTagArray - Existing PSPropTagArray

Top


function HrOpenSingleProvider(const AdminProviders: IProviderAdmin; out ProfileSection: IProfSect): HRESULT;

  description
    Gets the IProfSect object for a single provider from the ProviderTable in the IProviderAdmin object

parameters
   AdminProviders: IProviderAdmin - a pointer to an IProviderAdmin interface
   ProfileSection: IProfSect - returned pointer to ProfileSection

Top


function GetMAPIStatus(const MAPISession: IMAPISession; out MAPIStatus: IMAPIStatus): HRESULT;

 description
  
Gets the IMAPIStatus object from MAPI Session

 parameters
   MAPISession: IMAPISession - The active MAPI session
   MAPIStatus: IMAPIStatus - returned MAPI Status object

Top


procedure StringsFromVariant(Strings: TStrings; VariantValue: variant);

 description
  
Converts an array (variant) of strings to TStrings

 parameters
   Strings: TStrings - Target TStrings. If it is nil, then new TStrings will be created
   VariantValue: variant - Source variant array

Top


function StringsToVariant(Strings: TStrings): variant;

 description
  
Converts TStrings to an array (variant) of strings

 parameters
   Strings: TStrings - source

Top


function CopyProp(PropCount: Cardinal; Source: PSPropValue; FAlloc: TALLOCATEBUFFER; FAllocMore: TALLOCATEMORE; FFree: TFREEBUFFER;
out PropValue: PSPropValue): Boolean;

description
 Copies the properties defined by an array of SPropValue structures to a new destination.

parameters
  PropCount: Cardinal - Number of properties in the array Source
  Source: PSPropValue - Array of properties that will be copied
  FAlloc: TALLOCATEBUFFER; FAllocMore: TALLOCATEMORE; FFree: TFREEBUFFER - Entry points of functions for manipulating the MAPI memory
  PropValue: PSPropValue - Output array containing the copied properties

Top


function CopyOneProp(Source: PSPropValue; FAlloc: TALLOCATEBUFFER; FAllocMore: TALLOCATEMORE; FFree: TFREEBUFFER; out PropValue: PSPropValue): Boolean;

description
  Copies a single SPropValue structure to a new destination

parameters
 Source: PSPropValue - Property to be copied
 FAlloc: TALLOCATEBUFFER; FAllocMore: TALLOCATEMORE; FFree: TFREEBUFFER - Entry points of functions for manipulating the MAPI memory
 PropValue: PSPropValue - The output of copying

Top


function DuplicateOneProp(Source: PSPropValue; FAllocMore: TALLOCATEMORE; BasePoint: Pointer; out PropValue: TSPropValue): Boolean;

description
  Copies a single SPropValue structure to a new destination

parameters
  Source: PSPropValue - Property to be copied
  FAllocMore: TALLOCATEMORE - Entry points of functions for manipulating the MAPI memory
  BasePoint: Pointer - Base, parental point of property. Can be nil
  PropValue: PSPropValue - The output of copying

Top


function FindExchangeVersion(const MAPISession: IMAPISession): TExchangeInfo;

description
   Returns Microsoft Exchange Server version

parameters
  MAPISession: IMAPISession -  Active existing MAPI session

Top


function IsOldExchange(const MAPISession: IMAPISession): Boolean;

description
   Determines if Microsoft Exchange Server version is < Exchange Server 2000

parameters
  MAPISession: IMAPISession -  Active existing MAPI session

Top


function IsOldExchStore(const MDB: IMsgStore; var Version: word): Boolean;

description
 
Determines if Microsoft Exchange Server Message Store version is < 2000

parameters
  MDB: IMsgStore - Existing active Exchange Message store
  Version: word - Rerurns store version, as 5  (Exchange Server 5/5.5), 6 (Exchange Server 2000/2003), 8 (Exchange Server 2007), 14 (Exchange Server 2010),  15 (Exchange Server 2013), etc..  

Top


function IsStoreOffline(const MDB: IMsgStore): Boolean;

description
 
Determines if Microsoft Exchange Server Message Store is in "Off Line (Cached)" mode

parameters
  MDB: IMsgStore - Existing active Exchange Message store

Top


function GetMAPIVersion(Used: Boolean = False): String;

description
   Returns Extended MAPI version as string

parameters
  Used: Boolean  -  If true - take the version from the registry otherwise - from the loaded in the application memory MAPIXXX.dll.

Top


function GetOutlookVersionAsString(var Ver: String): Boolean;

description
   Returns Outlook version as string, e.g. '15.0.4551.1004'

parameters
  Ver: String - The resulting string containing the version

Top


function GetOutlookVersion(var V1, V2, V3, V4: DWORD): Boolean; overload;

description
   Returns Outlook version, e.g. V1=15 V2=0 V3=4551 V4=1004  ('15.0.4551.1004')


function GetOutlookVersion: Integer; overload;

description
   Returns Outlook version e.g. 15

Top


function FIsExchangeStore(const MDB: IMsgStore): BOOL; overload;
function FIsExchangeStore(const MAPIUID: TMAPIUID): Boolean; overload;

description
   Indicates whether the IMsgStore is Microsoft Exchange Store

parameters
  MDB: IMsgStore - Existing active Exchange Message store
  MAPIUID: TMAPIUID - The value of the property PR_MDB_PROVIDER

Top


function FIsExchangeUserStore(const MDB: IMsgStore): BOOL; overload;
function FIsExchangeUserStore(const MAPIUID: TMAPIUID): Boolean; overload;

description
   Indicates whether the IMsgStore is Personal Exchange Store

parameters
  MDB: IMsgStore - Existing active Exchange Message store
  MAPIUID: TMAPIUID - The value of the property PR_MDB_PROVIDER

Top


function FIsExchangeDelegateStore(const MDB: IMsgStore): BOOL; overload;
function FIsExchangeDelegateStore(const MAPIUID: TMAPIUID): Boolean; overload;

description
   Indicates whether the IMsgStore is Personal Shared (Delegated) Exchange Store

parameters
  MDB: IMsgStore - Existing active Exchange Message store
  MAPIUID: TMAPIUID - The value of the property PR_MDB_PROVIDER

Top


function FIsPublicStore(const Mdb: IMsgStore): Bool; overload;
function FIsPublicStore(const MAPIUID: TMAPIUID): Boolean; overload;

description
   Indicates whether the IMsgStore is Personal Shared (Delegated) Exchange Store

parameters
  MDB: IMsgStore - Existing active Exchange Message store
  MAPIUID: TMAPIUID - The value of the property PR_MDB_PROVIDER

Top


function HrMAPIOpenInbox(const MDB: IMsgStore; out Inbox: IMAPIFolder): HRESULT;

description
   Returns IPM Inbox folder

parameters
  MDB: IMsgStore - Active Message store
  Inbox: IMAPIFolder - Returned Inbox folder

Top


function PropIDIndex(lpArray: PSPropTagArray; ulPropTag: ULONG): Integer;

description
   Returns position of PropTag in the PSPropTagArray

parameters
  lpArray: PSPropTagArray - Existing PSPropTagArray
  ulPropTag: ULONG - PropTag for search
 

note:
  The comparison is made based on property identifier (PropID)

Top


function IsPropIDExist(lpArray: PSPropTagArray; ulPropTag: ULONG): Boolean;

description
   Indicates whether the PropTag (PropID) exists in PSPropTagArray

parameters
  lpArray: PSPropTagArray - Existing PSPropTagArray
  ulPropTag: ULONG - PropTag for search
 

note:
  The comparison is made based on property identifier (PropID)

Top


function ConcatSPropTagArrays(lpArray1, lpArray2: PSPropTagArray; out lpNewArray: PSPropTagArray): HRESULT;

description
   Takes two PSPropTagArray and combines them

parameters
  lpArray1, lpArray2: PSPropTagArray - Existing PSPropTagArray
  lpNewArray: PSPropTagArray - The result, a new array combining lpArray1 and lpArray2.

note:
  The result, a new array combining lpNewArray after its use, must be released by MAPIFreeBuffer

Top


function WideStringToAnsiString(const ws: WideString; const CodePage: word = CP_ACP): AnsiString;

description
   Converts Unicode string to Ansi string using specified code page.

Top


function PWideCharToAnsiString(const ws: PWideChar; const CodePage: word = CP_ACP): AnsiString;

description
   Converts PWideChar to Ansi string using specified code page.

Top


function AnsiToUnicode(const S: AnsiString; const CodePage: word = CP_ACP): WideString;

description
   Converts Ansi string to Unicode string using specified code page.

Top


function PAnsiCharToUnicode(const S: PAnsiChar; const CodePage: word = CP_ACP): WideString;

description
   Converts PAnsiChar to Unicode string using specified code page.

Top


function GetPropString(PropValue: PSPropValue): string; overload;
function GetPropString(const PropValue: TSPropValue): string; overload;

description
    Returns property value from TSPropValue as string, when PROP_TYPE is PT_STRING8 or PT_UNICODE

usages:

var
  Rows: PSRowSet;
  iCount: Integer;
  PP: PSPropValue;
  ....
  ....
 // Get BUSINESS FAX NUMBER from Contact item
   (*PR_BUSINESS_FAX_NUMBER
    Contains the telephone number of the recipient's business fax machine.
    These properties are examples of the properties that provides identification and access information about a recipient.
    These properties are defined by the recipient and the recipient's organization.
   *)
        PP := PpropFindProp(Rows.aRow[iCount].lpProps,
          Rows.aRow[iCount].cValues, CHANGE_PROP_TYPE(PR_BUSINESS_FAX_NUMBER,
          TextTypeFlag));
        if Assigned(PP) and (PROP_TYPE(PP.ulPropTag) <> PT_ERROR) then
          Result[RowCount].BUSINESS_FAX_NUMBER := MAPIUtils.GetPropString(PP);

Top


function BinaryToStream(Value: TSBinary; const OleStream: IStream): Integer; overload;
function BinaryToStream(Value: TSBinary; Stream: TStream): Integer; overload;

description
    Converts PT_BINARY value to IStream or TStream

parameters
  Value: TSBinary - Binary value to be converted
  OleStream: IStream / Stream: TStream - Receiving stream

usage:

function GetRTFAsString(PropValue: PSPropValue): string;
var
  Compressed: IStream;
  Uncompressed: IStream;
  hr: HRESULT;
  StreamBuffer: Array [0 .. 4095] Of Byte;
  iBytesRead: ULONG;
begin
  if not Assigned(PropValue) or (PropValue.ulPropTag <> PR_RTF_COMPRESSED) then
    Exit;
 
  Compressed := TStreamAdapter.Create(TMemoryStream.Create, soOwned);
 
  try
    if BinaryToStream(PropValue.Value.bin, Compressed) > 0 then
    begin
      Compressed.Seek(0, 0, Int64(nil^));
      hr := WrapCompressedRTFStream(Compressed, 0, Uncompressed);
      if failed(hr) then
        Exit;
 
      ZeroMemory(@StreamBuffer, Length(StreamBuffer));
 
      iBytesRead := 0;
      Uncompressed.Read(@StreamBuffer, Length(StreamBuffer) - 1, @iBytesRead);
      Repeat
        Result := Result + String(PAnsiChar(@StreamBuffer));
        ZeroMemory(@StreamBuffer, Length(StreamBuffer));
        Uncompressed.Read(@StreamBuffer, Length(StreamBuffer) - 1, @iBytesRead);
      Until iBytesRead <= 0;
    end;
 
  finally
    Uncompressed := nil;
    Compressed := nil;
  end;
 
end;

Top


procedure IStreamToStream(const Source: IStream; Destination: TStream);

description
    Converts IStream to TStream

usage:

var
 StreamOle: IStream;
 BodyStream: TStringStream;
 MessageBody:TRichEdit;
 
...
...
 
 
          hr := MAPIMessage.OpenProperty(
                  PR_BODY_A, // meessage text 
                  @IID_IStream, // interface ID reference
                  STGM_READ, // interface flags
                  MAPI_DEFERRED_ERRORS, // reduces RPCs
                  IUnknown(StreamOle));
          if not Failed(hr) then
          begin
            BodyStream := TStringStream.Create(''{$IFDEF DELPHI2009}, TEncoding.ascii {$ENDIF});
            try
              IStreamToStream(StreamOle, BodyStream);
              BodyStream.Position := 0;
              MessageBody.Lines.LoadFromStream(BodyStream);
            finally
              FreeAndNil(BodyStream);
            end;
          end;

Top


procedure StreamToIStream(Stream: TStream; const ComStream: IStream; const Commit: Boolean = True);

description
    Converts TStream to IStream

usage:

function SetMsgBodyPlain(const MAPIMessage: IMessage; Stream: TStream): Boolean;
var
  OleStream: IStream;
  ...
  ...
begin
  hr := S_OK;
  OleStream := nil;
  Stream.Position := 0;
    try
      hr := MAPIMessage.OpenProperty(PR_BODY, @IID_IStream, STGM_CREATE or STGM_WRITE Or STGM_DIRECT, MAPI_CREATE Or MAPI_MODIFY, IUnknown(OleStream));
      If failed(hr) Or Not Assigned(OleStream) Then
        Exit;
 
      StreamToIStream(Stream, OleStream);
 
      ...
end;

Top


function BytesToHex(Source: TBytes): String;

description
    Converts TBytes to string

Top


function BinaryToBytes(const Binary: TSBinary): TBytes; overload;
function BinaryToBytes(cb: Cardinal; lpb: Pointer): TBytes; overload;

description
    Converts TSBinary to TBytes

Top


procedure BytesToBinary(const Value: TBytes; out cb: ULONG; out lpb: PBYTE); overload;
procedure BytesToBinary(const Value: TBytes; var Binary: TSBinary); overload;

description
    Converts TBytes to TSBinary

Top


function MemoryStreamToBytes(Stream: TMemoryStream): TBytes;

description
    Converts TMemoryStream to TBytes

Top


function IsSupportsRTF(const MdbOrMsg: IMAPIProp): Boolean;

description
    Checks whether the message or store supports RTF text

Top


function IsSupportsUNICODE(const MAPIProp: IMAPIProp): Boolean;

description
    Checks whether the message or store supports UNICODE text/string

Top


function IsSameBytes(const Bytes1, Bytes2: TBytes): Boolean;
function IsSameTBytes(const Bytes1, Bytes2: TBytes): Boolean; deprecated;

description
    Compares two TBytes, whether they are the same

Top


function MAPICopyRestriction(SourceRestriction: PSRestriction; BaseObj: Pointer; out DestinationRestriction: PSRestriction): Boolean;

description
    Copies PSRestriction to new PSRestriction

Top


function MapiCopyPropSet(cProp: ULONG; SourceProp: PSPropValue; BaseObj: Pointer; out DestProp: PSPropValue): Boolean;

description
    Copies PSPropValue to new PSPropValue array

Top


function FindStringValue(cProp: ULONG; Prop: PSPropValue; PropTag: ULONG): string;

description
    Converts value from TSPropValue as string, when PROP_TYPE is PT_STRING8 or PT_UNICODE

Top


procedure MessageToStream(const MAPIMessage: IMessage; Stream: TStream);

description
  Converts an IMessage to TStream. Then, the resulting TStream can be saved as a file.

Top


procedure IStorageToStream(const Storage: IStorage; Stream: TStream);

description
  Converts an IStorage to TStream. Then, the resulting TStream can be saved as a file.

Top


procedure IStorageFromStream(const Storage: IStorage; const Stream: TStream);

description
  Creates an IStorage from TStream.

Top


function IsOutlook64: Boolean;

description
  Checks whether the installed Microsoft Office Outlook (version 2010 and above is 64 bit)

Top


Copyright © 2021 IMIBO
Privacy Statement