| Platform SDK: CDO for Windows 2000 |
You can use the IDataSource.OpenObject method to extract messages contained within the body parts of other Message objects. The process is analogous to opening files in Microsoft Word: the content in the opened file is copied from the disk into the running application. Embedded messages in other messages are contained in body parts with Content-Type message/*. When you encounter such a body part, you can extract it with the following steps:
' Reference to Microsoft ActiveX Data Objects 2.5 Library
' Reference to Microsoft CDO for Windows 2000 Library
Function ExtractMessage(iBp As IBodyPart) As Message
Dim iMsg As New CDO.Message
Dim iDsrc As IDataSource
Set iDsrc = iMsg
iDsrc.OpenObject iBp, "IBodyPart"
Set ExtractMessage = iMsg
End Function
#import "c:\program files\common files\system\ado\msado15.dll" no_namespace
#import <cdosys.dll> no_namespace
// ...
IMessagePtr ExtractMessage(IBodyPartPtr iBp)
{
IMessagePtr iMsg(__uuidof(Message));
IDataSourcePtr iDsrc;
iDsrc = iMsg;
try
{
iDsrc->OpenObject(iBp,_bstr_t("IBodyPart"));
}
catch(_com_error error)
{
throw error;
}
return iMsg;
}
Function ExtractMessage(iBp)
Dim iMsg
Set iMsg = CreateObject("CDO.Message")
Dim iDsrc
Set iDsrc = iMsg.DataSource
iDsrc.OpenObject iBp, "IBodyPart"
Set ExtractMessage = iMsg
End Function