+1 vote

I would like to scan incoming emails on an IMAP server for certain keywords and replace this keywords by other characters. The modified emails should be uploaded to the IMAP inbox again. Is this possible using the functionality of Mail.dll? It is maybe even possible without downloading the emails from the server using a server based threading?

Thanking you in advance.

by

1 Answer

0 votes

It is maybe even possible without downloading the emails from the server using a server based threading?

Nope, at least not using IMAP protocol - it is used for client access. It is not possible to program server side extensions with it.

Is this possible using the functionality of Mail.dll?

Yes, what you need to do is to download message, modify it, delete the original and upload it again.

For some short time (depending on your implementation) original message would be still visible in the INBOX though.

Yu can read more on uploading emails using IMAP here:
https://www.limilabs.com/blog/uploading-emails-using-imap

You'll need to use UploadMessageInfo class, so you can set unseen flag and internal server date:

UploadMessageInfo messageinfo = new UploadMessageInfo();
messageinfo.Flags.Add(Limilabs.Client.IMAP.Flag.Unseen);
imap.UploadMessage("INBOX", email, messageinfo);

To modify message's text/html:

IMail email = ....
email.TextData.Text = "modified text";
email.HtmlData.Text = "modified <strong>html</strong>";

Remember to make sure that IMail.TextData/IMail.HtmlData are not null. Emails may contain several versions of the body in different formats (text/html/rtf) or only one such format.

Some additional notes:

  • If message is signed/encrypted you shouldn't do anything as it will break the message
  • DKIM signature is going to be invalidated, if you modify the message
by (297k points)
...