Trying to hide inline attachments

K

krach.aran

I am writing some code to archive mail.
whel looping through my selection i check every e-mail to see if it
contains any attachments. However the outlook api gives me a number of
inline attachments that i don't want to see. I only want to see the
attachments that are visible via the paperclip icon in office.

Does anybody now of a way of detecting these inline attachments.

I tried to look at the attachment.type property, but this is not the
way to go.
I tried analysing the htmlbody to look for the filename, but this was
also no help.

TIA

Otto
 
K

Ken Slovak - [MVP - Outlook]

And the cid will be the same as in the PR_ATTACH_CONTENT_ID (0x3712001E or
urn:schemas:mailheader:content-id) property on the attachment object. That
will give you what to look for if you you're using Outlook 2007 or Extended
MAPI or CDO 1.21 or some other API that allows access to properties not
exposed in the Outlook 2003 or earlier object models.
 
K

krach.aran

This worked for me (don't mid the sloppy code.... cleaners are on
their way ;) ):

public static bool IsValidAttachment(Outlook.MailItem
mailitem, Outlook.Attachment attachment)
{
bool retval = false;
string CID = "";

try
{
if (attachment.FileName != "")
{
// this skips the olOLE types

MAPI.Session session = new Session();
session.Logon("", "", false, false, Type.Missing,
Type.Missing, Type.Missing);
MAPI.Message message =
(MAPI.Message)session.GetMessage(mailitem.EntryID, "");
MAPI.Attachments atts =
(Attachments)message.Attachments;


for (int teller = 0; teller <
mailitem.Attachments.Count; teller++)
{
MAPI.Attachment att =
(MAPI.Attachment)atts.get_Item(teller+1);


MAPI.Fields fields = (MAPI.Fields)att.Fields;
MAPI.Field field =
(MAPI.Field)fields.get_Item(MAPI.CdoPropTags.CdoPR_ATTACH_FILENAME,
null);

if ((string)field.Value ==
attachment.FileName)
{
field =
(MAPI.Field)fields.get_Item(0x3712001F, null);
CID = (string)field.Value;

field =
(MAPI.Field)fields.get_Item(0x37140003, null);


if (!CID.StartsWith(attachment.FileName)
&& (int)field.Value !=4)
retval = true;
}
}
session.Logoff();
}
}
catch
{

}

if (attachment.Type ==
Microsoft.Office.Interop.Outlook.OlAttachmentType.olByValue && CID ==
"")
retval = true;

return retval;
}
 
R

Rick McMullan

Exactly what I was looking for and so obscure! Thanks so much for posting this.

The problem with detecting inline attachments seems only to occur when using HTML mail. The RTF setting doesn't seem to create them.



krach.ara wrote:

This worked for me (don't mid the sloppy code....
23-Feb-08

This worked for me (don't mid the sloppy code.... cleaners are o
their way ;) )

public static bool IsValidAttachment(Outlook.MailIte
mailitem, Outlook.Attachment attachment

bool retval = false
string CID = ""

tr

if (attachment.FileName != ""

// this skips the olOLE type

MAPI.Session session = new Session()
session.Logon("", "", false, false, Type.Missing
Type.Missing, Type.Missing)
MAPI.Message message
(MAPI.Message)session.GetMessage(mailitem.EntryID, "")
MAPI.Attachments atts
(Attachments)message.Attachments

for (int teller = 0; teller
mailitem.Attachments.Count; teller++

MAPI.Attachment att
(MAPI.Attachment)atts.get_Item(teller+1)

MAPI.Fields fields = (MAPI.Fields)att.Fields
MAPI.Field field
(MAPI.Field)fields.get_Item(MAPI.CdoPropTags.CdoPR_ATTACH_FILENAME
null)

if ((string)field.Value =
attachment.FileName

field
(MAPI.Field)fields.get_Item(0x3712001F, null)
CID = (string)field.Value

field
(MAPI.Field)fields.get_Item(0x37140003, null)

if (!CID.StartsWith(attachment.FileName
&& (int)field.Value !=4
retval = true


session.Logoff()


catc




if (attachment.Type =
Microsoft.Office.Interop.Outlook.OlAttachmentType.olByValue && CID =
""
retval = true

return retval
}

Previous Posts In This Thread:

For embedded attachments, you don't find the file name but something likethis
For embedded attachments, you don't find the file name but something lik
this in html

<img src='cid:xxxxx'

--
Best regard
Michael Bauer - MVP Outloo
Use Outlook Categories? This is Your Tool
<http://www.vboffice.net/product.html?id=2006063&cmd=detail&lang=en&pub=6

Am Tue, 12 Feb 2008 02:47:44 -0800 (PST) schrieb (e-mail address removed):

Trying to hide inline attachments
I am writing some code to archive mail
whel looping through my selection i check every e-mail to see if i
contains any attachments. However the outlook api gives me a number o
inline attachments that i don't want to see. I only want to see th
attachments that are visible via the paperclip icon in office

Does anybody now of a way of detecting these inline attachments

I tried to look at the attachment.type property, but this is not th
way to go
I tried analysing the htmlbody to look for the filename, but this wa
also no help

TI

Otto

And the cid will be the same as in the PR_ATTACH_CONTENT_ID (0x3712001E or
And the cid will be the same as in the PR_ATTACH_CONTENT_ID (0x3712001E or
urn:schemas:mailheader:content-id) property on the attachment object. That
will give you what to look for if you you're using Outlook 2007 or Extended
MAPI or CDO 1.21 or some other API that allows access to properties not
exposed in the Outlook 2003 or earlier object models

--
Ken Slova
[MVP - Outlook
http://www.slovaktech.co
Author: Professional Programming Outlook 200
Reminder Manager, Extended Reminders, Attachment Option
http://www.slovaktech.com/products.htm



Unfortunatly, my problem can't be solved in managed code (seefollowing link
Unfortunatly, my problem can't be solved in managed code (see
following link for a quote)
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2472308&SiteID=1

unfortunatly we had to make some consessions in the features of the
application due to the short development time (have to deliver the
software tomorrow)
If i find a solution in managed code, i will post it here.

Thnxs for the pointers however !

This worked for me (don't mid the sloppy code....
This worked for me (don't mid the sloppy code.... cleaners are on
their way ;) ):

public static bool IsValidAttachment(Outlook.MailItem
mailitem, Outlook.Attachment attachment)
{
bool retval = false;
string CID = "";

try
{
if (attachment.FileName != "")
{
// this skips the olOLE types

MAPI.Session session = new Session();
session.Logon("", "", false, false, Type.Missing,
Type.Missing, Type.Missing);
MAPI.Message message =
(MAPI.Message)session.GetMessage(mailitem.EntryID, "");
MAPI.Attachments atts =
(Attachments)message.Attachments;


for (int teller = 0; teller <
mailitem.Attachments.Count; teller++)
{
MAPI.Attachment att =
(MAPI.Attachment)atts.get_Item(teller+1);


MAPI.Fields fields = (MAPI.Fields)att.Fields;
MAPI.Field field =
(MAPI.Field)fields.get_Item(MAPI.CdoPropTags.CdoPR_ATTACH_FILENAME,
null);

if ((string)field.Value ==
attachment.FileName)
{
field =
(MAPI.Field)fields.get_Item(0x3712001F, null);
CID = (string)field.Value;

field =
(MAPI.Field)fields.get_Item(0x37140003, null);


if (!CID.StartsWith(attachment.FileName)
&& (int)field.Value !=4)
retval = true;
}
}
session.Logoff();
}
}
catch
{

}

if (attachment.Type ==
Microsoft.Office.Interop.Outlook.OlAttachmentType.olByValue && CID ==
"")
retval = true;

return retval;
}


Submitted via EggHeadCafe - Software Developer Portal of Choice
BizTalk Repeating Structures Table Looping and Table Extract
http://www.eggheadcafe.com/tutorial...0-a5704fe31a76/biztalk-repeating-structu.aspx
 

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