Import stream/byte array into MailItem or SafeMailItem?

A

Arild

Hi,

currently we have a MemoryStream (easily converted to a
byte array) containing all the data from an Outlook
Message. Now we would like to retrieve different
properties from that message.

Is it possible to create an Outlook.MailItem or a
Redemption.SafeMailItem object and then import a
stream/byte array into that object for easy retrieval of
the mail item properties?

Also, we are working with C# - are there known problems
with interop here?

-Arild
 
A

Arild

I will guess that the format is Unicode (but I'm not
quite sure).

I've attached some code to illustrate how we get the byte
array from an unmanaged memory block. We have implemented
the Kernel32.dll in C# to lock and get size of the memory
block. (Conversion to a Stream is done for further
processing in the program).

protected Stream ReadByteStreamFromHandle( IntPtr
handle ) {
Stream stream = null;
HandleRef handleRef = new HandleRef( null,
handle );
IntPtr lockedHandle = Kernel32Lib.GlobalLock(
handleRef );

try {
int size = Kernel32Lib.GlobalSize(
handleRef );

byte[] buffer = new byte[size];
Marshal.Copy( lockedHandle, buffer, 0, size );

stream = new MemoryStream( buffer, 0, size );
} finally {
Kernel32Lib.GlobalUnlock( handleRef );
}

return stream;
}

-Arild
 
Top