Replace cid:image refrences in email body with Bas

2019-08-16 15:30发布

问题:

I have been tasked with writing an email archiving application. With lots of help from other SO questions and answers, I have succesfully saved the body of the email using Indy10 in Delphi 10.2.3, and it's image attachments as Base64encoded text files.

The body of an email with inline images contains strings like this:

<img width=360 height=153 id="Picture_x0020_8" src="cid:image002.png@01D4F3AE.C0AE8970">

And of course, the base64 encoding for that image looks like this:

data:image/x-png;base64,
iVBORw0KGg...Jggg==

My first question is about cr_lf. I have cr_lf just after base64, and at the end of the file (last 2 bytes). Is this correct for what I want to do?

Now I have to replace the <image width=360..8970"> with the base64encoded image text - and after that, save the new body to the archive, of course.

I can easily delete <image width=360..8970"> part from the body file, and then I want a simple way to insert the contents of the base64 txt file into that file at the right place.

I'll accept references to other SO questions I might have missed that do similar things. I haven't found anything in Delphi that helps me do this.

Thanks