developerWorks  >  Lotus  >  Forums & community  >  Notes/Domino 6 and 7 Forum

Notes/Domino 6 and 7 Forum

developerWorks




How to use C API to read mails
Pascal Quesseveur 08/23/2011 12:57 PM
Toolkits 6.5.4 All Platforms


I am trying to develop an extension for Notes 6.5 (that version is mandatory and I can't change it). That extension has to do the following:

- on sending mails: catch the attachments and the mail text, encrypt them in one file using specific algorithm, replace the existing mail with the encrypted file.

- on reading mails: decrypt the encrypted file, replace the mail content with the parts and attachments contained in the encrypted file.

I have choosen to develop that extension using the C API and I have followed the extmail sample (perhaps it would have been easier using LotusScript but I had absolutely no idea on how to do it). At present I am able to send mails but I have the following problems:

- When I call NFSNoteUpdate to validate message modifications, the extension handler is called a second time with mode EM_REG_BEFORE. I haven't read anything about this in the doc and I wonder if there is something wrong in my code.

- I thought the hardest task would have been sending the emails, but I found I am unable to read the received mails in my extension. I have tried to set a handler on EM_NSFNOTEOPEN but I always get a Notes panic crash due to an invalid handle. I have tried differents things without any success. I get the same error with extmngr sample. Other samples which manipulate notes through a database handle (as rsimple) work fine.

Basically my code is as follows:

=========================================================================
STATUS LNPUBLIC DLL_EXPORT EMHandlerNoteProc (EMRECORD FAR * pExRecord);

STATUS RegisterEntry()
{
STATUS error = EMRegister(EM_NSFNOTEOPEN, EM_REG_AFTERBEFORE,
(EMHANDLER)gHandlerNoteProc,
gRecursionID, &hHandlerNote);
return(error);
}
STATUS LNPUBLIC EMHandlerNoteProc (EMRECORD FAR * pex_record)
{
STATUS sError = NOERROR;
switch (pex_record->EId)
{
case EM_NSFNOTEOPEN:
VARARG_PTR ap = pex_record->Ap;
HANDLE h_note = VARARG_GET (ap, HANDLE);
if (pex_record->Status != NOERROR)
break;
if (pex_record->NotificationType == EM_BEFORE)
{
NOTEID nid;
// NSFNoteGetInfo (h_note, _NOTE_ID, &nid);
}
break;
}
return (ERR_EM_CONTINUE);
}
BOOL WINAPI DllMain (HINSTANCE hInstance, DWORD fdwReason, LPVOID lpReserved)
{
STATUS error = NOERROR;
switch (fdwReason)
{
case DLL_PROCESS_ATTACH:
InitializeCriticalSection (&gCriticalSection);
gHandlerNoteProc =
(EMHANDLER)MakeProcInstance ((FARPROC)EMHandlerNoteProc, hInstance);
break;
case DLL_PROCESS_DETACH:
CleanUp ();
FreeProcInstance (gHandlerNoteProc);
error = DeregisterEntry ();
DeleteCriticalSection (&gCriticalSection);
break;
}
return( TRUE );
UNREFERENCED_PARAMETER(lpReserved);
}
=========================================================================

I get a crash when I uncomment the line

// NSFNoteGetInfo (h_note, _NOTE_ID, &nid);

For my tests I use Notes 6.5.4 (March 27, 2005) and I send/get emails to a SMTP/IMAP server. I don't use any Domino server. I haven't been able to find the Notes API for 6.5 so I have installed the version 5.0.6 upgraded to 5.0.11.

I would be very pleased if someone could show me the way to read the mails, or give a pointer to some documentation or sample.

Go back