Imagine a mail server that supports attachments in the range of 400-500 mb. Or Imagine a mail that is 30 mb, but has 10 attachments - if we have to download the whole message each time we wish to remove an attachment from it, that's a 300 mb overhead the GC has to take care of.
IMailFolder.GetMessage
is nice, but in cases such as these, it's better to use IMailFolder.Fetch
.
Sadly though, I don't see a way in which I can add something to an IMessageSummary
(in my case, I'd like to add an attachment, or remove an attachment) and "modify" that message I fetched on the server with my change. That's possible by using ImailFolder.Append(MimeMessage)
, but as the method signature implies, it requires a MimeMessage
, which IMessageSummary
is not.
Any ideas?
First, let me clear something up:
The information contained on the IMessageSummary
is really meant as read-only metadata about the message. The Body
and Attachments
properties aren't the full MIME parts, they are just metadata about the MIME parts.
Okay, now that that is out of the way:
The base IMAP protocol does not support doing what you want to do. What you would need to do is download the full message, make changes to the message, append the modified message to the IMAP folder, and then delete the old (original) message.
If the server supports the REPLACE
extension, then the APPEND + STORE FLAGS \Deleted + EXPUNGE operations can be made atomic, but the gist of it is still the same in that you'd still need to download the message, modify it, and then upload it back to the server.
I think that covers your previous stackoverflow question here: How to move an attachment from one e-mail to another using MailKit/MimeKit?
(including it for context in case anyone reading this is interested in knowing the solution for that)
But this question is different from the old question in that you are asking if there is a more efficient way of adding or removing MIME parts from a message on the IMAP server without having to download it locally first.
There just so happens to be an IMAP extension called CATENATE that kind of allows for this.
Unfortunately, I have not yet had time to implement this extension in MailKit and I'm not sure if it's really worth doing because so few IMAP servers actually support this extension anyway.
That said, I'd be willing to add this extension to my TODO list if there is value in adding it.
You can check if your server supports this extension by checking:
if (client.Capabilities.HasFlag (ImapCapabilities.Catenate)) {
Console.WriteLine ("Yes! The IMAP server supports the CATENATE extension!");
}
If not (and I suspect it doesn't), then your only option is to download the message, remove parts, and then re-upload.