Remove Outlook Attachments, But Not Inline Images
Posted on 2009-12-16
In order to reduce PST size, I've written a routine that removes attachments from a given e-mail. asks me to save them, and inserts a list of removed attachments below the body text. This is available through a button in an open e-mail and is triggered whenever I've sent an e-mail.
It works perfectly, except for the fact that it *also* removes images embedded in the e-mail body (HTML format). It seems that I cannot distinguish through code between attachments and attachments posing as inline images. The FileName and DisplayName properties are no help, nor is the Position property, which gives me the position of the attachments relative to the Body, not the HTMLBody (or I could simply look for an IMG tag at the Position). The IMG tags in the HTMLBody refer to a CID code, not to the file name, so I can't use that either to determine which attachments are actually inline pictures.
I've considered the following extremely fault sensistive and cumbersome solution:
- Check each attachment's Position
- Look in the Body before the Position and register what text, if any, is there
- Look for that text in the HTMLBody and check if the text is followed (closely) by an IMG tag.
This might work, kinda, but seems rather complicated for something that should be simple.