12.19.2014

How I got around the Notes C API problem with MailAddMessageBodyComposite creating error 315 on larger HTML files

Tags: : Notes C API
0
I have always wanted to be able to import HTML into Notes with the C API in a proper way. Well ... as "proper" as proper can be. We all know that the quality and fidelity of the HTML import in Notes can be so-so, but it is always nicer to be able to do some import rather than none.

To make a long story short, searching around on the net points you to some few pages outlining techniques using the undocumented function ImportHTMLTextFile in the import DLL niHTML.dll. This is probably the very same function the Notes client uses when you import a HTML file into a rich text field. The ImportHTMLTextFile function swallow parameters specifying the URL you want to import, and generates a CD-record file. This is in essence a file with the CD-records as you would believe they would occure in the rich text field. To understand more about CD-records, take a look here. In order to transport the CD-records from the file generated by the ImportHTMLTextFile -function, we use another function named MailAddMessageBodyComposite. Looking in the reference guide it clearly states "This function creates multiple items of the same name and therefore is not limited to 64KB of input". Below you see a snippet of C/C++ code using these functions (note, all error handling is removed for clarity)

/* Prime the Import function with a temporary CD file name and create the CD-record file*/
EDITIMPORTDATA stImpExp;
ZeroMemory(&stImpExp,sizeof(EDITIMPORTDATA));
CopyCStringToChar(strTempCDFile,stImpExp.OutputFileName,OLDMAXPATH);

/* Import the HTML with the undocumented import function in the Import Library NIHTML.DLL from Notes */
error = m_dllImportHTML.ImportHtmlTextFile(&stImpExp,3,0,"",szHTMLFileName);

/* Coming here, we are ready to use the MailAddMessageBodyComposite */
error = NSFItemDelete(m_hDocNote,szRichTextFieldName, strRichTextFieldName.GetLength());
error = MailAddMessageBodyComposite(m_hDocNote,szRichTextFieldName,stImpExp.OutputFileName);

Running the code above on URLs with code below 64 KB went fine, but when the page-size grew beyond 64 KB I got error 315 .... "Memory Allocation Exceeded 65,000 bytes" from MailAddMessageBodyComposite. The ImportHtmlTextFile-function didn't have any problems swallowing huge pages. The 315-error led me to post the question Has anybody got the C API function MailAddMessageBodyComposite working with larger HTML? on the Notes 9 forum.

Since I didn't get any answers, and couldn't get MailAddMessageBodyComposite to work, I finally got my head around the MIME-functions in the C API and the following technique worked nicely - also with huge pages!

In order to get the pseudo-code to work, you must have your HTML file local first. Let's say it is stored as c:\temp\MyHTML.htm. Please note that the code below is not complete nor has error handling in place. Also note that the variable m_docNote is the NOTEHANDLE of the open note. The note will of course be saved after a successful import.

STATUSerror = NOERROR;
MIMEHANDLE        hMIMEStream;

/* Open a MIME stream. This will receive the strings from the file */        
error = MIMEStreamOpen(m_hDocNote, // note handle
        NULL,                               // item name
        0,                               // item name length
        MIME_STREAM_OPEN_WRITE,         // open flags
        &hMIMEStream );

/* Tell the stream that we will receive HTML soon */
error = MIMEStreamPutLine("Content-Type: text/html", hMIMEStream);

/* Loop through the lines in the file. You can use any kind of array or iterator here as long as you can get the file line-by-line */
for (lCur = 0; lCur < lMax; lCur++)
{
        error = MIMEStreamPutLine((char *)arrayFile[lCur], hMIMEStream);
}

/* Delete any potential field with the specified name and convert the MIME Stream to an itemized field */
error = NSFItemDelete(m_hDocNote,"Body", 4);
error = MIMEStreamItemize( m_hDocNote,
                "Body",
                4,
                MIME_STREAM_ITEMIZE_BODY,
                hMIMEStream);

/* Close MIME Stream */
MIMEStreamClose(hMIMEStream);

The pepper in the code above is simply to put the "Content-type"-string into the stream so the MIMEStreamItemize later understand the text as HTML. Also note that the flag MIME_STREAM_ITEMIZE_BODY limits the itemizer to render only the body field of the incoming mime.

Knowing that this technique worked with "fake MIME" as described above, I also tried to use the technique with real MIME files such as EML (drag a mail document from your inbox to your desktop and voila - you have an EML file of that mail!) or other MIME files. The code even imported embedded images without any problem.

Hopefully these tips are helpful if you struggle with MailAddMessageBodyComposite!

11.21.2013

Classic Notes: How to communicate with IBM Connections from LotusScript wrapping IBM SBT with LS2J - Part 3

Tags: : LotusScript Java Connections
0

This part 3 of 3 in the article series “Classic Notes: How to communicate with IBM Connections from LotusScript wrapping IBM SBT with LS2J”.

Read the others here:

Part 1

Part 2


Read more...

11.21.2013

Classic Notes: How to communicate with IBM Connections from LotusScript wrapping IBM SBT with LS2J - Part 2

Tags: : LotusScript Java Connections
0

This part 2 of 3 in the article series “Classic Notes: How to communicate with IBM Connections from LotusScript wrapping IBM SBT with LS2J”.

Read the others here:

Part 1

Part 3


Read more...

11.21.2013

Classic Notes: How to communicate with IBM Connections from LotusScript wrapping IBM SBT with LS2J - Part 1

Tags: : LotusScript Java Connections
0

This part 1 of 3 in the article series “Classic Notes: How to communicate with IBM Connections from LotusScript wrapping IBM SBT with LS2J”.

Read the others here:

Part 2

Part 3

… embark! …

You have seen the cool IBM Social Business Toolkit (IBM SBT), and you played around with the ??bercool Playground application. You dive into the code and quickly discover that you need some Java or JavaScript knowledge.

- Ooops, but I am mostly doing LotusScript, you say … what now?

Perhaps you ask a question on StackOverflow to see if anybody has some advice for your scenario (just completely out of the sky – perhaps something similar to this question Smilefjes). The chances are that you’d get a lot of advice abandoning your old and tired LotusScript  in favor for the much more modern Java language. Your challenge is that you have a lot of LotusScript code that you would love to enhance with the new cool IBM SBT possibilities, and perhaps not the time to take the heavy plunge into learning a new language.

This article – which assumes a whole bunch of details are in place – will show you how to have this small piece of LotusScript code …

SNAGHTMLcc5370

… put an entry into an Activity Stream in a specified community like this;

SNAGHTML61694e


Read more...

11.14.2013

How I got Lotus Connectors (LCLSX) to finally connect from our IBM i to a remote Windows DB/2 server

Tags: : LotusScript Connectors
0

If you have seen error messages like “30061 - Error: Relational database BLABLA not found.,  Connector 'db2',  Method -Connect-  (-30061) - Relational database BLABLA not found.” or “Error: Communication error occurred on distributed database processing.  See SQ30080 for invalid possibilities.  A common error is that the  password is case sensitive and is not being provided in the correct case” you’re not alone!

Read on how to see the bigger picture on how IBM i’s “Relational Database Directory Entries” should be configured based on what you see in the real target database. Finally you’ll see how to code Lotus Connectors LSX (LCLSX) to use this information to connect to the database.

Most of our Domino servers run on IBM i (aka System i, iSeries and AS/400). Since IBM i have DB2 natively supported, there is no need to install DB2 Client or DB2 Data Server Drivers (more on those below). The target DB/2 server is running on a remote Windows server, and I thought it would be a breeze to connect IBM i and the Windows machine together. Not so! First and foremost, there is sparse information on the net on how to exactly do this. You very quickly find sample code similar to this;

SNAGHTML13265e9

So how come the code above bails out at the Connect-method?


Read more...

05.09.2012

Classic Notes Development: Updated code to open design elements from Notes - in Designer

Tags: : LotusScript
0

Thanks to Stephan Wissel who pointed me in the correct direction regarding how to open design elements directly – from the Notes client with LotusScript.


Read more...

05.07.2012

Classic Notes Development; How to launch a database in Designer with Command Line Parameters

Tags: : LotusScript
0

Ever wanted to launch a database directly in Designer? Yes, then you probably are a developer Smilefjes

Read more to see a snippet of LotusScript code on how to launch the Designer with a specified database.

BTW – wish I could specify a specific designer element, so if you know, please chime in.


Read more...

04.30.2012

Classic Notes Development - Access Search Bar from LotusScript

Tags: : LotusScript
0

Have you ever wanted to access the Search Bar from LotusScript?

image

Being able to do so would perhaps remove the need for various homecooked solutions on how to do full text searches and display the results to the user. Even though we do have programmatic access to full text, I have allways felt that something is missing. Why not just use the standard search bar in the Notes client? This post describes how to do exactly that with a couple LotusScript classes, using Windows API functions. You can set and get the text of the Search Bar, and even click the "Search" button programmatically.


Read more...

01.10.2012

Looking forward to LS12! Has anybody seen presentation downloads yet?

Tags: : Lotusphere
0

Last year the official session schedule contained several presentations for download even before Lotusphere. This year I haven’t seen them yet.


10.27.2011

Can the 10-year old that wrote Microsoft MSI please step forward

Tags: : Microsoft Office Thoughts Windows 7
0
Have you ever seen the funny "Error "1310: Error writing to file: C:\Config.Msi..." -message when trying to install an application?

A picture named M2

..."Verify that you have access to that directory." ...

Read more...

Tags

Calendar