home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 1997 May
/
Pcwk0597.iso
/
borland
/
cb
/
setup
/
cbuilder
/
data.z
/
MAPI.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1997-02-28
|
19KB
|
497 lines
{*******************************************************}
{ }
{ Delphi Runtime Library }
{ Simple MAPI Interface Unit }
{ }
{ Copyright (c) 1996 Borland International }
{ }
{*******************************************************}
unit Mapi;
interface
uses Windows;
{
Messaging Applications Programming Interface.
Purpose:
This file defines the structures and constants used by that
subset of the Messaging Applications Programming Interface
which is supported under Windows by Microsoft Mail for PC
Networks version 3.x.
}
type
FLAGS = Cardinal;
{$nonamespace FLAGS}
LHANDLE = Cardinal;
{$nonamespace LHANDLE}
PLHANDLE = ^Cardinal;
const
lhSessionNull = (0);
type
PMapiFileDesc = ^TMapiFileDesc;
MapiFileDesc = packed record
ulReserved: Cardinal; { Reserved for future use (must be 0) }
flFlags: Cardinal; { Flags }
nPosition: Cardinal; { character in text to be replaced by attachment }
lpszPathName: LPSTR; { Full path name of attachment file }
lpszFileName: LPSTR; { Original file name (optional) }
lpFileType: Pointer; { Attachment file type (can be lpMapiFileTagExt) }
end;
{$nonamespace MapiFileDesc}
TMapiFileDesc = MapiFileDesc;
const
MAPI_OLE = $00000001;
MAPI_OLE_STATIC = $00000002;
type
PMapiFileTagExt = ^TMapiFileTagExt;
MapiFileTagExt = packed record
ulReserved: Cardinal; { Reserved, must be zero. }
cbTag: Cardinal; { Size (in bytes) of }
lpTag: PByte; { X.400 OID for this attachment type }
cbEncoding: Cardinal; { Size (in bytes) of }
lpEncoding: PByte; { X.400 OID for this attachment's encoding }
end;
{$nonamespace MapiFileTagExt}
TMapiFileTagExt = MapiFileTagExt;
PMapiRecipDesc = ^TMapiRecipDesc;
MapiRecipDesc = packed record
ulReserved: Cardinal; { Reserved for future use }
ulRecipClass: Cardinal; { Recipient class }
{ MAPI_TO, MAPI_CC, MAPI_BCC, MAPI_ORIG }
lpszName: LPSTR; { Recipient name }
lpszAddress: LPSTR; { Recipient address (optional) }
ulEIDSize: Cardinal; { Count in bytes of size of pEntryID }
lpEntryID: Pointer; { System-specific recipient reference }
end;
{$nonamespace MapiRecipDesc}
TMapiRecipDesc = MapiRecipDesc;
const
MAPI_ORIG = 0; { Recipient is message originator }
MAPI_TO = 1; { Recipient is a primary recipient }
MAPI_CC = 2; { Recipient is a copy recipient }
MAPI_BCC = 3; { Recipient is blind copy recipient }
type
PMapiMessage = ^TMapiMessage;
MapiMessage = packed record
ulReserved: Cardinal; { Reserved for future use (M.B. 0) }
lpszSubject: LPSTR; { Message Subject }
lpszNoteText: LPSTR; { Message Text }
lpszMessageType: LPSTR; { Message Class }
lpszDateReceived: LPSTR; { in YYYY/MM/DD HH:MM format }
lpszConversationID: LPSTR; { conversation thread ID }
flFlags: FLAGS; { unread,return receipt }
lpOriginator: PMapiRecipDesc; { Originator descriptor }
nRecipCount: Cardinal; { Number of recipients }
lpRecips: PMapiRecipDesc; { Recipient descriptors }
nFileCount: Cardinal; { # of file attachments }
lpFiles: PMapiFileDesc; { Attachment descriptors }
end;
{$nonamespace MapiMessage}
TMapiMessage = MapiMessage;
const
MAPI_UNREAD = $00000001;
MAPI_RECEIPT_REQUESTED = $00000002;
MAPI_SENT = $00000004;
{ Entry points. }
{ flFlags values for Simple MAPI entry points. All documented flags are
shown for each call. Duplicates are commented out but remain present
for every call. }
{ MAPILogon() flags. }
MAPI_LOGON_UI = $00000001; { Display logon UI }
MAPI_PASSWORD_UI = $00020000; { prompt for password only }
MAPI_NEW_SESSION = $00000002; { Don't use shared session }
MAPI_FORCE_DOWNLOAD = $00001000; { Get new mail before return }
MAPI_ALLOW_OTHERS = $00000008; { Make this a shared session }
MAPI_EXPLICIT_PROFILE = $00000010; { Don't use default profile }
MAPI_EXTENDED = $00000020; { Extended MAPI Logon }
MAPI_USE_DEFAULT = $00000040; { Use default profile in logon }
MAPI_SIMPLE_DEFAULT = MAPI_LOGON_UI or MAPI_FORCE_DOWNLOAD or MAPI_ALLOW_OTHERS;
MAPI_SIMPLE_EXPLICIT = MAPI_NEW_SESSION or MAPI_FORCE_DOWNLOAD or MAPI_EXPLICIT_PROFILE;
{ MAPILogoff() flags. }
MAPI_LOGOFF_SHARED = $00000001; { Close all shared sessions }
MAPI_LOGOFF_UI = $00000002; { It's OK to present UI }
{ MAPISendMail() flags. }
{ #define MAPI_LOGON_UI 0x00000001 Display logon UI }
{ #define MAPI_NEW_SESSION 0x00000002 Don't use shared session }
MAPI_DIALOG = $00000008; { Display a send note UI }
{ # define MAPI_USE_DEFAULT 0x00000040 Use default profile in logon }
{ MAPIFindNext() flags. }
MAPI_UNREAD_ONLY = $00000020; { Only unread messages }
MAPI_GUARANTEE_FIFO = $00000100; { use date order }
MAPI_LONG_MSGID = $00004000; { allow 512 char returned ID }
{ MAPIReadMail() flags. }
MAPI_PEEK = $00000080; { Do not mark as read. }
MAPI_SUPPRESS_ATTACH = $00000800; { header + body, no files }
MAPI_ENVELOPE_ONLY = $00000040; { Only header information }
MAPI_BODY_AS_FILE = $00000200;
{ MAPISaveMail() flags. }
{ #define MAPI_LOGON_UI 0x00000001 Display logon UI }
{ #define MAPI_NEW_SESSION 0x00000002 Don't use shared session }
{ #define MAPI_LONG_MSGID 0x00004000 /* allow 512 char returned ID }
{ MAPIAddress() flags. }
{ #define MAPI_LOGON_UI 0x00000001 Display logon UI }
{ #define MAPI_NEW_SESSION 0x00000002 Don't use shared session }
{ MAPIDetails() flags. }
{ #define MAPI_LOGON_UI 0x00000001 Display logon UI }
{ #define MAPI_NEW_SESSION 0x00000002 Don't use shared session }
MAPI_AB_NOMODIFY = $00000400; { Don't allow mods of AB entries }
{ MAPIResolveName() flags. }
{ #define MAPI_LOGON_UI 0x00000001 Display logon UI }
{ #define MAPI_NEW_SESSION 0x00000002 Don't use shared session }
{ #define MAPI_DIALOG 0x00000008 Prompt for choices if ambiguous }
{ #define MAPI_AB_NOMODIFY 0x00000400 Don't allow mods of AB entries }
type
PFNMapiLogon = ^TFNMapiLogOn;
TFNMapiLogOn = function(ulUIParam: Cardinal; lpszProfileName: LPSTR;
lpszPassword: LPSTR; flFlags: FLAGS; ulReserved: Cardinal;
lplhSession: PLHANDLE): Cardinal stdcall;
PFNMapiLogOff = ^TFNMapiLogOff;
TFNMapiLogOff = function(lhSession: LHANDLE; ulUIParam: Cardinal; flFlags: FLAGS;
ulReserved: Cardinal): Cardinal stdcall;
PFNMapiSendMail = ^TFNMapiSendMail;
TFNMapiSendMail = function(lhSession: LHANDLE; ulUIParam: Cardinal;
var lpMessage: TMapiMessage; flFlags: FLAGS;
ulReserved: Cardinal): Cardinal stdcall;
PFNMapiSendDocuments = ^TFNMapiSendDocuments;
TFNMapiSendDocuments = function(ulUIParam: Cardinal; lpszDelimChar: LPSTR;
lpszFilePaths: LPSTR; lpszFileNames: LPSTR;
ulReserved: Cardinal): Cardinal stdcall;
PFNMapiFindNext = ^TFNMapiFindNext;
TFNMapiFindNext = function(lhSession: LHANDLE; ulUIParam: Cardinal;
lpszMessageType: LPSTR; lpszSeedMessageID: LPSTR; flFlags: FLAGS;
ulReserved: Cardinal; lpszMessageID: LPSTR): Cardinal stdcall;
PFNMapiReadMail = ^TFNMapiReadMail;
TFNMapiReadMail = function(lhSession: LHANDLE; ulUIParam: Cardinal;
lpszMessageID: LPSTR; flFlags: FLAGS; ulReserved: Cardinal;
var lppMessage: PMapiMessage): Cardinal stdcall;
PFNMapiSaveMail = ^TFNMapiSaveMail;
TFNMapiSaveMail = function(lhSession: LHANDLE; ulUIParam: Cardinal;
var lpMessage: TMapiMessage; flFlags: FLAGS; ulReserved: Cardinal;
lpszMessageID: LPSTR): Cardinal stdcall;
PFNMapiDeleteMail = ^TFNMapiDeleteMail;
TFNMapiDeleteMail = function(lhSession: LHANDLE; ulUIParam: Cardinal;
lpszMessageID: LPSTR; flFlags: FLAGS;
ulReserved: Cardinal): Cardinal stdcall;
PFNMapiFreeBuffer = ^TFNMapiFreeBuffer;
TFNMapiFreeBuffer = function(pv: Pointer): Cardinal stdcall;
PFNMapiAddress = ^TFNMapiAddress;
TFNMapiAddress = function(lhSession: LHANDLE; ulUIParam: Cardinal;
lpszCaption: LPSTR; nEditFields: Cardinal; lpszLabels: LPSTR;
nRecips: Cardinal; var lpRecips: TMapiRecipDesc; flFlags: FLAGS;
ulReserved: Cardinal; lpnNewRecips: PULONG;
var lppNewRecips: PMapiRecipDesc): Cardinal stdcall;
PFNMapiDetails = ^TFNMapiDetails;
TFNMapiDetails = function(lhSession: LHANDLE; ulUIParam: Cardinal;
var lpRecip: TMapiRecipDesc; flFlags: FLAGS;
ulReserved: Cardinal): Cardinal stdcall;
PFNMapiResolveName = ^TFNMapiResolveName;
TFNMapiResolveName = function(lhSession: LHANDLE; ulUIParam: Cardinal;
lpszName: LPSTR; flFlags: FLAGS; ulReserved: Cardinal;
var lppRecip: PMapiRecipDesc): Cardinal stdcall;
const
SUCCESS_SUCCESS = 0;
MAPI_USER_ABORT = 1;
MAPI_E_USER_ABORT = MAPI_USER_ABORT;
MAPI_E_FAILURE = 2;
MAPI_E_LOGON_FAILURE = 3;
MAPI_E_LOGIN_FAILURE = MAPI_E_LOGON_FAILURE;
MAPI_E_DISK_FULL = 4;
MAPI_E_INSUFFICIENT_MEMORY = 5;
MAPI_E_ACCESS_DENIED = 6;
MAPI_E_TOO_MANY_SESSIONS = 8;
MAPI_E_TOO_MANY_FILES = 9;
MAPI_E_TOO_MANY_RECIPIENTS = 10;
MAPI_E_ATTACHMENT_NOT_FOUND = 11;
MAPI_E_ATTACHMENT_OPEN_FAILURE = 12;
MAPI_E_ATTACHMENT_WRITE_FAILURE = 13;
MAPI_E_UNKNOWN_RECIPIENT = 14;
MAPI_E_BAD_RECIPTYPE = 15;
MAPI_E_NO_MESSAGES = 16;
MAPI_E_INVALID_MESSAGE = 17;
MAPI_E_TEXT_TOO_LARGE = 18;
MAPI_E_INVALID_SESSION = 19;
MAPI_E_TYPE_NOT_SUPPORTED = 20;
MAPI_E_AMBIGUOUS_RECIPIENT = 21;
MAPI_E_AMBIG_RECIP = MAPI_E_AMBIGUOUS_RECIPIENT;
MAPI_E_MESSAGE_IN_USE = 22;
MAPI_E_NETWORK_FAILURE = 23;
MAPI_E_INVALID_EDITFIELDS = 24;
MAPI_E_INVALID_RECIPS = 25;
MAPI_E_NOT_SUPPORTED = 26;
{ Delphi wrapper calls around Simple MAPI }
function MapiLogOn(ulUIParam: Cardinal; lpszProfileName: LPSTR;
lpszPassword: LPSTR; flFlags: FLAGS; ulReserved: Cardinal;
lplhSession: PLHANDLE): Cardinal;
function MapiLogOff(lhSession: LHANDLE; ulUIParam: Cardinal; flFlags: FLAGS;
ulReserved: Cardinal): Cardinal;
function MapiSendMail(lhSession: LHANDLE; ulUIParam: Cardinal;
var lpMessage: TMapiMessage; flFlags: FLAGS; ulReserved: Cardinal): Cardinal;
function MapiSendDocuments(ulUIParam: Cardinal; lpszDelimChar: LPSTR;
lpszFilePaths: LPSTR; lpszFileNames: LPSTR; ulReserved: Cardinal): Cardinal;
function MapiFindNext(lhSession: LHANDLE; ulUIParam: Cardinal;
lpszMessageType: LPSTR; lpszSeedMessageID: LPSTR; flFlags: FLAGS;
ulReserved: Cardinal; lpszMessageID: LPSTR): Cardinal;
function MapiReadMail(lhSession: LHANDLE; ulUIParam: Cardinal;
lpszMessageID: LPSTR; flFlags: FLAGS; ulReserved: Cardinal;
var lppMessage: PMapiMessage): Cardinal;
function MapiSaveMail(lhSession: LHANDLE; ulUIParam: Cardinal;
var lpMessage: TMapiMessage; flFlags: FLAGS; ulReserved: Cardinal;
lpszMessageID: LPSTR): Cardinal;
function MapiDeleteMail(lhSession: LHANDLE; ulUIParam: Cardinal;
lpszMessageID: LPSTR; flFlags: FLAGS;
ulReserved: Cardinal): Cardinal;
function MapiFreeBuffer(pv: Pointer): Cardinal;
function MapiAddress(lhSession: LHANDLE; ulUIParam: Cardinal;
lpszCaption: LPSTR; nEditFields: Cardinal; lpszLabels: LPSTR;
nRecips: Cardinal; var lpRecips: TMapiRecipDesc; flFlags: FLAGS;
ulReserved: Cardinal; lpnNewRecips: PULONG;
var lppNewRecips: PMapiRecipDesc): Cardinal;
function MapiDetails(lhSession: LHANDLE; ulUIParam: Cardinal;
var lpRecip: TMapiRecipDesc; flFlags: FLAGS;
ulReserved: Cardinal): Cardinal;
function MapiResolveName(lhSession: LHANDLE; ulUIParam: Cardinal;
lpszName: LPSTR; flFlags: FLAGS; ulReserved: Cardinal;
var lppRecip: PMapiRecipDesc): Cardinal;
var
MAPIDLL: string = 'MAPI32.DLL';
implementation
var
MAPIModule: HModule = 0;
LogOn: TFNMapiLogOn = nil;
LogOff: TFNMapiLogOff = nil;
SendMail: TFNMapiSendMail = nil;
SendDocuments: TFNMapiSendDocuments = nil;
FindNext: TFNMapiFindNext = nil;
ReadMail: TFNMapiReadMail = nil;
SaveMail: TFNMapiSaveMail = nil;
DeleteMail: TFNMapiDeleteMail = nil;
FreeBuffer: TFNMapiFreeBuffer = nil;
Address: TFNMapiAddress = nil;
Details: TFNMapiDetails = nil;
ResolveName: TFNMapiResolveName = nil;
procedure InitMapi;
begin
if MAPIModule = 0 then
MAPIModule := LoadLibrary(PChar(MAPIDLL));
end;
function MapiLogOn(ulUIParam: Cardinal; lpszProfileName: LPSTR;
lpszPassword: LPSTR; flFlags: FLAGS; ulReserved: Cardinal;
lplhSession: PLHANDLE): Cardinal;
begin
InitMapi;
if @LogOn = nil then
@LogOn := GetProcAddress(MAPIModule, 'MAPILogon');
if @LogOn <> nil then
Result := LogOn(ulUIParam, lpszProfileName, lpszPassword, flFlags,
ulReserved, lplhSession)
else Result := 1;
end;
function MapiLogOff(lhSession: LHANDLE; ulUIParam: Cardinal; flFlags: FLAGS;
ulReserved: Cardinal): Cardinal;
begin
InitMapi;
if @LogOff = nil then
@LogOff := GetProcAddress(MAPIModule, 'MAPILogoff');
if @LogOff <> nil then
Result := LogOff(lhSession, ulUIParam, flFlags, ulReserved)
else Result := 1;
end;
function MapiSendMail(lhSession: LHANDLE; ulUIParam: Cardinal;
var lpMessage: TMapiMessage; flFlags: FLAGS; ulReserved: Cardinal): Cardinal;
begin
InitMapi;
if @SendMail = nil then
@SendMail := GetProcAddress(MAPIModule, 'MAPISendMail');
if @SendMail <> nil then
Result := SendMail(lhSession, ulUIParam, lpMessage, flFlags, ulReserved)
else Result := 1;
end;
function MapiSendDocuments(ulUIParam: Cardinal; lpszDelimChar: LPSTR;
lpszFilePaths: LPSTR; lpszFileNames: LPSTR;
ulReserved: Cardinal): Cardinal;
begin
InitMapi;
if @SendDocuments = nil then
@SendDocuments := GetProcAddress(MAPIModule, 'MAPISendDocuments');
if @SendDocuments <> nil then
Result := SendDocuments(ulUIParam, lpszDelimChar, lpszFilePaths,
lpszFileNames, ulReserved)
else Result := 1;
end;
function MapiFindNext(lhSession: LHANDLE; ulUIParam: Cardinal;
lpszMessageType: LPSTR; lpszSeedMessageID: LPSTR; flFlags: FLAGS;
ulReserved: Cardinal; lpszMessageID: LPSTR): Cardinal;
begin
InitMapi;
if @FindNext = nil then
@FindNext := GetProcAddress(MAPIModule, 'MAPIFindNext');
if @FindNext <> nil then
Result := FindNext(lhSession, ulUIParam, lpszMessageType,
lpszSeedMessageID, flFlags, ulReserved, lpszMessageID)
else Result := 1;
end;
function MapiReadMail(lhSession: LHANDLE; ulUIParam: Cardinal;
lpszMessageID: LPSTR; flFlags: FLAGS; ulReserved: Cardinal;
var lppMessage: PMapiMessage): Cardinal;
begin
InitMapi;
if @ReadMail = nil then
@ReadMail := GetProcAddress(MAPIModule, 'MAPIReadMail');
if @ReadMail <> nil then
Result := ReadMail(lhSession, ulUIParam, lpszMessageID, flFlags,
ulReserved, lppMessage)
else Result := 1;
end;
function MapiSaveMail(lhSession: LHANDLE; ulUIParam: Cardinal;
var lpMessage: TMapiMessage; flFlags: FLAGS; ulReserved: Cardinal;
lpszMessageID: LPSTR): Cardinal;
begin
InitMapi;
if @SaveMail = nil then
@SaveMail := GetProcAddress(MAPIModule, 'MAPISaveMail');
if @SaveMail <> nil then
Result := SaveMail(lhSession, ulUIParam, lpMessage, flFlags, ulReserved,
lpszMessageID)
else Result := 1;
end;
function MapiDeleteMail(lhSession: LHANDLE; ulUIParam: Cardinal;
lpszMessageID: LPSTR; flFlags: FLAGS;
ulReserved: Cardinal): Cardinal;
begin
InitMapi;
if @DeleteMail = nil then
@DeleteMail := GetProcAddress(MAPIModule, 'MAPIDeleteMail');
if @DeleteMail <> nil then
Result := DeleteMail(lhSession, ulUIParam, lpszMessageID, flFlags,
ulReserved)
else Result := 1;
end;
function MapiFreeBuffer(pv: Pointer): Cardinal;
begin
InitMapi;
if @FreeBuffer = nil then
@FreeBuffer := GetProcAddress(MAPIModule, 'MAPIFreeBuffer');
if @FreeBuffer <> nil then
Result := FreeBuffer(pv)
else Result := 1;
end;
function MapiAddress(lhSession: LHANDLE; ulUIParam: Cardinal;
lpszCaption: LPSTR; nEditFields: Cardinal; lpszLabels: LPSTR;
nRecips: Cardinal; var lpRecips: TMapiRecipDesc; flFlags: FLAGS;
ulReserved: Cardinal; lpnNewRecips: PULONG;
var lppNewRecips: PMapiRecipDesc): Cardinal;
begin
InitMapi;
if @Address = nil then
@Address := GetProcAddress(MAPIModule, 'MAPIAddress');
if @Address <> nil then
Result := Address(lhSession, ulUIParam, lpszCaption, nEditFields,
lpszLabels, nRecips, lpRecips, flFlags, ulReserved, lpnNewRecips,
lppNewRecips)
else Result := 1;
end;
function MapiDetails(lhSession: LHANDLE; ulUIParam: Cardinal;
var lpRecip: TMapiRecipDesc; flFlags: FLAGS; ulReserved: Cardinal): Cardinal;
begin
InitMapi;
if @Details = nil then
@Details := GetProcAddress(MAPIModule, 'MAPIDetails');
if @Details <> nil then
Result := Details(lhSession, ulUIParam, lpRecip, flFlags, ulReserved)
else Result := 1;
end;
function MapiResolveName(lhSession: LHANDLE; ulUIParam: Cardinal;
lpszName: LPSTR; flFlags: FLAGS; ulReserved: Cardinal;
var lppRecip: PMapiRecipDesc): Cardinal;
begin
InitMapi;
if @ResolveName = nil then
@ResolveName := GetProcAddress(MAPIModule, 'MAPIResolveName');
if @ResolveName <> nil then
Result := ResolveName(lhSession, ulUIParam, lpszName, flFlags,
ulReserved, lppRecip)
else Result := 1;
end;
initialization
finalization
if MAPIModule <> 0 then FreeLibrary(MAPIModule);
end.