File: 0.04.00a/server/base/tests/smtp.inc.php (View as Code)

1: 2: /* ------------------------------------------------------------- 3: This file is part of FreeNATS 4: 5: FreeNATS is (C) Copyright 2008 PurplePixie Systems 6: 7: FreeNATS is free software: you can redistribute it and/or modify 8: it under the terms of the GNU General Public License as published by 9: the Free Software Foundation, either version 3 of the License, or 10: (at your option) any later version. 11: 12: FreeNATS is distributed in the hope that it will be useful, 13: but WITHOUT ANY WARRANTY; without even the implied warranty of 14: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15: GNU General Public License for more details. 16: 17: You should have received a copy of the GNU General Public License 18: along with FreeNATS. If not, see www.gnu.org/licenses 19: 20: For more information see www.purplepixie.org/freenats 21: -------------------------------------------------------------- */ 22: 23: function smtp_test_connect($hostname,$port=25,$timeout=-1,$debug=false) 24: { 25: if ($port=="") $port=25; 26: if ($timeout<=0) $timeout=20; // default 27: $errno=0; 28: $errstr=0; 29: $fp=@fsockopen($hostname,$port,$errno,$errstr,$timeout); 30: if ($errno!=0) return 0; 31: if ($fp<=0) return 0; 32: stream_set_timeout($fp,$timeout); 33: $header=@fgets($fp,128); 34: if ($debug) echo $header."\n"; 35: if (substr($header,0,3)!="220") return 0; 36: if (@fputs($fp,"HELO freenats\n")===false) return 0; 37: $body=@fgets($fp,128); 38: if ($debug) echo $body."\n"; 39: if ($body=="") return 0; 40: if (@fputs($fp,"QUIT\n")===false) return 0; 41: @fclose($fp); 42: return 1; 43: } 44: 45: function smtp_test_time($hostname,$port=25,$timeout=-1,$debug=false) 46: { 47: $timer=new TFNTimer(); 48: $timer->Start(); 49: $res=smtp_test_connect($hostname,$port,$timeout,$debug); 50: $time=$timer->Stop(); 51: if ($res<=0) return $res; // connect failed 52: $time=round($time,4); 53: if ($time==0) $time=0.0001; 54: return $time; 55: } 56: 57: ?>