HTMLBody problem

  • Thread starter Thread starter dorutzu
  • Start date Start date
D

dorutzu

Hi,

I'm trying to do something similar to the Image Blocking made by
Outlook 2003. So when a new Inspector is open, I take the MailItem
that is to be shown and modify it't HTMLBody to block the images. The
problem is that usualy, the first time I open the item, the images are
there, and the next times, the images are blocked. Could you tell me
why this is happening, and how could I avoid this? Is something
related to the timing or something like that?

Thanks,
Doru
 
Because you modify the HTMLBody and the changes persist. The next time you
open the message, you see the result of the modification.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
...and is there any way not to show the e-mail with the images, just the
one with the bloked ones? In other words, is there any way to change the
e-mail(with the modified one) in the Inspector before it is displayed,
without closing the inspector and re-opening it(using the same
inspector)?

Thanks for all your answers,
Doru
 
Sure, set the HTMLBody property, but make sure the change does not get
saved.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
I think you got me wrong. The problem is the exact oposite: I want to
display the changed e-mail(bloked pictures) in the Inspector before
diplaying the original one(with pictures). It doesn't matter if the
changed e-mail gets saved (that's even better)...The whole idea is to
prevent somehow the images to get downloaded...and I don't have access
to the e-mail before the OnNewInspector event fires, so I take the
e-mail from the inspector, change it's HTMLBody, but the displayed
e-mail is the original one(before changes).

Sorry to bug you :-)
Doru
 
Hmmm... Changing the HTMLBody propety always worked for me. What is your
code?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
My code is written in VC++, hope it helps(if not, the comments should be
enough):

void __stdcall CAddin::OnNewInspector(IDispatch * Ctrl)
{
USES_CONVERSION;
//get opening inspector
CComQIPtr<Outlook::_Inspector> spInspector(Ctrl);
if(spInspector == NULL)
return;
//get current item
CComPtr<IDispatch> spDispCurItem;
hr = spInspector->get_CurrentItem(&spDispCurItem);
if(FAILED(hr))
return;

CComQIPtr<Outlook::_MailItem> spMailItem(spDispCurItem);
if(spMailItem == NULL)
return;

OlBodyFormat bf;
hr = spMailItem->get_BodyFormat(&bf);
if(FAILED(hr))
return;
//if it;s not HTML format, we don't care about it
if(bf != olFormatHTML)
{
return;
}

hr = spMailItem->get_HTMLBody(&bstrString);
if(FAILED(hr))
return;
//get the HTMLBody in modifiedBody
CString modifiedBody = W2T(bstrString);
//my HTML stripping function
if(!m_pMain->StripHTML(&modifiedBody)) //if we didn't find any pictures
return;
//put back the modified(stripped of pictures) body
bstrString = T2W(modifiedBody);
hr = spMailItem->put_HTMLBody(bstrString);
if(FAILED(hr))
return;
}

That's about all. And indeed it works, but never the first time...First
time, the images get downloaded. How should I make to not to display the
original e-mail, just the modified one?

Thanks for your time,
Doru
 
Hmmm.. Looks fine to me unless the HTML that you set is corrupted. If you
try to immediately read the HTML after setting it, is it what you'd expect?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
Well, I tested both things: the html is well formed, and after setting
the HTMLBody, when I look at it again, it's ok, as expected. The problem
is that I have to somehow refresh the content of the Inspector...

Here is some code added:

//a very simple html content, which is well formed for sure :-)
modifiedBody = "the new HTML Body";
bstrString = T2W(modifiedBody);
hr = spMailItem->put_HTMLBody(bstrString);
if(FAILED(hr))
return;
//after setting the new value, I take it again to assure is' ok
hr = spMailItem->get_HTMLBody(&bstrString);
AfxMessageBox(W2T(bstrString));

When I run it, when the inspector opens, the original e-mail is loaded
in the inspector, but the messagebox says "the new HTML Body", and on
next open of the e-mail, "the new HTML Body" appears. If there is a way
to force the Inspector to refresh after setting the new body content
would be just perfect.
I also tried to Close() the Inspector, and then Display() the e-mail,
but the result is the same...

Thanks again for all your advices and pacience,
Doru
 
I can only think of using Inspector.HTMLEditor (which returns HTMLDocument
object) to directly manipulate the HTML...

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
Thanks! That sounds nice...the only problem I have is that I don't know
how to initialize the HTMLDocument in VC++. Could you give me an example
or a link to something similar?
For now, all I did was:

CComPtr<IDispatch> spDisp;
spInspector->get_HTMLEditor(&spDisp);

//what next?

Thanks,
Doru
 
Back
Top