CURL for HMG latest Version ?

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

User avatar
AUGE_OHR
Posts: 2064
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

CURL for HMG latest Version ?

Post by AUGE_OHR »

hi,

where can i get "lates" LIB "a" for HMG :?:

"new" Sample include EMAIL.PRG but when try to run i get
hbmk2: Error: Referenced, missing, but unknown function(s):
HB_CURL_MAIL_ADDRESS_TO_EMAIL(), CURL_GLOBAL_SSLSET(), HB_CURL_DATE(),
TIP_MAILASSEMBLE()
have fun
Jimmy
User avatar
danielmaximiliano
Posts: 2612
Joined: Fri Apr 09, 2010 4:53 pm
Location: Argentina
Contact:

Re: CURL for HMG latest Version ?

Post by danielmaximiliano »

AUGE_OHR wrote: Tue Aug 16, 2022 1:29 am hi,

where can i get "lates" LIB "a" for HMG :?:

"new" Sample include EMAIL.PRG but when try to run i get
hbmk2: Error: Referenced, missing, but unknown function(s):
HB_CURL_MAIL_ADDRESS_TO_EMAIL(), CURL_GLOBAL_SSLSET(), HB_CURL_DATE(),
TIP_MAILASSEMBLE()
donde se encuentra ese ejemplo ?
*´¨)
¸.·´¸.·*´¨) ¸.·*¨)
(¸.·´. (¸.·` *
.·`. Harbour/HMG : It's magic !
(¸.·``··*

Saludos / Regards
DaNiElMaXiMiLiAnO

Whatsapp. := +54901169026142
Telegram Name := DaNiElMaXiMiLiAnO
User avatar
AUGE_OHR
Posts: 2064
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: CURL for HMG latest Version ?

Post by AUGE_OHR »

danielmaximiliano wrote: Wed Aug 17, 2022 1:10 am donde se encuentra ese ejemplo ?

Code: Select all

/* Copyright 2014-2017 Viktor Szakats */

#require "hbcurl"
#require "hbtip"

#include "simpleio.ch"
#include "hbcurl.ch"

#define HB_CURLVERINFO_VERSION                1
#define HB_CURLVERINFO_VERSION_NUM            2
#define HB_CURLVERINFO_PROTOCOLS              8  /* Array */
#define HB_CURLSSLBACKEND_SCHANNEL            8
#define HB_CURLSSLSET_OK                      0
#define HB_CURLOPT_MIMEPOST                   250

PROCEDURE Main( cFrom, cPassword, cTo, cHost )

   LOCAL lSystemCA, cCA := hb_PathJoin( iif( hb_DirBase() == "", hb_cwd(), hb_DirBase() ), "cacert.pem" )
   #if defined( __PLATFORM__WINDOWS )
   LOCAL tmp
   #endif

   LOCAL curl
   LOCAL lAPI_curl := curl_version_info()[ HB_CURLVERINFO_VERSION_NUM ] >= 0x073800

   LOCAL cUser
   LOCAL cText
   LOCAL cHTML
   LOCAL cSubject

   /* Require STARTTLS on port 587 (true) or allow it to proceed without it (false) */
   LOCAL lSTARTTLS_force

   IF hb_AScan( curl_version_info()[ HB_CURLVERINFO_PROTOCOLS ], "smtps",,, .T. ) == 0
      ? "Error: Requires libcurl 7.20.0 or newer, built with TLS/SSL and SMTP protocol support"
      RETURN
   ENDIF

   hb_default( @cFrom    , "from@example.net" )
   hb_default( @cPassword, "password" )
   hb_default( @cTo      , "to@example.org" )
   hb_default( @cHost    , "localhost" )

   cFrom := "<" + ( cUser := hb_curl_mail_address_to_email( cFrom ) ) + ">"
   cTo := "<" + hb_curl_mail_address_to_email( cTo ) + ">"
   cHost := Lower( cHost )

   cSubject := "Example sending a MIME-formatted message"

   cText := ;
      e"This is the inline text message of the email.\r\n" + ;
      e"\r\n" + ;
      e"  It could be a lot of lines that would be displayed in an email\r\n" + ;
      e"viewer that is not able to handle HTML.\r\n"

   cHTML := ;
      e"<html><body>\r\n" + ;
      e"<p>This is the inline <strong>HTML</strong> message of the email.</p>" + ;
      e"<br>\r\n" + ;
      e"<p>It could be a lot of HTML data that would be displayed by " + ;
      e"email viewers able to handle HTML.</p>" + ;
      e"</body></html>\r\n"

   lSTARTTLS_force := .F.

   /* NOTE: Consult your provider for updated settings
            and create a Pull Request if necessary. */

   DO CASE
   CASE cHost == "apple" .OR. "@icloud.com" $ cFrom .OR. "@mac.com" $ cFrom .OR. "@me.com" $ cFrom
      cHost := "smtp://smtp.mail.me.com:587"; lSTARTTLS_force := .T.
   CASE cHost == "fastmail" .OR. "@fastmail.com" $ cFrom .OR. "@fastmail.fm" $ cFrom
      cHost := "smtps://smtp.fastmail.com"
   CASE cHost == "gmx.net" .OR. "@gmx.net" $ cFrom .OR. "@gmx.ch" $ cFrom .OR. "@gmx.de" $ cFrom
      cHost := "smtps://mail.gmx.net"
   CASE cHost == "google" .OR. "@gmail.com" $ cFrom .OR. "@googlemail.com" $ cFrom
      cHost := "smtps://smtp.gmail.com"
   CASE cHost == "mail.ru" .OR. "@mail.ru" $ cFrom
      cHost := "smtps://smtp.mail.ru"
   CASE cHost == "netease" .OR. "@163.com" $ cFrom
      cHost := "smtps://smtp.163.com"
   CASE cHost == "office365"
      cHost := "smtp://smtp.office365.com:587"; lSTARTTLS_force := .T.
   CASE cHost == "outlook" .OR. "@outlook.com" $ cFrom .OR. "@hotmail.com" $ cFrom
      cHost := "smtp://smtp-mail.outlook.com:587"; lSTARTTLS_force := .T.
   CASE cHost == "sina" .OR. "@sina.com" $ cFrom
      cHost := "smtps://smtp.vip.sina.com"
   CASE cHost == "uol" .OR. "@uol.com.br" $ cFrom
      cHost := "smtps://smtps.uol.com.br"
   CASE cHost == "yahoo" .OR. "@yahoo.com" $ cFrom
      cHost := "smtps://smtp.mail.yahoo.com"
   CASE cHost == "mailtrap.io" .OR. "@mailtrap.io" $ cFrom
      cHost := "smtp://smtp.mailtrap.io:465"; lSTARTTLS_force := .T.
      cUser := StrTran( cUser, "@mailtrap.io" )
   CASE cHost == "localhost"
      cHost := "smtp://localhost:1025"  /* MailHog */
      cUser := cPassword := NIL

   CASE cHost == "securesmtp.t-online.de"
      cHost := "smtp://securesmtp.t-online.de:465"; lSTARTTLS_force := .T.

   CASE cHost == "smtp.web.de"
      cHost := "smtp://smtp.web.de:587"; lSTARTTLS_force := .T.

   ENDCASE

   ? "libcurl:", curl_version_info()[ HB_CURLVERINFO_VERSION ]
   ? "Payload API:", iif( lAPI_curl, "libcurl native", "tip_MailAssemble()" )
   ? "Host:", cHost, iif( lSTARTTLS_force, "(must STARTTLS)", "" )

   #if defined( __PLATFORM__UNIX )
      lSystemCA := .T.
   #elif defined( __PLATFORM__WINDOWS )
      /* Switch to SChannel SSL backend, if available (on Windows).
         Doing this to use the OS certificate store. */
      curl_global_sslset( -1,, @tmp )
      IF ( lSystemCA := ;
         HB_CURLSSLBACKEND_SCHANNEL $ tmp .AND. ;
         curl_global_sslset( HB_CURLSSLBACKEND_SCHANNEL ) == HB_CURLSSLSET_OK )
         cCA := NIL
      ELSE
         cCA := hb_DirBase() + hb_DirSepToOS( "../../../bin/" ) + cCA
      ENDIF
   #else
      lSystemCA := .F.
   #endif

   curl_global_init()

   IF Empty( curl := curl_easy_init() )
      ? "Failed to init"
   ELSE
      IF ! lSystemCA
         IF hb_vfExists( cCA )
            curl_easy_setopt( curl, HB_CURLOPT_CAINFO, cCA )
         ELSE
            ?
            ? "Error: Trusted Root Certificates missing. Open this URL in your web browser:"
            ? "  " + "https://curl.se/ca/cacert.pem"
            ? "and save the file as:"
            ? "  " + cCA
            RETURN
         ENDIF
      ENDIF
      curl_easy_setopt( curl, HB_CURLOPT_USE_SSL, ;
         iif( lSTARTTLS_force, HB_CURLUSESSL_ALL, HB_CURLUSESSL_TRY ) )
      curl_easy_setopt( curl, HB_CURLOPT_UPLOAD )
      curl_easy_setopt( curl, HB_CURLOPT_URL, cHost )
      curl_easy_setopt( curl, HB_CURLOPT_PROTOCOLS, ;
         hb_bitOr( HB_CURLPROTO_SMTPS, HB_CURLPROTO_SMTP ) )
      curl_easy_setopt( curl, HB_CURLOPT_TIMEOUT_MS, 15000 )
      curl_easy_setopt( curl, HB_CURLOPT_VERBOSE, .T. )
      curl_easy_setopt( curl, HB_CURLOPT_USERNAME, cUser )
      curl_easy_setopt( curl, HB_CURLOPT_PASSWORD, cPassword )
      curl_easy_setopt( curl, HB_CURLOPT_MAIL_FROM, cFrom )
      curl_easy_setopt( curl, HB_CURLOPT_MAIL_RCPT, { cTo } )

      IF lAPI_curl
         curl_easy_setopt( curl, HB_CURLOPT_HTTPHEADER, { ;
            "Date: " + hb_curl_date(), ;
            "To: " + cTo, ;
            "From: hbcurl " + cFrom, ;
            "Cc: " + cTo, ;
            "Message-ID: <dcd7cb36-11db-487a-9f3a-e652a9458efd@rfcpedant.example.org>", ;
            "Reply-To: " + cFrom, ;
            "Disposition-Notification-To: " + cFrom, ;
            "X-Priority: " + hb_ntos( 3 ), ;  /* 1: high, 3: standard, 5: low */
            "Subject: " + cSubject } )

         /* NOTE: 'charset' to be added when implemented */
         curl_easy_setopt( curl, HB_CURLOPT_MIMEPOST, { ;
            { "subparts" => { ;
              { "data" => cHTML, ;
                "type" => "text/html" }, ;
              { "data" => cText } }, ;
              "type" => "multipart/alternative", ;
              "headers" => { "Content-Disposition: inline" } }, ;
            { "filedata" => __FILE__ }, ;
            { "data" => Replicate( hb_BChar( 123 ), 1024 ), ;
              "type" => "image/png", ;
              "encoder" => "base64", ;  /* binary, 8bit, 7bit, base64, quoted-printable */
              "filename" => "mock.png" } } )
      ELSE
         cText := tip_MailAssemble( ;
            "hbtip " + cFrom, ;
            { cTo }, ;
            /* aCC */, ;
            cText, ;
            cSubject, ;
            { __FILE__, { "mock.png", Replicate( hb_BChar( 123 ), 1024 ) } } /* attachments */, ;
            /* nPriority */, ;
            /* lRead */, ;
            /* cReplyTo */, ;
            /* cCharset */, ;
            /* cEncoding */, ;
            .F. /* lBodyHTML */, ;
            /* bSMIME */ )
         curl_easy_setopt( curl, HB_CURLOPT_UL_BUFF_SETUP, cText )
         curl_easy_setopt( curl, HB_CURLOPT_INFILESIZE_LARGE, hb_BLen( cText ) )
      ENDIF

      ? "Result:", curl_easy_perform( curl )
WAIT
      curl_easy_cleanup( curl )
   ENDIF

RETURN

FUNCTION hb_curl_mail_address_to_email( cAddress )
   LOCAL tmp, tmp1

   IF ( tmp := At( "<", cAddress ) ) > 0 .AND. ;
      ( tmp1 := hb_At( ">", cAddress, tmp + 1 ) ) > 0
      RETURN AllTrim( SubStr( cAddress, tmp + 1, tmp1 - tmp - 1 ) )
   ENDIF

   RETURN cAddress

FUNCTION hb_curl_mail_address_to_name( cAddress )
   LOCAL tmp

   IF ( tmp := At( "<", cAddress ) ) > 0 .AND. ;
      hb_At( ">", cAddress, tmp + 1 ) > 0
      RETURN RTrim( Left( cAddress, tmp - 1 ) )
   ENDIF

RETURN cAddress
the Sample is from hb-main.zip made by Viktor Szakats
i have have found it "somewhere" @GitHub ...

it include Source
date.c
easy.c
escold.c
global.c
miscc.c
ver.c
hbcurl.ch
hbcurl.hbc
hbcurl.hbp
hbcurl.hbx
misc.prg
tests\email.prg
tests\ftp_uldl.prg
tests\hbmk.hbm
so how to build LIB "a" from Source :idea:

p.s. "where" to put Source to build :?:
have fun
Jimmy
User avatar
AUGE_OHR
Posts: 2064
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: CURL for HMG latest Version ?

Post by AUGE_OHR »

hi,

have try Code using Extended Version
Turbo Incremental Link 5.69 Copyright (c) 1997-2005 Borland
Error: Unresolved external '_HB_FUN_CURL_VERSION_INFO' referenced from G:\MINIGUI\SAMPLES\APPLICATIONS\SENDMAIL2\EMAIL.OBJ
Error: Unresolved external '_HB_FUN_CURL_GLOBAL_SSLSET' referenced from G:\MINIGUI\SAMPLES\APPLICATIONS\SENDMAIL2\EMAIL.OBJ
Error: Unresolved external '_HB_FUN_CURL_GLOBAL_INIT' referenced from G:\MINIGUI\SAMPLES\APPLICATIONS\SENDMAIL2\EMAIL.OBJ
Error: Unresolved external '_HB_FUN_CURL_EASY_INIT' referenced from G:\MINIGUI\SAMPLES\APPLICATIONS\SENDMAIL2\EMAIL.OBJ
Error: Unresolved external '_HB_FUN_CURL_EASY_SETOPT' referenced from G:\MINIGUI\SAMPLES\APPLICATIONS\SENDMAIL2\EMAIL.OBJ
Error: Unresolved external '_HB_FUN_HB_CURL_DATE' referenced from G:\MINIGUI\SAMPLES\APPLICATIONS\SENDMAIL2\EMAIL.OBJ
Error: Unresolved external '_HB_FUN_CURL_EASY_PERFORM' referenced from G:\MINIGUI\SAMPLES\APPLICATIONS\SENDMAIL2\EMAIL.OBJ
Error: Unresolved external '_HB_FUN_CURL_EASY_CLEANUP' referenced from G:\MINIGUI\SAMPLES\APPLICATIONS\SENDMAIL2\EMAIL.OBJ
so it seem a older hbCURL Version than HMG 3.4.4 while more HB_FUNC() are missing
have fun
Jimmy
User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: CURL for HMG latest Version ?

Post by Rathinagiri »

If you have the entire source code, you can try the batch file which comes along with HMGSQL.
AUGE_OHR wrote: Wed Aug 17, 2022 1:57 am
danielmaximiliano wrote: Wed Aug 17, 2022 1:10 am donde se encuentra ese ejemplo ?

Code: Select all

/* Copyright 2014-2017 Viktor Szakats */

#require "hbcurl"
#require "hbtip"

#include "simpleio.ch"
#include "hbcurl.ch"

#define HB_CURLVERINFO_VERSION                1
#define HB_CURLVERINFO_VERSION_NUM            2
#define HB_CURLVERINFO_PROTOCOLS              8  /* Array */
#define HB_CURLSSLBACKEND_SCHANNEL            8
#define HB_CURLSSLSET_OK                      0
#define HB_CURLOPT_MIMEPOST                   250

PROCEDURE Main( cFrom, cPassword, cTo, cHost )

   LOCAL lSystemCA, cCA := hb_PathJoin( iif( hb_DirBase() == "", hb_cwd(), hb_DirBase() ), "cacert.pem" )
   #if defined( __PLATFORM__WINDOWS )
   LOCAL tmp
   #endif

   LOCAL curl
   LOCAL lAPI_curl := curl_version_info()[ HB_CURLVERINFO_VERSION_NUM ] >= 0x073800

   LOCAL cUser
   LOCAL cText
   LOCAL cHTML
   LOCAL cSubject

   /* Require STARTTLS on port 587 (true) or allow it to proceed without it (false) */
   LOCAL lSTARTTLS_force

   IF hb_AScan( curl_version_info()[ HB_CURLVERINFO_PROTOCOLS ], "smtps",,, .T. ) == 0
      ? "Error: Requires libcurl 7.20.0 or newer, built with TLS/SSL and SMTP protocol support"
      RETURN
   ENDIF

   hb_default( @cFrom    , "from@example.net" )
   hb_default( @cPassword, "password" )
   hb_default( @cTo      , "to@example.org" )
   hb_default( @cHost    , "localhost" )

   cFrom := "<" + ( cUser := hb_curl_mail_address_to_email( cFrom ) ) + ">"
   cTo := "<" + hb_curl_mail_address_to_email( cTo ) + ">"
   cHost := Lower( cHost )

   cSubject := "Example sending a MIME-formatted message"

   cText := ;
      e"This is the inline text message of the email.\r\n" + ;
      e"\r\n" + ;
      e"  It could be a lot of lines that would be displayed in an email\r\n" + ;
      e"viewer that is not able to handle HTML.\r\n"

   cHTML := ;
      e"<html><body>\r\n" + ;
      e"<p>This is the inline <strong>HTML</strong> message of the email.</p>" + ;
      e"<br>\r\n" + ;
      e"<p>It could be a lot of HTML data that would be displayed by " + ;
      e"email viewers able to handle HTML.</p>" + ;
      e"</body></html>\r\n"

   lSTARTTLS_force := .F.

   /* NOTE: Consult your provider for updated settings
            and create a Pull Request if necessary. */

   DO CASE
   CASE cHost == "apple" .OR. "@icloud.com" $ cFrom .OR. "@mac.com" $ cFrom .OR. "@me.com" $ cFrom
      cHost := "smtp://smtp.mail.me.com:587"; lSTARTTLS_force := .T.
   CASE cHost == "fastmail" .OR. "@fastmail.com" $ cFrom .OR. "@fastmail.fm" $ cFrom
      cHost := "smtps://smtp.fastmail.com"
   CASE cHost == "gmx.net" .OR. "@gmx.net" $ cFrom .OR. "@gmx.ch" $ cFrom .OR. "@gmx.de" $ cFrom
      cHost := "smtps://mail.gmx.net"
   CASE cHost == "google" .OR. "@gmail.com" $ cFrom .OR. "@googlemail.com" $ cFrom
      cHost := "smtps://smtp.gmail.com"
   CASE cHost == "mail.ru" .OR. "@mail.ru" $ cFrom
      cHost := "smtps://smtp.mail.ru"
   CASE cHost == "netease" .OR. "@163.com" $ cFrom
      cHost := "smtps://smtp.163.com"
   CASE cHost == "office365"
      cHost := "smtp://smtp.office365.com:587"; lSTARTTLS_force := .T.
   CASE cHost == "outlook" .OR. "@outlook.com" $ cFrom .OR. "@hotmail.com" $ cFrom
      cHost := "smtp://smtp-mail.outlook.com:587"; lSTARTTLS_force := .T.
   CASE cHost == "sina" .OR. "@sina.com" $ cFrom
      cHost := "smtps://smtp.vip.sina.com"
   CASE cHost == "uol" .OR. "@uol.com.br" $ cFrom
      cHost := "smtps://smtps.uol.com.br"
   CASE cHost == "yahoo" .OR. "@yahoo.com" $ cFrom
      cHost := "smtps://smtp.mail.yahoo.com"
   CASE cHost == "mailtrap.io" .OR. "@mailtrap.io" $ cFrom
      cHost := "smtp://smtp.mailtrap.io:465"; lSTARTTLS_force := .T.
      cUser := StrTran( cUser, "@mailtrap.io" )
   CASE cHost == "localhost"
      cHost := "smtp://localhost:1025"  /* MailHog */
      cUser := cPassword := NIL

   CASE cHost == "securesmtp.t-online.de"
      cHost := "smtp://securesmtp.t-online.de:465"; lSTARTTLS_force := .T.

   CASE cHost == "smtp.web.de"
      cHost := "smtp://smtp.web.de:587"; lSTARTTLS_force := .T.

   ENDCASE

   ? "libcurl:", curl_version_info()[ HB_CURLVERINFO_VERSION ]
   ? "Payload API:", iif( lAPI_curl, "libcurl native", "tip_MailAssemble()" )
   ? "Host:", cHost, iif( lSTARTTLS_force, "(must STARTTLS)", "" )

   #if defined( __PLATFORM__UNIX )
      lSystemCA := .T.
   #elif defined( __PLATFORM__WINDOWS )
      /* Switch to SChannel SSL backend, if available (on Windows).
         Doing this to use the OS certificate store. */
      curl_global_sslset( -1,, @tmp )
      IF ( lSystemCA := ;
         HB_CURLSSLBACKEND_SCHANNEL $ tmp .AND. ;
         curl_global_sslset( HB_CURLSSLBACKEND_SCHANNEL ) == HB_CURLSSLSET_OK )
         cCA := NIL
      ELSE
         cCA := hb_DirBase() + hb_DirSepToOS( "../../../bin/" ) + cCA
      ENDIF
   #else
      lSystemCA := .F.
   #endif

   curl_global_init()

   IF Empty( curl := curl_easy_init() )
      ? "Failed to init"
   ELSE
      IF ! lSystemCA
         IF hb_vfExists( cCA )
            curl_easy_setopt( curl, HB_CURLOPT_CAINFO, cCA )
         ELSE
            ?
            ? "Error: Trusted Root Certificates missing. Open this URL in your web browser:"
            ? "  " + "https://curl.se/ca/cacert.pem"
            ? "and save the file as:"
            ? "  " + cCA
            RETURN
         ENDIF
      ENDIF
      curl_easy_setopt( curl, HB_CURLOPT_USE_SSL, ;
         iif( lSTARTTLS_force, HB_CURLUSESSL_ALL, HB_CURLUSESSL_TRY ) )
      curl_easy_setopt( curl, HB_CURLOPT_UPLOAD )
      curl_easy_setopt( curl, HB_CURLOPT_URL, cHost )
      curl_easy_setopt( curl, HB_CURLOPT_PROTOCOLS, ;
         hb_bitOr( HB_CURLPROTO_SMTPS, HB_CURLPROTO_SMTP ) )
      curl_easy_setopt( curl, HB_CURLOPT_TIMEOUT_MS, 15000 )
      curl_easy_setopt( curl, HB_CURLOPT_VERBOSE, .T. )
      curl_easy_setopt( curl, HB_CURLOPT_USERNAME, cUser )
      curl_easy_setopt( curl, HB_CURLOPT_PASSWORD, cPassword )
      curl_easy_setopt( curl, HB_CURLOPT_MAIL_FROM, cFrom )
      curl_easy_setopt( curl, HB_CURLOPT_MAIL_RCPT, { cTo } )

      IF lAPI_curl
         curl_easy_setopt( curl, HB_CURLOPT_HTTPHEADER, { ;
            "Date: " + hb_curl_date(), ;
            "To: " + cTo, ;
            "From: hbcurl " + cFrom, ;
            "Cc: " + cTo, ;
            "Message-ID: <dcd7cb36-11db-487a-9f3a-e652a9458efd@rfcpedant.example.org>", ;
            "Reply-To: " + cFrom, ;
            "Disposition-Notification-To: " + cFrom, ;
            "X-Priority: " + hb_ntos( 3 ), ;  /* 1: high, 3: standard, 5: low */
            "Subject: " + cSubject } )

         /* NOTE: 'charset' to be added when implemented */
         curl_easy_setopt( curl, HB_CURLOPT_MIMEPOST, { ;
            { "subparts" => { ;
              { "data" => cHTML, ;
                "type" => "text/html" }, ;
              { "data" => cText } }, ;
              "type" => "multipart/alternative", ;
              "headers" => { "Content-Disposition: inline" } }, ;
            { "filedata" => __FILE__ }, ;
            { "data" => Replicate( hb_BChar( 123 ), 1024 ), ;
              "type" => "image/png", ;
              "encoder" => "base64", ;  /* binary, 8bit, 7bit, base64, quoted-printable */
              "filename" => "mock.png" } } )
      ELSE
         cText := tip_MailAssemble( ;
            "hbtip " + cFrom, ;
            { cTo }, ;
            /* aCC */, ;
            cText, ;
            cSubject, ;
            { __FILE__, { "mock.png", Replicate( hb_BChar( 123 ), 1024 ) } } /* attachments */, ;
            /* nPriority */, ;
            /* lRead */, ;
            /* cReplyTo */, ;
            /* cCharset */, ;
            /* cEncoding */, ;
            .F. /* lBodyHTML */, ;
            /* bSMIME */ )
         curl_easy_setopt( curl, HB_CURLOPT_UL_BUFF_SETUP, cText )
         curl_easy_setopt( curl, HB_CURLOPT_INFILESIZE_LARGE, hb_BLen( cText ) )
      ENDIF

      ? "Result:", curl_easy_perform( curl )
WAIT
      curl_easy_cleanup( curl )
   ENDIF

RETURN

FUNCTION hb_curl_mail_address_to_email( cAddress )
   LOCAL tmp, tmp1

   IF ( tmp := At( "<", cAddress ) ) > 0 .AND. ;
      ( tmp1 := hb_At( ">", cAddress, tmp + 1 ) ) > 0
      RETURN AllTrim( SubStr( cAddress, tmp + 1, tmp1 - tmp - 1 ) )
   ENDIF

   RETURN cAddress

FUNCTION hb_curl_mail_address_to_name( cAddress )
   LOCAL tmp

   IF ( tmp := At( "<", cAddress ) ) > 0 .AND. ;
      hb_At( ">", cAddress, tmp + 1 ) > 0
      RETURN RTrim( Left( cAddress, tmp - 1 ) )
   ENDIF

RETURN cAddress
the Sample is from hb-main.zip made by Viktor Szakats
i have have found it "somewhere" @GitHub ...

it include Source
date.c
easy.c
escold.c
global.c
miscc.c
ver.c
hbcurl.ch
hbcurl.hbc
hbcurl.hbp
hbcurl.hbx
misc.prg
tests\email.prg
tests\ftp_uldl.prg
tests\hbmk.hbm
so how to build LIB "a" from Source :idea:

p.s. "where" to put Source to build :?:
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
AUGE_OHR
Posts: 2064
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: CURL for HMG latest Version ?

Post by AUGE_OHR »

hi Rathinagiri,

this is the LIB Source for that Email Sample.
hbcurl.zip
(38.21 KiB) Downloaded 422 times
Question :
a.) "where" to put those Source :?:
b.) "how" to use hbcurl.hbp :?:

i guess to put Source into x:\hmg.3.4.4\HARBOUR\contrib\hbcurl\
and start with : hbmk2 hbcurl.hbp
have fun
Jimmy
User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: CURL for HMG latest Version ?

Post by Rathinagiri »

Create Build.bat using the below code inside HMG Source folder say d:\hmg.3.5\source\hbcurl

Code: Select all

@echo off

SET HMGPATH=%~dp0%
SET HMGPATH1=%HMGPATH:~0,-15%

SET PATH=%HMGPATH1%\harbour\bin;%HMGPATH1%\mingw\bin;%PATH%


hbmk2 hbcurl.hbp -i%hmgpath1%\include
pause
When I tried to run the build.bat it says "Missing Dependency Curl"
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
edk
Posts: 914
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland

Re: CURL for HMG latest Version ?

Post by edk »

Support for IMAP and SMTP protocols from HMG using the latest fork of the libcurl library.

In the attachment I am sending sources, libraries for example of using libCurl in communication with mail servers via IMAP and SMTP protocols.

The program was tested on several IMAP servers: web.de; gmail.com; om.pl; onet.pl using both SSL and STARTTLS - however, I can not guarantee that it will work properly on all servers, I worked a bit in the dark, mostly by trial and error, because IMAP documents are quite extensive, I focused on the basic activities: logging, listing, reading messages, sending messages, deleting messages, creating and deleting folders, and placing messages after sending to the 'Sent' folder.

Attached is a ready configuration for connecting to the IMAP web.de server, but you can try to connect to your server by simply selecting the Configure button.
IMAP_SMTP_LIBCURL.png
IMAP_SMTP_LIBCURL.png (346.69 KiB) Viewed 39391 times
Important. The newest libraries for both libcurl and the Harbour fork of this library are required for the program to compile.

The libcurl.dll (version 7.85) and the rest of the .dll files should be placed in the same folder as the executing program. The libCurl fork for Harbour is located in the hmg.3.4.4 subfolder. You need to copy the contents of this folder to your location of hmg.3.4.4 (not tested on other versions) overwriting old files.

The new fork is necessary to be able to read the information headers sent from the IMAP server. Unfortunately, the native functions for reading these headers do not work in this fork, the solution is to process them in debug mode, which slows down the whole process, but well: Beggars can't be choosers ;-)

Note, use this tool with caution as folders and messages can be deleted.

IMAP folder names are encoded in mUTF-7 (modified UTF-7), so there is support for this encoding in the source.

I noticed that TipMail doesn't always work properly with all message formats, but I haven't found a newer version on the web, so we have to deal with its limitations. Also, ActiveX shell.explorer.2 support from a thread other than the main thread causes the program to crash, so I resigned from a separate thread for reading messages and download them in the main one.

PS. A big thank you to Marek (MOL) for the effort he put into paving the way for success.

Some comments and functions may be in Polish, which I'm sorry for, but I didn't have much time to clean up the code. I hope the code will be quite understandable after all.

edk.
Attachments
imap_Curl.7z
(3.29 MiB) Downloaded 509 times
User avatar
mol
Posts: 3724
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Contact:

Re: CURL for HMG latest Version ?

Post by mol »

Great work, Edward!
I only began and you're great finishman!
User avatar
serge_girard
Posts: 3169
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: CURL for HMG latest Version ?

Post by serge_girard »

Thanks Edward !
Great job!

Serge
There's nothing you can do that can't be done...
Post Reply