From c86db093becc3dfffa008a895709563104a6505e Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 13 Apr 2010 20:30:25 +0000 Subject: [PATCH] Fix: Can provide ip address on smtps. Better error reporting. --- ChangeLog | 1 + htdocs/includes/smtps/SMTPs.php | 11 +++++++++-- htdocs/lib/CMailFile.class.php | 5 ++++- htdocs/lib/functions2.lib.php | 2 +- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index f7831eda591..5ca27301334 100644 --- a/ChangeLog +++ b/ChangeLog @@ -25,6 +25,7 @@ For users: - Fix: Format number was wrong for ar_AR language. - Fix: Can change password if has only permission change password. - Fix: Project PDF document show the tasks. +- Fix: bug #29278 : SMTP fails with IP For developers: - More comments in code. diff --git a/htdocs/includes/smtps/SMTPs.php b/htdocs/includes/smtps/SMTPs.php index b0dfa909e3d..fb6e279af97 100644 --- a/htdocs/includes/smtps/SMTPs.php +++ b/htdocs/includes/smtps/SMTPs.php @@ -627,7 +627,11 @@ class SMTPs $host=$this->getHost(); $host=preg_replace('@tcp://@i','',$host); // Remove prefix $host=preg_replace('@ssl://@i','',$host); // Remove prefix - if ( (gethostbyname ( $host )) == $host ) + + // DOL_CHANGE LDR + include_once(DOL_DOCUMENT_ROOT.'/lib/functions2.lib.php'); + + if ( (! is_ip($host)) && ((gethostbyname ( $host )) == $host) ) { $this->_setErr ( 99, $host . ' is either offline or is an invalid host name.' ); $_retVal = false; @@ -1996,7 +2000,7 @@ class SMTPs */ //$content = 'Content-Type: multipart/related; boundary="' . $this->_getBoundary() . '"' . "\r\n"; $content = 'Content-Type: multipart/mixed; boundary="' . $this->_getBoundary() . '"' . "\r\n"; - + // TODO Restore // . "\r\n" // . 'This is a multi-part message in MIME format.' . "\r\n"; @@ -2513,6 +2517,9 @@ class SMTPs /** * $Log$ + * Revision 1.12 2010/04/13 20:30:25 eldy + * Fix: Can provide ip address on smtps. Better error reporting. + * * Revision 1.11 2010/01/12 13:02:07 hregis * Fix: missing attach-files * diff --git a/htdocs/lib/CMailFile.class.php b/htdocs/lib/CMailFile.class.php index f3184b740e5..88315b39e21 100644 --- a/htdocs/lib/CMailFile.class.php +++ b/htdocs/lib/CMailFile.class.php @@ -401,7 +401,10 @@ class CMailFile { if (! empty($conf->global->MAIN_MAIL_DEBUG)) $this->smtps->setDebug(true); $result=$this->smtps->sendMsg(); - //print $resultvalue; + if (! $result) + { + $this->error=$this->smtps->getErrors(); + } } if (! empty($conf->global->MAIN_MAIL_DEBUG)) $this->dump_mail(); diff --git a/htdocs/lib/functions2.lib.php b/htdocs/lib/functions2.lib.php index 5639ede3403..d9f84314f33 100644 --- a/htdocs/lib/functions2.lib.php +++ b/htdocs/lib/functions2.lib.php @@ -1101,7 +1101,7 @@ function getListOfModels($db,$type) */ function is_ip($ip) { - if (!ereg("^([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$", $ip)) return 0; + if (!preg_match("/^([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/", $ip)) return 0; if (sprintf("%u",ip2long($ip)) == sprintf("%u",ip2long('255.255.255.255'))) return 0; if (sprintf("%u",ip2long('10.0.0.0')) <= sprintf("%u",ip2long($ip)) and sprintf("%u",ip2long($ip)) <= sprintf("%u",ip2long('10.255.255.255'))) return 2; if (sprintf("%u",ip2long('172.16.0.0')) <= sprintf("%u",ip2long($ip)) and sprintf("%u",ip2long($ip)) <= sprintf("%u",ip2long('172.31.255.255'))) return 2;