File: 0.04.00a/server/base/tests/imap.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 imap_test_connect($host,$user,$pass,$timeout=-1,$protocol="imap",$port=-1,$ssl=false,$debug=false) 24: { 25: if ($timeout>0) imap_timeout(IMAP_OPENTIMEOUT,$timeout); 26: 27: if ($port<=0) 28: { 29: $port=143; // default 30: if ( ($protocol=="imap") && ($ssl) ) $port=993; 31: else if ($protocol=="pop3") 32: { 33: if ($ssl) $port=995; 34: else $port=110; 35: } 36: } 37: 38: $mailbox="{".$host.":".$port."/service=".$protocol; 39: if ($ssl) $mailbox.="/ssl"; 40: $mailbox.="/novalidate-cert"; 41: $mailbox.="}INBOX"; 42: if ($debug) echo $user.":".$pass."@".$mailbox."\n"; 43: $imap=@imap_open($mailbox,$user,$pass); 44: if ($imap===false) return 0; 45: 46: @imap_close($imap); 47: return 1; 48: } 49: 50: function imap_test_time($host,$user,$pass,$timeout=-1,$protocol="imap",$port=-1,$ssl=false,$debug=false) 51: { 52: $timer=new TFNTimer(); 53: $timer->Start(); 54: $res=imap_test_connect($host,$user,$pass,$timeout,$protocol,$port,$ssl,$debug); 55: $time=$timer->Stop(); 56: if ($res<=0) return $res; // test failed to connect 57: $time=round($time,4); 58: if ($time==0) $time=0.0001; 59: return $time; 60: } 61: 62: ?>