RTF Export to MHT/MIME with Embedded Images

  • This mostly works. I tried to check compatibility ising IE / Chrome / Firefox. Firefox with the UnMHT plug-in is pretty flaky. Identical MHT files with different file names : one can display, one cannot.

    If you fix a few issues, IE & Chrome can work reliably. I gave up on Firefox.

    ******* Capitalization Problems *******

    => Content-Type: multipart/related; (not Content-type: Multipart/related;)

    => Content-Type: image/jpeg (not Content-type: image/jpeg)

    => base64 (not Base64)

    ******* Formatting Problems *******

    Content-Type: multipart/related;
    (this must be a $9 Tab char here)boundary="167E796F_34224ED7"

    If you have a space instead of a tab char, various browsers choke.

    Also, in the procedure TMIMEPart.ComposeParts, the code that checks line length and re-formats a line will screw up the "Content-Type" like that as shown above.

    In the procedure, TWPMimeWriter.Create, make the following change:

    FMultiPart := FMessage.AddPartMultipart('related', nil);

    If you don't do this, inline images show additionally at the end of the document.

    **** WpTools / Synapse Formatting of an Embedded Object ******

    By Default, WpTools and Synapse format embedded pictures like:

    HTML for Embedded image:
    <img src=3D"CID000100000001"

    Tags Before Base64 Image Data:
    Content-Type: image/jpeg
    Content-Transfer-Encoding: base64
    Content-ID: CID000100000001
    Content-Disposition: inline
    Content-Location: image1.JPG // not the real file name

    Neither IE nor Chrome can display the above as formatted. If you add "cid:" like below, IE can display the embedded image. Not Chrome.

    <img src=3D"cid:CID000100000001"

    **** My Issue ******

    The basic problem I have is WpTools/ Synapse MHT generator uses the CID as the value set for the <img src>. I need to use the JPG filename I defined for the RTF image object. I cannot determine how to reference it. A generic file name like "image1.jpg" has been generated even though the real image name should be known.

    In TWPHTMLWriter.WriteObject, the HTML <img src = is prepared and set from the CID value (something like CID000100000001).
    I can override it and set fnam := 'file:///'+obj.FileName where obj.FileName == 'ADS_20120130184831_EV00003.jpg' (my original RTF file name - which is known here).

    In WpioMime, TWPMimeWriter.WriteMainText, the headers that precede the base64 test data are written. EmbeddedImageElements[] is something I have no control over. The known filenames from the RTF objects have been replaced with generic names.

    data.filename = 'image1.jpg'
    data.cid = 'CID000100000001'

    After all of this, my question is ....

    Can I get to the original JPG filename in the TWPMimeWriter.WriteMainText functions?


    My ultimate goal is to format the HTML header like :

    <img src=3D"file:///ADS_20110131132421_EV00025.jpg"

    and the base64 header to:

    Content-Type: image/jpeg
    Content-Transfer-Encoding: base64
    Content-Disposition: inline
    Content-Location: file:///ADS_20110131132421_EV00025.jpg

    Any help would be appreciated.