So far we learned about the URLs, how to retrieve the Outline that contains folders and views and how to utilize JavaScript to deal with an API tha hadn't been designed for language neutral access. This part will deal with the retrieval of messages. There are quite some formats, strategies and tweaks to consider:
- A message consists of headers (fields), and message parts that can be plain text, HTML, embedded images, attachments or other stuff (like the JSON used for embedded experiences). When to retrieve what part is an excellent question
- Depending on your use case, your final client might or might not have access to the original iNotes implementation (Firewall, Offline, VPN), so just showing the HTML and let it fetch missing pieces might not do the trick
- The HTML retrieved might not be well formed or contain links you don't want to execute (tracker images, tracker CSS, JavaScript stuff)
- Automatically retrieving the whole message can be network heavy if there are large images or attachments in the MIME parts, this needs to be planned carefully
- iNotes allows to retrieve the message fields as (kind-of) JSON using
l_JSVars
or retrieve the MIME headers using l_MailMessageHeader
- The content of the message is accessible via
s_MailMemoReadBodyContent
or UNID/Body?OpenField
or l_MailMessageHeader&PresetFields=FullMessage;1
(as raw Mime)
- The MIME parts retrieved come infested with <br /> tags, since iNotes renders them in a display window (I would have used <pre>, but that's a different story. So they need cleanup
To begin I'll use the result of
l_JSVars
to learn about the document. Since, again, it is JavaScript, not JSON, I'll take the Rhino approach to extract a Java object.
The parts I'm interested in is in the variable named
DXX
which contains
item
that is a representation of NotesItems. True to the nature of an item, the JSON is quite elaborate, which you can see on the example of the form item:
{ "@name": "Form",
"textlist": {
"text": [
{"0": "Memo"}
]
}
}
For our purposes this will be flattened into a Map that has the item name as key. The Java code is quite similar to the retrieval of the Outline, the magic is in the JavaScript:
public MessageObject(String code, String rawMsg) {
long start = System.currentTimeMillis();
ScriptEngine engine = new ScriptEngineManager().getEngineByExtension("js");
engine.eval(code);
Invocable jsFunc = (Invocable) engine;
MessageObject msg = (MessageObject) jsFunc.invokeFunction("getMessageObject", rawMsg);
long end = System.currentTimeMillis();
System.out.println(msg.getUNID());
System.out.print("Time in ms:");
System.out.println(end-start);
return msg;
}
A little detail to stumble over is the item structure. It can be
textlist/text
or only
text
(feels like MIME Headers) and
datetimelist/datetimepair/datetime
or
datetimelist/datetime
.