When trying to convert the MSG-File stored with Microsoft Outlook 15.0 to EML using Outlook 2016 MAPIToMIMEStm API returns different stream output when this API is called multiple times without restarting the process. The Java application loads the JNI dll which converts the messages stored in the .pst file into .eml files.

.eml file content->


MIME-Version: 1.0
Content-Type: multipart/alternative;
boundary="----=_NextPart_000_0004_01D9F13A.C9638500"
X-Mailer: Microsoft Outlook 15.0
Content-Type: text/plain;
    charset="us-ascii"
Content-Transfer-Encoding: 7bit
<PR_BODY>
...

The code snippet is given below.

MAPIINIT_0 MAPIINIT= { 0, MAPI_MULTITHREAD_NOTIFICATIONS};
HRESULT hr = MAPIInitialize(&MAPIINIT);

//Extract IMessage from the IMAPIFolder 
IConverterSession* pConverterSession = NULL;    
hr = CoCreateInstance(CLSID_IConverterSession, NULL, CLSCTX_INPROC_SERVER,
                                  IID_IConverterSession, (void **) &pConverterSession);
                                  
LPSTREAM pStream = NULL;
hr = OpenStreamOnFile(MAPIAllocateBuffer, MAPIFreeBuffer, STGM_CREATE |
        STGM_READWRITE, const_cast<char*>(mbFilename.c_str()), NULL, &pStream);
        
ULONG flags = CCSF_SMTP | CCSF_INCLUDE_BCC | CCSF_8BITHEADERS;
hr = pConverterSession->MAPIToMIMEStm(pMessage, pStream, flags);
//pStream->Stat() shows the stream output of length 4285 which includes the PR_BODY of the IMessage.

pStream->Commit(0);
pStream->Release();
pConverterSession->Release();
MAPIUninitialize();

If the same code is called again without restarting the application then pStream->Stat() shows the stream output of length 4228 excluding the PR_BODY of the IMessage. The MAPIToMIMEStm excludes the PR_BODY of the IMessage during conversion.

If the Java application is restarted, then pStream->Stat() shows that stream output of length 4285 which includes the PR_BODY of the IMessage.

What could be the reasons for this behavior of Outlook MAPI pConverterSession->MAPIToMIMEStm()?

0

There are 0 best solutions below