Search This Blog

Monday, August 7, 2017

Appending MIME item to NotesRichTextItem

Hi guys

May be this will save someone's day.

The story:
Some external UI posts HTML-data to Notes.
That HTML has to be added to NotesRichtextItem.

1) When I tested simple case manually all worked OK:

1.1) Here is my Notes form

1.2) I put some data in Notes document and save it
1.3) Then I run an agent over this document with code like

Sub Initialize
Dim s As New NotesSession
Dim doc As NotesDocument
Dim rt1 As NotesRichTextItem
Dim rt2 As NotesRichTextItem

Set doc = s.Documentcontext
Set rt1 = doc.getfirstitem("RTBody")
Set rt2 = doc.getfirstitem("MIMEBody")

Call rt1.Appendrtitem(rt2)

Call, False)
End Sub

1.4) The result is what I need

2) However when I create MIME item via lotusscript the result of merging was wrong:

2.1) Here is my form - only NotesRichtextItem on form:

2.2) Here is an agent for creating MIMEBody:

Sub Initialize
Dim s As New NotesSession
Dim doc As NotesDocument
Dim m As NotesMIMEEntity
Dim h As NotesMIMEHeader
Dim stream As NotesStream

Set stream = s.createstream
Set doc = s.Documentcontext

s.Convertmime = False

Set m = doc.Createmimeentity("MIMEBody")
Set h = m.Createheader("Content-Type")
Call h.Setheaderval("text/html")
Call stream.writetext({<p style="color:red">BBBBBBBBBBBB</p>})
Call m.Setcontentfromtext(stream, "text/html", ENC_NONE )
Call, False)

s.Convertmime = True
End Sub

3.2) If you run the agent above - it creates MIME item correctly and HTML looks OK (I have added MIMEBody field on my form temporarily just to show you that HTML is OK)

2.4) When I run agent to merge the fields (the agent from point 1.3) I have got completely black text

After investigation why is it such a difference I discovered that MIME->NotesRichTextItem conversion seems to support only basic things, probably does not support CSS at all - didn't dig up so deeply.

If you check HTML automatically generated by Notes for MIME item saved in Notes UI it will be very basic without CSS, for example HTML for screen below is:

<font size=3 color=red><b>BBBBBBBBBBBB</b></font>

If you append such MIME item to NotesRichtextItem it will work OK.
However HTML like this:

<font size=3 style="color:red"><b>BBBBBBBBBBBB</b></font>

cannot be correctly appended to NotesRichtextItem.

No comments:

Post a Comment