Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to distinguish "real" mail attachment from pics in html mail?

I was messing around with OpenPop, a library written in C# for POP3 mail fetch. It seems to work OK, but I didn't quite get the idea how to make a difference between explicitly attached files to mail, and stuff like pictures in HTML-content mails. This library treats them all as "attachments". For my needs I wouldn't consider a picture within HTML mail an attachment.
From the library docs:

A MessagePart is considered to be an attachment, if
- it is not holding text and is not a MultiPart message or
- it has a Content-Disposition header that says it is an attachment

What should I do or search for, at least in theoretical terms (because I'm not really familiar with mail protocols)?

like image 572
Less Avatar asked Mar 04 '12 17:03

Less


2 Answers

You could check if the image file is referenced in the body text of the email. You would need to parse the HTML and look for tags such as img or the background-image property in a CSS selector. If the image is not used by the message itself, then consider it to be a "genuine" attachment.

like image 128
Tony the Pony Avatar answered Sep 16 '22 20:09

Tony the Pony


I've done it this way and it seems to work:

foreach (OpenPop.Mime.MessagePart fileItem in elencoAtt)
{
    System.Net.Mime.ContentDisposition cDisp = fileItem.ContentDisposition;

    //Check for the attachment...
    if (!cDisp.Inline)
    {
        // Attachment not in-line
    }
    else
    {
        // Attachment in-line
    }
}
like image 41
Fabio Avatar answered Sep 18 '22 20:09

Fabio