+2 votes

Is there any way, that i can just delete email attachments only and leave the content text of the email?

by
edited by

1 Answer

0 votes
 
Best answer

No, it is not possible with IMAP nor POP3 protocols.

You could create new email with the same content, without attachments, and upload it to the server.

Removing attachments from a message is a complex problem.

Attachments are part of the message, there is no way to remove them, without modifying email's structure.

This leads to 3 major problems:

  1. Any SMIME signature that mail had is going to be invalidated

  2. Any DKIM signature that mail had is going to be invalidated

  3. When attachments are removed, the root MIME object must also be removed.
    The problem is that it is impossible to distinguish between
    custom email headers and custom headers of the root MIME object,
    so always there is a chance that some information will be lost.

Please note that this is not Mail.dll limitation, but rather limitation of the email system/protocols.

That being said:

Consider using RemoveAttachments method on IMail object.

Internally it re-creates MIME tree if needed, copies all information from original message, skipping the attachments:

IMail original = ...;
original.RemoveAttachments();

There is also ReplaceAttachments method, that replaces all attachments with a text attachment with information, that attachment was removed.

This solves point 3 (as attachments are there, but are much smaller), but still 1 and 2 can never be solved.

Hope this helps a bit.


Of course I don't know your exact scenario, but just one afterthought:

I would store original eml downloaded from the server somewhere. Event if it's big - disk space is quite cheep now.

Parser may incorrectly parse the message, attachments may contain some vital data. In future someone may decide to extract additional information from email attachments.

You can always decide on deleting those files later.

by (297k points)
...