Reading .msg files

Reading .msg files

Post by Jeff McKa » Fri, 10 Jun 2005 15:14:11


I have a need to write mapi code that will take as input an Outlook
generated .msg file, and
view it's properties. A while ago someone pointed me to code that would do
the opposite,
i.e. create a .msg file from a message object (see
http://www.yqcomputer.com/ ;en-us;171907). Is there
similar example code for what I need to do, or can someone give me an
overview?
 
 
 

Reading .msg files

Post by Iv Borisso » Fri, 10 Jun 2005 20:00:53

This s Pascal (Delphi) code, but you can easy translate it to domethig
other:


try
hr := StgOpenStorage(PWideChar(MessageFileName),
nil,
STGM_TRANSACTED or
STGM_SHARE_EXCLUSIVE or
STGM_READWRITE,
nil, 0, Storage);
if failed(hr) then
begin
MessageDlg('StgOpenStorage Error!' , mtError, [mbOK], 0);
exit;
end;

Pointer(Malloc):=MAPIGetDefaultMalloc;

if not Assigned(Malloc) then
begin
MessageDlg('MAPIGetDefaultMalloc Error!' , mtError, [mbOK], 0);
exit;
end;

hr := OpenIMsgOnIStg(
nil,//Input parameter pointing to a message session object.
@MAPIAllocateBuffer, //Input parameter pointing to the
MAPIAllocateBuffer function.
@MAPIAllocateMore,//Input parameter pointing to the MAPIAllocateMore
function
@MAPIFreeBuffer,//Input parameter pointing to the MAPIAllocateMore
function
Malloc, //Input parameter pointing to a standard OLE memory
allocator
nil, //Input parameter pointing to an optional MAPI support
object
Storage, //Input-output parameter pointing to an IStorage
object that is open and has read-write access
nil, //Input parameter pointing to a message-release
callback function
0, //Input parameter containing caller data to be written
by the callback function
0, //Input parameter containing a bitmask of flags used
to control whether the OLE method
// IStorage.Commit is called when the client calls
the IMessage.SaveChanges method
Msg //Output parameter pointing to a variable where the
returned message object is stored.
);

if failed(hr) then
begin
MessageDlg('OpenIMsgOnIStg Error!' , mtError, [mbOK], 0);
exit;
end;

if Assigned(Msg) then
begin
// DO SOMETHING WITH Msg Interface
end;
finally
if Assigned(Msg) then Msg:=nil;
if Assigned(Storage) then Storage:=nil;
if Assigned(Malloc) then Malloc := nil;
end;


--
Iv Borissov
IMI Support Team
http://www.yqcomputer.com/

*everything that has a beginning has an end*


do