From 8d0fba2d445dccbd131fe4f5d40502c756ac58ae Mon Sep 17 00:00:00 2001 From: Antonio Carlos Pantaglione Date: Sat, 12 Dec 2009 12:57:49 +0000 Subject: [PATCH] 2009-12-12 10:45 UTC-0300 Antonio Carlos Pantaglione + harbour/contrib/hbwin/mapi.c + harbour/contrib/hbwin/tests/testmapi.prg * MAPI send mail function. --- harbour/ChangeLog | 5 + harbour/contrib/hbwin/mapi.c | 125 +++++++++++++++++++++++ harbour/contrib/hbwin/tests/testmapi.prg | 15 +++ 3 files changed, 145 insertions(+) create mode 100644 harbour/contrib/hbwin/mapi.c create mode 100644 harbour/contrib/hbwin/tests/testmapi.prg diff --git a/harbour/ChangeLog b/harbour/ChangeLog index cf29df8d3a..6ce78951d6 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -17,6 +17,11 @@ past entries belonging to author(s): Viktor Szakats. */ +2009-12-12 10:45 UTC-0300 Antonio Carlos Pantaglione + + harbour/contrib/hbwin/mapi.c + + harbour/contrib/hbwin/tests/testmapi.prg + * MAPI send mail function. + 2009-12-12 13:52 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/include/hbwinuni.h + added new macro HB_ITEMGETSTR() diff --git a/harbour/contrib/hbwin/mapi.c b/harbour/contrib/hbwin/mapi.c new file mode 100644 index 0000000000..ba72c9b83e --- /dev/null +++ b/harbour/contrib/hbwin/mapi.c @@ -0,0 +1,125 @@ + +#include +#include +#include +#include + +static HINSTANCE hMapiLib = 0L; + +BOOL static LoadMapiLib( void ) +{ + if( ( hMapiLib = LoadLibrary( "mapi32.dll" ) ) >= (HINSTANCE) 32) + { + return TRUE; + } + + return FALSE; +} + +HB_FUNC( HB_MAPISENDMAIL ) +{ + ULONG uError; + int iLen, i; + LPMAPISENDMAIL MAPISendMail; + MapiRecipDesc origin; + + MapiMessage note; + + ZeroMemory ( ¬e, sizeof ( MapiMessage ) ); + ZeroMemory ( &origin, sizeof ( MapiRecipDesc ) ); + + note.ulReserved = 0L; + note.nRecipCount = 0; + note.lpRecips = NULL; + note.lpOriginator = NULL; + note.nFileCount = 1; + note.lpszSubject = ISCHAR( 1 ) ? hb_parc( 1 ) : ""; + note.lpszNoteText = ISCHAR( 2 ) ? hb_parc( 2 ) : ""; + note.lpszMessageType = ISCHAR( 3 ) ? hb_parc( 3 ) : NULL; + note.lpszDateReceived = ISCHAR( 4 ) ? hb_parc( 4 ) : ""; + note.flFlags = ( ISLOG( 6 ) && hb_parl( 6 ) ) ? MAPI_RECEIPT_REQUESTED: 0; + + if( hb_pcount() >= 8 && ISARRAY( 8 ) && hb_arrayLen( hb_param( 8, HB_IT_ARRAY ) ) ) + { + origin.lpszName = hb_parvc( 8, 1 ); + origin.lpszAddress = hb_parvc( 8, 2 ); + note.lpOriginator = &origin; + } + + if( hb_pcount() >= 9 && ISARRAY( 9 ) && ( iLen = hb_arrayLen( hb_param( 9, HB_IT_ARRAY ) ) ) > 0 ) + { + MapiRecipDesc target[ 100 ]; + + ZeroMemory( target, sizeof ( MapiRecipDesc ) * 100 ); + + for( i = 0; i < ( iLen < 100 ? iLen : 100 ); i++ ) + { + hb_arrayGet( hb_param( 9, HB_IT_ARRAY ), i + 1, hb_stackReturnItem() ); + + if ( hb_parvclen( -1, 1 ) > 0 ) + { + target[ i ].lpszName = hb_parvc( -1, 1 ); + if ( hb_parvclen( -1, 2 ) > 0 ) + { + target[ i ].lpszAddress = hb_parvc( -1, 2 ); + } + } + else + { + target[ i ].lpszName = hb_parvc( -1, 2 ); + } + target[ i ].ulRecipClass = hb_parvnl( -1, 3 ) ; + } + note.nRecipCount = iLen; + note.lpRecips = target; + } + else + { + note.nRecipCount = 0; + } + + if( hb_pcount() >= 10 && ISARRAY( 10 ) && ( iLen = hb_arrayLen( hb_param( 10, HB_IT_ARRAY ) ) ) > 0 ) + { + MapiFileDesc FileDesc[ 100 ]; + + ZeroMemory( FileDesc, sizeof( MapiFileDesc ) * 100 ); + + for( i = 0; i < ( iLen < 100 ? iLen : 100 ); i++ ) + { + hb_arrayGet( hb_param( 10, HB_IT_ARRAY ), i + 1, hb_stackReturnItem() ); + FileDesc[ i ].ulReserved = 0 ; + FileDesc[ i ].lpszPathName = hb_parvc( -1, 2 ); + FileDesc[ i ].lpszFileName = hb_parvc( -1, 1 ); + FileDesc[ i ].nPosition = -1 ; + } + + note.nFileCount = iLen; + note.lpFiles = FileDesc; + } + else + { + note.nFileCount = 0; + } + + if( LoadMapiLib() ) + { + MAPISendMail = ( LPMAPISENDMAIL ) GetProcAddress( hMapiLib, "MAPISendMail"); + + if ( ISLOG( 7 ) && hb_parl( 7 ) ) + { + uError = (*MAPISendMail) (0L, ( ULONG ) GetActiveWindow(), ¬e, MAPI_DIALOG | MAPI_LOGON_UI, 0L); + } + else + { + uError = (*MAPISendMail) (0L, ( ULONG ) GetActiveWindow(), ¬e, MAPI_LOGON_UI, 0L); + } + + FreeLibrary( hMapiLib ); + + hb_retnl( uError ); + } + else + { + hb_retnl( -1 ); + } +} diff --git a/harbour/contrib/hbwin/tests/testmapi.prg b/harbour/contrib/hbwin/tests/testmapi.prg new file mode 100644 index 0000000000..9e4694801a --- /dev/null +++ b/harbour/contrib/hbwin/tests/testmapi.prg @@ -0,0 +1,15 @@ +function main( cSubject, cBody, lMailConf, lFromUser, aSender, aDest, aFiles ) + + local nRet := HB_MAPISendMail( cSubject, ; // subject + cBody, ; // menssage + nil, ; // type of message + DtoS( Date() ) + " " + Time(), ; // send date + "", ; // conversation ID + lMailConf, ; // acknowledgment + lFromUser, ; // user intervention + aSender, ; // sender + aDest, ; // destinators + aFiles ; // attach + ) + +return nRet == 0