in-line image, when does outlook remove from attachment

  • Thread starter Thread starter Krishna
  • Start date Start date
K

Krishna

I am developing an "encryption type" plug-in to Outlook 2003 using
C# based on Outlook Object Model.
I am having trouble when the email has an inline image, i.e. when an
image is pasted into the email message body. I understand that the
image is referenced with a CID and it is actually transmitted as an
attachment.

Here is my problem.
On the receiving side, when does outlook actually remove the image from
attachment and place it inline in the email message.
When I place my decryption code in mail-item open event-handler, the
image is not shown and instead a red-cross mark is shown. All I do is
in the mail-item open event-handler; I read the received email body,
decrypt it and set the HTMLBody to the decrypted data. But, if I close
the inspector and let outlook open the same decrypted message; I get
back the email with the inline image. (I am not doing any encryption to
the attachment.)
Are there any flags that I should set in addition to setting the
HTMLBody of the mail-item in the receiving side.

Any help/suggestion is greatly appreciated.
Thanks,
Krishna.
 
Outlook does not remove aan image from the message attachments, it is still
there, Outlook simply adds an extra property (PR_ATTACH_CONTENT_ID) to
correlate the <img> tag with the attachment.
Is the property correctly set on teh attachment? Does your HTML body specify
the right value of the cid attributes in the img tags?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
Thanks for the reply. I checked with OutlookSpy and all the flags seem
to be set correctly. I am pasting the tags from OutlookSpy.

PR_ATTACH_CONTENT_ID_W PT_UNICODE [email protected]
PR_ATTACH_FILENAME PT_STRING8 image001.gif
PR_ATTACH_FILENAME_W PT_UNICODE image001.gif
PR_ATTACH_LONG_FILENAME PT_STRING8 image001.gif
PR_ATTACH_LONG_FILENAME_W PT_UNICODE image001.gif
PR_ATTACH_METHOD PT_LONG 1
PR_ATTACH_MIME_TAG_W PT_UNICODE image/gif
PR_ATTACH_NUM PT_LONG 0
PR_ATTACH_SIZE PT_LONG 27289
PR_ATTACH_TAG PT_BINARY cb:9, lpb: 2A 86 48 86 F7 14 03 0A 04
PR_RECORD_KEY PT_BINARY cb:4, lpb: A5 06 01 00
PR_RENDERING_POSITION PT_LONG -1


And, in the HTMLBody, I am actually setting the same data that I get in
the send-event handler. I am doing it manually in the debugger, so the
HTMLBody is the same. The HTMLBody segment is here:

<body lang=EN-US link=blue vlink=purple>\r\n\r\n<div
class=Section1>\r\n\r\n<p class=MsoNormal><font size=2 face=Arial><span
style='font-size:10.0pt;\r\nfont-family:Arial'><img width=640
height=480
id=\"_x0000_i1025\"\r\nsrc=\"cid:[email protected]\">…123456…<o:p></o:p></span></font></p>\r\n\r\n</div>\r\n\r\n</body>\r\n\r\n</html>\r\n"

Also, if i simply close the inspector window with the red-cross mark
and re-open, i get the image correctly. So I guess there is something I
am missing when I set the HTMLBody manually in the mail-item open event
handler and let outlook display it, and when compared to outlook
directly openning the email with email body set appropriately.
 
But HTMLBody is different from the original body on the receiving side,
right? If I remember correctly, Outlook does not reparse the attachments
collection when HTML body with cid's is set.
Why not modify the message when it is received rather than justs before it
is displayed?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
But HTMLBody is different from the original body on the receiving side,
Yes. Right now I am doing everything manually in the debugger (like
copying the contents of HTMLBody bef actually modifying it and redoing
the same in open event) and can get the same behaviour programatically.
If I remember correctly, Outlook does not reparse the attachments
collection when HTML body with cid's is set.

This explains exactly what I have been looking for. Thanks a lot.


As you suggested, I tried to modify when I receive the message, and it
works.
But my application cannot store decrypted messages in outlook and that
is why I have to place the decryption part in the mail-item open event
handler.
(While closing, I actually put-back the encoded data).
Is there any work-around for manipulating outlook reparsing the
attachments in the Open event handler.
 
But HTMLBody is different from the original body on the receiving side,
Yes. Right now I am doing everything manually in the debugger (like
copying the contents of HTMLBody bef actually modifying it and redoing
the same in open event) and can get the same behaviour programatically.
If I remember correctly, Outlook does not reparse the attachments
collection when HTML body with cid's is set.

This explains exactly what I have been looking for. Thanks a lot.


As you suggested, I tried to modify when I receive the message, and it
works.
But my application cannot store decrypted messages in outlook and that
is why I have to place the decryption part in the mail-item open event
handler.
(While closing, I actually put-back the encoded data).
Is there any work-around for manipulating outlook reparsing the
attachments in the Open event handler.
 
Doesn't sound like the most secure approach - what happens if the user hits
Save when the message is displayed and then Outlook crashes or your add-in
becomes disabled?
Sounds like an ideal candidate for a custom form - you will never have to
put unencrypted data back, but you can display pretty much anaything you
want in your custom form.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
thanks for pointing out the security issues in my approach. i did not
think of them.
i don't know much about custom forms.
if i understand correctly, are you suggesting that everytime i display
a message, i display it in a custom form.
so everytime i get an open mail event, i translate the contents from
that mailitem to my custom form and associate the inspector with my
custom form. is that how it works.
 
Yes, essentially you would need to design a custom form for a custom message
class. If a message has the right message class (e.g. IPM.Note.MyForm) your
form would be invoked.
I am not an expert in Outlook forms (I did do custom MAPI forms, but it is a
totally different beast), so you might want to post in the
microsoft.public.office.developer.outlook.forms newsgroup

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
Thanks for the help. I will read about Custom Forms and goto
microsoft.public.office.developer.outlook.forms.
 
Back
Top