-1

I began developing a complex solution then found that the DxlExporter will do all the work for you. I wanted to share this simple solution.

jch
  • 3,600
  • 1
  • 15
  • 17
  • I have not heard of Lotus Notes for 10 years or so. It's actually interesting that it's still in use somewhere. – PM 77-1 Apr 27 '21 at 20:55
  • @PM77-1 : The product was renamed IBM Notes (and IBM Domino) many years ago, and it is now HCL Notes and HCL Domino, after HCL purchased it a couple of years ago. Version 11 was released last year and version 12 is in beta, to be released this summer, and version 13 is already planned. The installed base is actually growing, and it is used in many more places than you may think. – Karl-Henry Martinsson Apr 29 '21 at 15:24

2 Answers2

0

After converting the doc to MIME via convertToMIME() use the DxlExporter to do the rest of the work. It creates XML output that contains a <mime> tag in which the output of the fully converted MIME format document resides. This code does not do a full XML parse. It simply grabs everything between the <mime> </mime> tags. I've successfully converted 10s of thousands of email documents with this code with only a handful of failures - with all of those coming from badly formatted external email documents. I've had 100% success on Notes-originated email documents.

import lotus.domino.Document;
import lotus.domino.DxlExporter;
import lotus.domino.NotesException;
import lotus.domino.Session;

public class DocToMimeConverter
{
    private static final int MIMEOPTION_DXL = 0;
    private static final String tagStart = "<mime><![CDATA[";
    private static final String tagEnd = "]]></mime>";

    private DxlExporter exporter = null;
    
    public DocToMimeConverter(Session session) throws NotesException
    {
        super();
        exporter = session.createDxlExporter();
    }

    public String convert(Document doc) throws NotesException
    {
        String mimeDoc = null;
        
        exporter.setMIMEOption(MIMEOPTION_DXL);
        
        doc.removeItem("$KeepPrivate");
        doc.convertToMIME(Document.CVT_RT_TO_PLAINTEXT_AND_HTML);
        String dxl = exporter.exportDxl(doc);
        
        int idxStart = dxl.indexOf(tagStart);
        int idxEnd = dxl.indexOf(tagEnd);
        
        if (idxStart != -1 && idxEnd != -1 && idxEnd > idxStart)
        {
            mimeDoc = dxl.substring(idxStart + tagStart.length(), idxEnd);
        }
        
        return mimeDoc;
    }
}

The $KeepPrivate will prevent any document containing it to fail. So include doc.removeItem("$KeepPrivate") if you want to convert those documents also.

Also in the calling program:

Session s = NotesFactory.createSession((String)null, (String)null, NotesAuth.getPassword());
s.setConvertMIME(false);

The setConvertMIME(false) says to not convert any native MIME formatted documents to Notes format. Useful if your objective is to do a MIME conversion. Saves a little time and any round trip inaccuracies.

I used the following code to select email messages in the calling program:

if ("Memo".equals(doc.getItemValueString("Form")) ||
        "Reply".equals(doc.getItemValueString("Form")))

For my use case I used the UUID of the Notes document along with the '*.EML' to create individual files for each email message. These were then successfully imported into another email system.

jch
  • 3,600
  • 1
  • 15
  • 17
0

@jch, my tests with your code works fine with Notes generated messages, while I'm losing html fidelity for messages coming from the internet or no html at all. Have you experimented with another way for internet generated posts (those with some html tables and divs)?

I've tried adding the following with no luck:

    exporter.setRichTextOption(RICHTEXTOPTION_RAW); 
    exporter.setConvertNotesBitmapsToGIF(true); 
    if (doc.hasItem("$KeepPrivate")) {
        doc.removeItem("$KeepPrivate"); 
    }
    doc.convertToMIME(Document.CVT_RT_TO_HTML);
  • No, I have not. And no longer have access to a Notes system to try out potential solutions. – jch Dec 29 '22 at 19:10