1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
|
<?php
function gethostbynameFalse($nametotest){
$ipaddress = $nametotest;
$ipaddress = gethostbyname($nametotest);
if ($ipaddress == $nametotest) {
return false;
}else {
return $ipaddress;
}
}
function checkMailbox($user,$host,$email,$mailbox_type,$server,$login,$password){
global $errTxt;
// Check function parameters...
switch($mailbox_type){
case "MSN":
case "HOTMAIL":{
if($mailbox_type == "MSN"){
$domain = "msn.com";
}else{
$domain = "hotmail.com";
}
echo $login;
if(!isMailPassword($login)){
if(false != strstr('@',$login)){
$errTxt = "Mail login format not correct, you shouldn't happen ".'@'."$domain to login)";
}else{
$errTxt = "Mail login format not correct!";
}
return false;
}
if(!isMailPassword($password)){
$errTxt = "Mail password format not correct!";
return false;
}
// This one need field checking, otherwise a user can execute a system wide command under nobody:nogroup user...
$cmd = "gotmail -u $login".'@'."$domain -d $domain -p $password -s localhost -f $user".'@'."$host --nodownload";
echo $cmd;
$out = exec($cmd,$output,$ret_val);
$cmd_console = "";
for($i=0;$i<sizeof($output);$i++){
echo $output[$i]."<br>";
$cmd_console .= $output[$i]."<br>";
}
if($ret_val != 0){
$errTxt = "Could not get mail from $domain: $cmd_console";
return false;
}
}break;
case "POP3":{
// Check email format
if(!isValidEmail($email)){
$errTxt = "Give email is not valid $email";
return false;
}
// echo "Checking POP3<br>";
if(($server_ip = gethostbynameFalse($server)) == false){
$errTxt = "Cannot resolv your pop3 server, maybe you entered a wrong address: $server";
return false;
}
// echo "Opening socket<br>";
$soc = fsockopen($server_ip,110,$erno,$errstring,10);
if($soc == false){
$errTxt = "Could not connect to pop3 server (timed out): $server";
return false;
}
// echo "Checking ok after connect<br>";
$popline = fgets($soc,1024);
if(!strstr($popline,"+OK")){
$errTxt = "Server did not send OK after connect, maybe wrong server or server is down: $popline";
return false;
}
// echo "Sending login<br>";
if(!fwrite($soc,"USER $login\n")){
$errTxt = "Could not write USER $login to server";
return false;
}
// echo "Checking ok after login<br>";
$popline = fgets($soc,1024);
if(!strstr($popline,"+OK")){
$errTxt = "Server did not send OK after USER, maybe login is wrong: $popline";
return false;
}
//echo "Sending pass<br>";
if(!fwrite($soc,"PASS $password\n")){
$errTxt = "Could not write to pop3 server for password";
return false;
}
//echo "Checking ok after pass<br>";
$popline = fgets($soc,1024);
if(!strstr($popline,"+OK")){
$errTxt = "Server didn't accept your login/pass: $popline";
return false;
}
//echo "Closing socket<br>";
fclose($soc);
}break;
default:{
$errTxt = "Mailbox type not supported (yet?)!";
return false;
}break;
}
$errTxt = "Successfully checked and added mail account.";
return true;
}
?>
|