From b61a3a5b20104d8a03a6594df70b40c320bb5117 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Mon, 9 Jan 2012 21:20:48 +0000 Subject: [PATCH] 2012-01-09 22:20 UTC+0100 Viktor Szakats (harbour syenar.net) * contrib/hbtip/sendmail.prg * contrib/hbtip/smtpcli.prg ! After a conversation with Antonio Maniero (also subscriber of the dev-list), we detected some trouble with hb_sendmail() under some conditions: EXIM servers refuse the HELO/EHLO greeting that doesn't conform to RFC2821, so when one try to autenticate with username containing an @ or any other character that is not allowed in FQDNs, the server refuses to proceed. Many SMTP servers, (EG: Google ones) are more tolerant, so I believe that this helped the problem gets unnoticed. The patch introduces a new parameter, preserving backward compatibility and at the same time fixing the @ problem, even in unmodified code that doesn't provide the extra parameter (as we removed the cUser from the HELO string, that is causing trouble with EXIM. Anyway, these strings would be accepted only by tolerant servers, so the correct one should cause no problem at all). ; Patch and description by Carlos Bacco. Thank you. --- harbour/ChangeLog | 19 +++++++++++++++++++ harbour/contrib/hbtip/sendmail.prg | 10 ++++++---- harbour/contrib/hbtip/smtpcli.prg | 10 ++++++---- 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index af3fe756a6..81a15dfda2 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -16,6 +16,25 @@ The license applies to all entries newer than 2009-04-28. */ +2012-01-09 22:20 UTC+0100 Viktor Szakats (harbour syenar.net) + * contrib/hbtip/sendmail.prg + * contrib/hbtip/smtpcli.prg + ! After a conversation with Antonio Maniero (also subscriber of the + dev-list), we detected some trouble with hb_sendmail() under some + conditions: + EXIM servers refuse the HELO/EHLO greeting that doesn't conform to + RFC2821, so when one try to autenticate with username containing an @ + or any other character that is not allowed in FQDNs, the server + refuses to proceed. Many SMTP servers, (EG: Google ones) are more + tolerant, so I believe that this helped the problem gets unnoticed. + The patch introduces a new parameter, preserving backward + compatibility and at the same time fixing the @ problem, even in + unmodified code that doesn't provide the extra parameter (as we + removed the cUser from the HELO string, that is causing trouble with + EXIM. Anyway, these strings would be accepted only by tolerant + servers, so the correct one should cause no problem at all). + ; Patch and description by Carlos Bacco. Thank you. + 2012-01-09 16:18 UTC+0100 Viktor Szakats (harbour syenar.net) * contrib/hbssl/ssl.c * contrib/hbssl/sslctx.c diff --git a/harbour/contrib/hbtip/sendmail.prg b/harbour/contrib/hbtip/sendmail.prg index 3fd07b3cc3..f246840de1 100644 --- a/harbour/contrib/hbtip/sendmail.prg +++ b/harbour/contrib/hbtip/sendmail.prg @@ -58,7 +58,7 @@ FUNCTION hb_SendMail( cServer, nPort, cFrom, xTo, xCC, xBCC, cBody, cSubject, ; aFiles, cUser, cPass, cPopServer, nPriority, lRead, ; xTrace, lPopAuth, lNoAuth, nTimeOut, cReplyTo, ; - lTLS, cSMTPPass, cCharset, cEncoding ) + lTLS, cSMTPPass, cCharset, cEncoding, cClientHost ) /* cServer -> Required. IP or domain name of the mail server nPort -> Optional. Port used my email server @@ -78,8 +78,10 @@ FUNCTION hb_SendMail( cServer, nPort, cFrom, xTo, xCC, xBCC, cBody, cSubject, ; If a block is passed, it will be called for each log event with the message a string, no param on session close. lPopAuth -> Optional. Do POP3 authentication before sending mail. lNoAuth -> Optional. Disable Autentication methods - nTimeOut -> Optional. Number os ms to wait default 20000 (20s) + nTimeOut -> Optional. Number os ms to wait default 10000 (10s) cReplyTo -> Optional. + cClientHost-> Optional. Domain name of the SMTP client in the format smtp.example.com OR client IP surrounded by brackets as in [200.100.100.5] + Note: This parameter is optional for backwards compatibility, but should be provided to comply with RFC 2812. */ LOCAL cTmp @@ -228,7 +230,7 @@ FUNCTION hb_SendMail( cServer, nPort, cFrom, xTo, xCC, xBCC, cBody, cSubject, ; oUrl:cFile := cTo + iif( Empty( cCC ), "", "," + cCC ) + iif( Empty( cBCC ), "", "," + cBCC ) BEGIN SEQUENCE - oInmail := tIPClientSMTP():New( oUrl, xTrace ) + oInmail := tIPClientSMTP():New( oUrl, xTrace, NIL, cClientHost ) RECOVER lReturn := .F. END SEQUENCE @@ -293,7 +295,7 @@ FUNCTION hb_SendMail( cServer, nPort, cFrom, xTo, xCC, xBCC, cBody, cSubject, ; ENDIF BEGIN SEQUENCE - oInmail := tIPClientSMTP():New( oUrl, xTrace ) + oInmail := tIPClientSMTP():New( oUrl, xTrace, NIL, cClientHost ) RECOVER lReturn := .F. END SEQUENCE diff --git a/harbour/contrib/hbtip/smtpcli.prg b/harbour/contrib/hbtip/smtpcli.prg index 9b9ab4760c..d4b1040123 100644 --- a/harbour/contrib/hbtip/smtpcli.prg +++ b/harbour/contrib/hbtip/smtpcli.prg @@ -63,7 +63,7 @@ CREATE CLASS tIPClientSMTP FROM tIPClient - METHOD New( oUrl, xTrace, oCredentials ) + METHOD New( oUrl, xTrace, oCredentials, cClientHost ) METHOD Open( cUrl, lTLS ) METHOD Close() METHOD Write( cData, nLen, bCommit ) @@ -84,16 +84,18 @@ CREATE CLASS tIPClientSMTP FROM tIPClient HIDDEN: VAR isAuth INIT .F. + VAR cClientHost ENDCLASS -METHOD New( oUrl, xTrace, oCredentials ) CLASS tIPClientSMTP +METHOD New( oUrl, xTrace, oCredentials, cClientHost ) CLASS tIPClientSMTP ::super:new( oUrl, iif( ISLOGICAL( xTrace ) .AND. xTrace, "smtp", xTrace ), oCredentials ) ::nDefaultPort := iif( ::oUrl:cProto == "smtps", 465, 25 ) ::nConnTimeout := 50000 ::nAccessMode := TIP_WO // a write only + ::cClientHost := cClientHost RETURN Self @@ -118,7 +120,7 @@ METHOD Open( cUrl, lTLS ) CLASS tIPClientSMTP ENDIF ENDIF - ::InetSendall( ::SocketCon, "HELO " + iif( Empty( ::oUrl:cUserid ), "tipClientSMTP", ::oUrl:cUserid ) + ::cCRLF ) + ::InetSendall( ::SocketCon, "HELO " + iif( Empty( ::cClientHost ), "tipClientSMTP", ::cClientHost ) + ::cCRLF ) RETURN ::GetOk() @@ -143,7 +145,7 @@ METHOD OpenSecure( cUrl, lTLS ) CLASS tIPClientSMTP ENDIF ENDIF - ::InetSendall( ::SocketCon, "EHLO " + iif( Empty( ::oUrl:cUserid ), "tipClientSMTP", ::oUrl:cUserid ) + ::cCRLF ) + ::InetSendall( ::SocketCon, "EHLO " + iif( Empty( ::cClientHost ), "tipClientSMTP", ::cClientHost ) + ::cCRLF ) RETURN ::GetOk()