Rich Text to MIME conversion crashing

I’m trying to write an application which will convert note items from Domino Rich Text to MIME format.

I found in Notes C API function “MIMEConvertCDParts” which should do everything I need.

I wrote simple application and copied example from documentation to see what it will look like after conversion. While running it all RichField itens become null.

So my question is: Whats is wrong?

Thanks in advance for any help.

#ifdef __cplusplus

extern "C" {

#endif

/* OS and C include files */

#include <stdio.h>

#include <string.h>

#include <memory.h>

/* Lotus C API for Domino and Notes include files */

#include <global.h>

#include <nsfdb.h>

#include <nsfnote.h>

#include <nsfsearc.h>

#include <ods.h>

#include <osmem.h>

#include <nsferr.h>

#include <odserr.h>

#include <osmisc.h>

#include <mime.h>

#include <nsfnote.h>

#include <mailmisc.h>

/* Function prototypes */

STATUS LNPUBLIC note_action ( /* called for every document */

        VOID far *,

        SEARCH_MATCH far *,

        ITEM_TABLE far *);

void PrintAPIError (STATUS);

CCHANDLE hCC = NULLHANDLE;

int main(int argc, char *argv)

{

/* Local data declarations */

char        *db_filename;   /* pathname of source database */

DBHANDLE    db_handle;      /* handle of source database */

STATUS        error;        /* return status from API calls */

/* Get the command line parameters that the user entered. */

if (argc != 2)

    {

    printf ("\nUsage:  ConverterMime  <arquivo nsf>  \n");

    return (NOERROR);

    }

db_filename = argv[1];

/* Start by calling Notes Init. */

 error = NotesInitExtended (argc, argv);

 if (error)

 {

     printf("Error: Não foi possivel iniciar o Notes.\n");

     return (1);

 }

/* Open the database. */

if (error = NSFDbOpen (db_filename, &db_handle))

{

   PrintAPIError (error); 

   NotesTerm();

   return (1);

}

/* Call NSFSearch to find all data notes in the database. */

if (error = NSFSearch (

     db_handle,        /* database handle */

     NULLHANDLE,       /* selection formula */

     NULL,             /* title of view in selection formula */

     0,                /* search flags */

     NOTE_CLASS_DOCUMENT,  /* note class to find */

     NULL,             /* starting date (unused) */

     note_action,      /* action routine for notes found */

     &db_handle,       /* argument to action routine */

     NULL))            /* returned ending date (unused) */



     {

     NSFDbClose (db_handle);

     PrintAPIError (error); 

     NotesTerm();

     return (1);

     }

/* Close the database. */

if (error = NSFDbClose (db_handle))

{

     PrintAPIError (error); 

     NotesTerm();

     return (1);

}

/* End of main routine. */

printf(“\nProgram completed successfully.\n”);

NotesTerm();

return (0);

}

/************************************************************************

FUNCTION:   note_action



PURPOSE:    This is the routine that is called by NSFSearch for

            each note that matches the selection criteria.



INPUTS:

    The first argument to this function is the optional argument

    that we supplied when we called NSFSearch.



    The second argument is supplied by NSFSearch.    It is

    a structure of information about the note that was found.



    The third argument is also supplied by NSFSearch and is

    the summary buffer for this note.

*************************************************************************/

STATUS LNPUBLIC note_action

        (VOID far *db_handle,

        SEARCH_MATCH far *pSearchMatch,

        ITEM_TABLE far *summary_info)

{

SEARCH_MATCH  SearchMatch;

NOTEHANDLE    note_handle;

STATUS        error;



memcpy( (char*)&SearchMatch, (char*)pSearchMatch, sizeof(SEARCH_MATCH) );

/* Skip this note if it does not really match the search criteria (it is

now deleted or modified). This is not necessary for full searches,

but is shown here in case a starting date was used in the search. */

/* if (SearchMatch.MatchesFormula != SE_FMATCH) V3 */

if (!(SearchMatch.SERetFlags & SE_FMATCH))     /* V4 */

    return (NOERROR);

/* Print the note ID. */

printf ("\nNote ID is: %lX.\n", SearchMatch.ID.NoteID);

/* Open the note. */

if (error = NSFNoteOpen (

        *(DBHANDLE far *)db_handle,    /* database handle */

        SearchMatch.ID.NoteID,    /* note ID */

        0,            /* open flags */

        &note_handle))        /* note handle (return) */

   

    return (ERR(error));

/***************************************************************/

/* get the notes flags, determine if the note was opened in canonical format, */

/* create the default conversion control settings and then call MIMEConvertCDParts */

DHANDLE hNote = note_handle;

WORD wNoteFlags;

BOOL bCanonical;

BOOL bIsMIME;

NSFNoteGetInfo(hNote, _NOTE_FLAGS, &wNoteFlags);

bCanonical = (wNoteFlags & NOTE_FLAG_CANONICAL) != 0;

bIsMIME = NSFNoteHasMIMEPart(hNote);

/* create the default conversion control settings */

if (error = MMCreateConvControls(&hCC)) {

   PrintAPIError (error); 

   NotesTerm();

   return (1);

}

MMSetReadReceipt(hCC, 1); /* 0 - Do not pass read receipt requests when importing or exporting (default) */

                            /* 1 - Support read receipt requests (as Return-Receipt-To when exporting) */

                            /* 2 - Support read receipt requests (as Disposition-Notification-To when exporting) */

if (error = MIMEConvertCDParts(hNote, bCanonical, bIsMIME, hCC)) {

return (ERR(error));

}

/* destroy the default conversion control settings */

if (error = MMDestroyConvControls(hCC)) {

   PrintAPIError (error); 

   NotesTerm();

   return (1);

}

/***************************************************************/

/* Save the note. */

if (error = NSFNoteUpdate (hNote, 0))

    return (ERR(error));

/* Close the note. */

if (error = NSFNoteClose (hNote))

    return (ERR(error));

/* End of subroutine. */

return (NOERROR);

}

/*************************************************************************

FUNCTION:   PrintAPIError



PURPOSE:    This function prints the Lotus C API for Domino and Notes

    error message associated with an error code.

**************************************************************************/

void PrintAPIError (STATUS api_error)

{

STATUS  string_id = ERR(api_error);

char    error_text[200];

WORD    text_len;



/* Get the message for this Lotus C API for Domino and Notes error code

   from the resource string table. */



text_len = OSLoadString (NULLHANDLE,

                         string_id,

                         error_text,

                         sizeof(error_text));



/* Print it. */

fprintf (stderr, "\n%s\n", error_text);

}

#ifdef __cplusplus

}

#endif