function _sendtoip($ip, $arrto, $isrelay)
 {
     $ssl = '';
     $pnm = $this->_port;
     if ($isrelay) {
         $ssl = $this->_relay['ssl'] ? $this->_relay['ssl'] . '://' : '';
         $pnm = $this->_relay['port'];
     }
     if (!($sock = fsockopen($ssl . $ip, $pnm, $errnum, $errmsg, $this->_timeout))) {
         $this->result = 'Error 10: ' . $errmsg;
         return false;
     }
     stream_set_timeout($sock, $this->_timeout);
     $loop = $rcv = 0;
     while (!feof($sock)) {
         $loop++;
         if ($rcv = fgets($sock, $this->max_sl)) {
             if ($loop == $this->max_cl || substr($rcv, 0, 4) != "220-") {
                 break;
             }
         } else {
             break;
         }
     }
     if (!$rcv) {
         $this->result = 'Error 11: can\'t read';
         return false;
     }
     if (substr($rcv, 0, 4) != "220 ") {
         $this->result = 'Error 12: ' . $rcv;
         return false;
     }
     if (!FUNC::is_connection($sock)) {
         $this->result = 'Error 13: invalid resource connection';
         return false;
     }
     if ($isrelay && $this->_relay['user'] != "" && $this->_relay['pass'] != "") {
         if (!fputs($sock, 'EHLO ' . $this->_fromhost . $this->_crlf)) {
             $this->result = 'Error 20: can\'t write';
             return false;
         }
         $loop = $rcv = 0;
         $getinfo = '';
         while (!feof($sock)) {
             $loop++;
             if ($rcv = fgets($sock, $this->max_sl)) {
                 $getinfo .= $rcv;
                 if ($loop == $this->max_cl || substr($rcv, 0, 4) != "250-") {
                     break;
                 }
             } else {
                 break;
             }
         }
         if (!$rcv) {
             $this->result = 'Error 21: can\'t read';
             return false;
         }
         if (substr($rcv, 0, 4) != "250 ") {
             if (!FUNC::is_connection($sock)) {
                 $this->result = 'Error 22: invalid resource connection';
                 return false;
             }
             if (!fputs($sock, 'HELO ' . $this->_fromhost . $this->_crlf)) {
                 $this->result = 'Error 23: can\'t write';
                 return false;
             }
             $loop = $rcv = 0;
             $getinfo = '';
             while (!feof($sock)) {
                 $loop++;
                 if ($rcv = fgets($sock, $this->max_sl)) {
                     $getinfo .= $rcv;
                     if ($loop == $this->max_cl || substr($rcv, 0, 4) != "250-") {
                         break;
                     }
                 } else {
                     break;
                 }
             }
             if (!$rcv) {
                 $this->result = 'Error 24: can\'t read';
                 return false;
             }
             if (substr($rcv, 0, 4) != "250 ") {
                 $this->result = 'Error 25: ' . $rcv;
                 return false;
             }
         }
         $authlogin = strstr($getinfo, 'LOGIN');
         $authplain = strstr($getinfo, 'PLAIN');
         $authtype = 'login';
         if ($this->_relay['auth'] == "autodetect" || $this->_relay['auth'] == "login") {
             if (!$authlogin) {
                 if ($authplain) {
                     $authtype = 'plain';
                 }
             }
         } elseif ($this->_relay['auth'] == "plain") {
             if ($authplain) {
                 $authtype = 'plain';
             }
         }
         if (!FUNC::is_connection($sock)) {
             $this->result = 'Error 26: invalid resource connection';
             return false;
         }
         if ($authtype == "login") {
             if (!fputs($sock, 'AUTH LOGIN' . $this->_crlf)) {
                 $this->result = 'Error 270: can\'t write';
                 return false;
             }
             if (!($rcv = fgets($sock, $this->max_sl))) {
                 $this->result = 'Error 271: can\'t read';
                 return false;
             }
             if (substr($rcv, 0, 4) != "334 ") {
                 $this->result = 'Error 272: ' . $rcv;
                 return false;
             }
             if (!FUNC::is_connection($sock)) {
                 $this->result = 'Error 273: invalid resource connection';
                 return false;
             }
             if (!fputs($sock, base64_encode($this->_relay['user']) . $this->_crlf)) {
                 $this->result = 'Error 274: can\'t write';
                 return false;
             }
             if (!($rcv = fgets($sock, $this->max_sl))) {
                 $this->result = 'Error 275: can\'t read';
                 return false;
             }
             if (substr($rcv, 0, 4) != "334 ") {
                 $this->result = 'Error 276: ' . $rcv;
                 return false;
             }
             if (!FUNC::is_connection($sock)) {
                 $this->result = 'Error 277: invalid resource connection';
                 return false;
             }
             if (!fputs($sock, base64_encode($this->_relay['pass']) . $this->_crlf)) {
                 $this->result = 'Error 278: can\'t write';
                 return false;
             }
             if (!($rcv = fgets($sock, $this->max_sl))) {
                 $this->result = 'Error 279: can\'t read';
                 return false;
             }
             if (substr($rcv, 0, 4) != "235 ") {
                 $this->result = 'Error 280: ' . $rcv;
                 return false;
             }
         } elseif ($authtype == "plain") {
             if (!FUNC::is_connection($sock)) {
                 $this->result = 'Error 281: invalid resource connection';
                 return false;
             }
             if (!fputs($sock, 'AUTH PLAIN ' . base64_encode($this->_relay['user'] . chr(0) . $this->_relay['user'] . chr(0) . $this->_relay['pass']) . $this->_crlf)) {
                 $this->result = 'Error 282: can\'t write';
                 return false;
             }
             if (!($rcv = fgets($sock, $this->max_sl))) {
                 $this->result = 'Error 283: can\'t read';
                 return false;
             }
             if (substr($rcv, 0, 4) != "235 ") {
                 $this->result = 'Error 284: ' . $rcv;
                 return false;
             }
         }
     } else {
         if (!fputs($sock, 'HELO ' . $this->_fromhost . $this->_crlf)) {
             $this->result = 'Error 30: can\'t write';
             return false;
         }
         $loop = $rcv = 0;
         while (!feof($sock)) {
             $loop++;
             if (!($rcv = fgets($sock, $this->max_sl))) {
                 if ($loop == $this->max_cl || substr($rcv, 0, 4) != "250-") {
                     break;
                 }
             } else {
                 break;
             }
         }
         if (!$rcv) {
             $this->result = 'Error 31: can\'t read';
             return false;
         }
         if (substr($rcv, 0, 4) != "250 ") {
             if (!FUNC::is_connection($sock)) {
                 $this->result = 'Error 32: invalid resource connection';
                 return false;
             }
             if (!fputs($sock, 'EHLO ' . $this->_fromhost . $this->_crlf)) {
                 $this->result = 'Error 33: can\'t write';
                 return false;
             }
             $loop = $rcv = 0;
             while (!feof($sock)) {
                 $loop++;
                 if (!($rcv = fgets($sock, $this->max_sl))) {
                     if ($loop == $this->max_cl || substr($rcv, 0, 4) != "250-") {
                         break;
                     }
                 } else {
                     break;
                 }
             }
             if (!$rcv) {
                 $this->result = 'Error 34: can\'t read';
                 return false;
             }
             if (substr($rcv, 0, 4) != "250 ") {
                 $this->result = 'Error 35: ' . $rcv;
                 return false;
             }
         }
     }
     if (!FUNC::is_connection($sock)) {
         $this->result = 'Error 40: invalid resource connection';
         return false;
     }
     if (!fputs($sock, 'MAIL FROM:<' . $this->_fromaddr['address'] . '>' . $this->_crlf)) {
         $this->result = 'Error 41: can\'t write';
         return false;
     }
     if (!($rcv = fgets($sock, $this->max_sl))) {
         $this->result = 'Error 42: can\'t read';
         return false;
     }
     if (substr($rcv, 0, 4) != "250 ") {
         $this->result = 'Error 43: ' . $rcv;
         return false;
     }
     $relayh = $isrelay ? '@' . $this->_relay['host'] . ':' : '';
     $setver = true;
     foreach ($arrto as $arrval) {
         if (!FUNC::is_connection($sock)) {
             $this->result = 'Error 50: invalid resource connection';
             $setver = false;
             break;
         }
         if (!fputs($sock, 'RCPT TO:<' . $relayh . $arrval . '>' . $this->_crlf)) {
             $this->result = 'Error 51: can\'t write';
             $setver = false;
             break;
         }
         if (!($rcv = fgets($sock, $this->max_sl))) {
             $this->result = 'Error 52: can\'t read';
             $setver = false;
             break;
         }
         $submsg = substr($rcv, 0, 4);
         if (!($submsg == "250 " || $submsg == "251 ")) {
             $this->result = 'Error 53: ' . $rcv;
             $setver = false;
             break;
         }
     }
     if (!$setver) {
         return false;
     }
     if (!FUNC::is_connection($sock)) {
         $this->result = 'Error 60: invalid resource connection';
         return false;
     }
     if (!fputs($sock, 'DATA' . $this->_crlf)) {
         $this->result = 'Error 61: can\'t write';
         return false;
     }
     if (!($rcv = fgets($sock, $this->max_sl))) {
         $this->result = 'Error 62: can\'t read';
         return false;
     }
     if (substr($rcv, 0, 4) != "354 ") {
         $this->result = 'Error 63: ' . $rcv;
         return false;
     }
     if (!FUNC::is_connection($sock)) {
         $this->result = 'Error 70: invalid resource connection';
         return false;
     }
     if (!fputs($sock, $this->_content['header']['client'])) {
         $this->result = 'Error 71: can\'t write';
         return false;
     }
     $setver = true;
     foreach ($this->_content['body'] as $partmsg) {
         if (!FUNC::is_connection($sock)) {
             $this->result = 'Error 72: invalid resource connection';
             $setver = false;
             break;
         }
         if (!fputs($sock, $partmsg)) {
             $this->result = 'Error 73: can\'t write';
             $setver = false;
             break;
         }
     }
     if (!$setver) {
         return false;
     }
     if (!FUNC::is_connection($sock)) {
         $this->result = 'Error 80: invalid resource connection';
         return false;
     }
     if (!fputs($sock, $this->_crlf . '.' . $this->_crlf)) {
         $this->result = 'Error 81: can\'t write';
         return false;
     }
     if (!($rcv = fgets($sock, $this->max_sl))) {
         $this->result = 'Error 82: can\'t read';
         return false;
     }
     if (substr($rcv, 0, 4) != "250 ") {
         $this->result = 'Error 83: ' . $rcv;
         return false;
     }
     if (FUNC::is_connection($sock)) {
         if (fputs($sock, 'RSET' . $this->_crlf)) {
             if (FUNC::is_connection($sock)) {
                 if ($rcvr = @fgets($sock, $this->max_sl)) {
                     if (substr($rcvr, 0, 3) == "250") {
                         if (fputs($sock, 'QUIT' . $this->_crlf)) {
                             if (FUNC::is_connection($sock)) {
                                 if ($rcvq = @fgets($sock, $this->max_sl)) {
                                     $rcv = $rcvq;
                                 }
                                 FUNC::close($sock);
                             }
                         }
                     }
                 }
             }
         }
     }
     $this->result = 'Success: ' . $rcv;
     return true;
 }
示例#2
0
 function pquit($connection)
 {
     $ret = false;
     if (FUNC::is_connection($connection)) {
         fputs($connection, "QUIT\r\n");
         $rcv = fgets($connection, 1024);
         if (substr($rcv, 0, 3) == '+OK') {
             $ret = true;
         } else {
             trigger_error('Response error "' . $rcv . '", on class POP3::pquit()', 512);
         }
         FUNC::close($connection);
     } else {
         trigger_error('Invalid resource connection, on class POP3::pquit()', 512);
     }
     return $ret;
 }