How to distinguish a "real" email application from photos in html mail?

I was messing around with OpenPop, a C # library for sending POP3 mail. Everything seems to be working fine, but I didn’t quite understand how to make the difference between explicitly attached files to mail and things like pictures in HTML content messages. This library views them all as "attachments." For my needs, I will not consider the image in the HTML letter in the application.
From the library documentation:

MessagePart is considered an attachment if - it does not contain 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, at least in theoretical terms (because I'm not very familiar with mail protocols)?

+6
source share
3 answers

You can check if the image file is indicated in the main body of the message. You will need to parse the HTML and look for tags like img or the background-image property in the CSS selector. If the image is not used by the message itself, then consider it a β€œgenuine” attachment.

+4
source

I am a developer on OpenPop.NET .

These are just some of the reference data about letters that contain attachments. Tony Pony's answer is the way to go.

I also had the problem of distinguishing attachments from non-attachments when I implemented that part of OpenPop.NET. MIME has a Content-Disposition header that can determine if a specific part is an attachment or not.

For example, here is the attachment

 Content-Disposition: attachment 

and there may be an image in the HTML part of the email

 Content-Disposition: inline 

As much as this is pleasant, the problem is that many email clients do not add these headers, which makes reading readers such as OpenPop.NET more difficult. We decided not to look at all parts of the HTML email address to see which images are referenced, and therefore, it now depends on the library user.

If you develop a good solution to the problem, you can add it as an example for the project.

+3
source

I did 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 } } 
+3
source

Source: https://habr.com/ru/post/909947/


All Articles