How we can find out the format of the mail.

V

Vinayakc

Hi all,

I have written one Outlook add-in in C++. I want to detect the mail
format of the mail through that add-in. ( RTF,HTML or Plain Text ).
I have tried to do some search on this, I only got that, thorugh VBA we
can use BodyFormat property of the mail item. How I can access this
property through my C++ code?

If Outlook is able to detect the format of incoming mail, I think we
should also able to detect the format? Are there any MAPI properties
which we can use for this?

Through OutllookSpy when I look the properties of that mail item, I
observerd that
1. HTML and RTF mails have PR_RTF_COMPRESSED property.
2. Plain text does not have PR_RTF_COMPRESSED property.
3. RTF mails have useTNEF property value as True and HTML mails have
useTNEF property value as False.

Will this observation help us??

Please reply as soon as possible.

Thanks and Regards
Vinayakc
 
D

Dmitry Streblechenko

Read the RTFBody property and check if "\fromhtml1" is in the first 100
bytes or so: if yes, you have HTML. If you have "\fromtext" - it is text.
Otherwise it is pure RTF.
If RTF is missing, check if PR_HTML_BODY or PR_HTML is present.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
V

Vinayakc

Hi Dmitry,

Thanks for your reply.
I have searched for how to access the "RTFBody" property of the mail
item. But I could not get anything on that.
I want to use Outlook object model and MAPI propertries only.
I am not using Redemption.

Thanks and Regards
Vinayakc.
 
D

Dmitry Streblechenko

Open the PR_RTF_COMPRESSED property from IMessage as IStream and uncompress
it using WrapCompressedRtfStream function.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
V

Vinayakc

My code for other's reference :

BOOL CheckHTML(CComPtr<IMessage> pMsg, BOOL* bHtml)
{
HRESULT hr = S_OK;
LPSTREAM lpCompressed = NULL;
LPSTREAM lpUncompressed = NULL;
BOOL bRet = TRUE;
BYTE htmlbuf[UNCOMPRESSED_RTF_BUFFER_MAX_SIZE] = {0};
try
{
hr = pMsg->OpenProperty(PR_RTF_COMPRESSED,
&IID_IStream,
STGM_READ,
0,
(LPUNKNOWN*)&lpCompressed);
if( hr!= S_OK )
{
LOG_ERR_MESSAGE(_T("OpenProperty(): error while opening property
PR_RTF_COMPRESSED. ") , hr);
bRet = FALSE;
goto Error;
}

hr = WrapCompressedRTFStream(lpCompressed,
0,
&lpUncompressed
);

if( hr!= S_OK )
{
LOG_ERR_MESSAGE(_T("WrapCompressedRTFStream(): error while reading
uncompressed property PR_RTF_COMPRESSED. ") , hr);
bRet = FALSE;
goto Error;
}
ULONG red;
hr = lpUncompressed->Read(htmlbuf, UNCOMPRESSED_RTF_BUFFER_MAX_SIZE -
1, &red);
if( lpUncompressed )
lpUncompressed->Release();
if( lpCompressed )
lpCompressed->Release();
htmlbuf[UNCOMPRESSED_RTF_BUFFER_MAX_SIZE]=0;
if( htmlbuf != 0)
{
// We look for the words "\fromhtml1" somewhere in the uncompressed
RTF body
// If it contains "\fromhtml1" then we assume message format as
HTML
if( strstr( (const char*) htmlbuf, "\\fromhtml1" ) != NULL)
{
*bHtml = TRUE;
}
else
{
*bHtml = FALSE;
}
}
goto End;
}
catch(...)
{
LOG_ERR_MESSAGE(_T("Exception Generated") , GetLastError());
REPORT_SYSTEM_ERROR_TO_IRONPORT_HTTP(_T("Exception Generated"));
bRet = FALSE;
goto Error;
}
End:
Error:
return bRet;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top