示例#1
0
文件: MAIL5.php 项目: voitto/dbscript
 public function send($resc = null, $debug = null)
 {
     global $_RESULT;
     $_RESULT = $err = array();
     if (!FUNC5::is_debug($debug)) {
         $debug = debug_backtrace();
     }
     if (is_resource($resc)) {
         $delivery = 'relay';
     } else {
         if ($resc == null) {
             $delivery = 'local';
         }
         if (!is_string($resc)) {
             $err[] = 'invalid connection type';
         } else {
             $resc = strtolower(trim($resc));
             if ($resc == 'local' || $resc == 'client' || $resc == 'sendmail' || $resc == 'qmail') {
                 $delivery = $resc;
             } else {
                 $err[] = 'invalid connection value';
             }
         }
     }
     if (count($this->To) == 0) {
         $err[] = 'to mail address is not set';
     }
     if (!isset($this->Subject['content'])) {
         $err[] = 'mail subject is not set';
     }
     if (!(isset($this->Text['content']) || isset($this->Html['content']))) {
         $err[] = 'mail message is not set';
     }
     if (count($err) > 0) {
         FUNC5::trace($debug, implode(', ', $err));
     } else {
         $header['local'] = $header['client'] = array();
         $body = '';
         $from = null;
         if (isset($this->From['address']) && is_string($this->From['address'])) {
             $from = $this->From['address'];
             $hv = 'From: ';
             if (isset($this->From['name'])) {
                 $hn = MIME5::encode_header($this->From['name'], isset($this->From['charset']) ? $this->From['charset'] : null, isset($this->From['encoding']) ? $this->From['encoding'] : null, null, null, $debug);
                 if ($hn == $this->From['name']) {
                     $hn = '"' . str_replace('"', '\\"', $this->From['name']) . '"';
                 }
                 $hv .= $hn . ' <' . $this->From['address'] . '>';
             } else {
                 $hv .= $this->From['address'];
             }
             $header['local'][] = $hv;
             $header['client'][] = $hv;
         }
         $addrs = $arr = array();
         foreach ($this->To as $to) {
             if (isset($to['address']) && FUNC5::is_mail($to['address'], false, $debug)) {
                 $addrs[] = $to['address'];
                 if (isset($to['name'])) {
                     $hn = MIME5::encode_header($to['name'], isset($to['charset']) ? $to['charset'] : null, isset($to['encoding']) ? $to['encoding'] : null, null, null, $debug);
                     if ($hn == $to['name']) {
                         $hn = '"' . str_replace('"', '\\"', $to['name']) . '"';
                     }
                     $arr[] = $hn . ' <' . $to['address'] . '>';
                 } else {
                     $arr[] = $to['address'];
                 }
             }
         }
         if (count($arr) > 0) {
             $to = implode(', ', $arr);
             $header['client'][] = 'To: ' . implode(', ' . MIME5::LE . "\t", $arr);
         } else {
             FUNC5::trace($debug, 'to mail address is not set');
         }
         if (count($this->Cc) > 0) {
             $arr = array();
             foreach ($this->Cc as $cc) {
                 if (isset($cc['address']) && FUNC5::is_mail($cc['address'], false, $debug)) {
                     $addrs[] = $cc['address'];
                     if (isset($cc['name'])) {
                         $hn = MIME5::encode_header($cc['name'], isset($cc['charset']) ? $cc['charset'] : null, isset($cc['encoding']) ? $cc['encoding'] : null, null, null, $debug);
                         if ($hn == $cc['name']) {
                             $hn = '"' . str_replace('"', '\\"', $cc['name']) . '"';
                         }
                         $arr[] = $hn . ' <' . $cc['address'] . '>';
                     } else {
                         $arr[] = $cc['address'];
                     }
                 }
             }
             if (count($arr) > 0) {
                 $header['local'][] = 'Cc: ' . implode(', ', $arr);
                 $header['client'][] = 'Cc: ' . implode(', ' . MIME5::LE . "\t", $arr);
             }
         }
         $hbcc = '';
         if (count($this->Bcc) > 0) {
             $arr = array();
             foreach ($this->Bcc as $bcc) {
                 if (FUNC5::is_mail($bcc, false, $debug)) {
                     $arr[] = $bcc;
                     $addrs[] = $bcc;
                 }
             }
             if (count($arr) > 0) {
                 $header['local'][] = 'Bcc: ' . implode(', ', $arr);
                 $hbcc = MIME5::LE . 'Bcc: ' . implode(', ', $arr);
             }
         }
         $hn = MIME5::encode_header($this->Subject['content'], isset($this->Subject['charset']) ? $this->Subject['charset'] : null, isset($this->Subject['encoding']) ? $this->Subject['encoding'] : null, null, null, $debug);
         $subject = $hn;
         $header['client'][] = 'Subject: ' . $hn;
         if (is_int($this->Priority) || is_string($this->Priority)) {
             $arr = false;
             if ($this->Priority == 1 || $this->Priority == 'high') {
                 $arr = array(1, 'high');
             } else {
                 if ($this->Priority == 3 || $this->Priority == 'normal') {
                     $arr = array(3, 'normal');
                 } else {
                     if ($this->Priority == 5 || $this->Priority == 'low') {
                         $arr = array(5, 'low');
                     }
                 }
             }
             if ($arr) {
                 $header['local'][] = 'X-Priority: ' . $arr[0];
                 $header['local'][] = 'X-MSMail-Priority: ' . $arr[1];
                 $header['client'][] = 'X-Priority: ' . $arr[0];
                 $header['client'][] = 'X-MSMail-Priority: ' . $arr[1];
             }
         }
         $header['client'][] = 'Message-Id: <' . MIME5::unique() . '@xpertmailer.com>';
         if (count($this->Header) > 0) {
             foreach ($this->Header as $harr) {
                 if (isset($harr['name'], $harr['value']) && strlen($harr['name']) >= 2 && FUNC5::is_alpha($harr['name'], true, '-')) {
                     $hn = MIME5::encode_header($harr['value'], isset($harr['charset']) ? $harr['charset'] : null, isset($harr['encoding']) ? $harr['encoding'] : null, null, null, $debug);
                     $header['local'][] = ucfirst($harr['name']) . ': ' . $hn;
                     $header['client'][] = ucfirst($harr['name']) . ': ' . $hn;
                 }
             }
         }
         $text = $html = $att = null;
         if (isset($this->Text['content'])) {
             $text = MIME5::message($this->Text['content'], 'text/plain', null, isset($this->Text['charset']) ? $this->Text['charset'] : null, isset($this->Text['encoding']) ? $this->Text['encoding'] : null, null, null, null, null, $debug);
         }
         if (isset($this->Html['content'])) {
             $html = MIME5::message($this->Html['content'], 'text/html', null, isset($this->Html['charset']) ? $this->Html['charset'] : null, isset($this->Html['encoding']) ? $this->Html['encoding'] : null, null, null, null, null, $debug);
         }
         if (count($this->Attach) > 0) {
             $att = array();
             foreach ($this->Attach as $attach) {
                 if (isset($attach['content'])) {
                     $att[] = MIME5::message($attach['content'], isset($attach['type']) ? $attach['type'] : null, isset($attach['name']) ? $attach['name'] : null, isset($attach['charset']) ? $attach['charset'] : null, isset($attach['encoding']) ? $attach['encoding'] : null, isset($attach['disposition']) ? $attach['disposition'] : null, isset($attach['id']) ? $attach['id'] : null, null, null, $debug);
                 }
             }
             if (count($att) == 0) {
                 $att = null;
             }
         }
         $arr = MIME5::compose($text, $html, $att);
         if ($delivery == 'relay') {
             $res = SMTP5::send($resc, $addrs, implode(MIME5::LE, $header['client']) . MIME5::LE . $arr['header'] . MIME5::LE . MIME5::LE . $arr['content'], $this->Path != null ? $this->Path : $from, $debug);
             return $this->_result($_RESULT, $res);
         } else {
             if ($delivery == 'local') {
                 $rpath = !FUNC5::is_win() && $this->Path != null ? '-f ' . $this->Path : null;
                 $spath = $this->Path != null ? @ini_set('sendmail_from', $this->Path) : false;
                 $res = mail($to, $subject, $arr['content'], implode(MIME5::LE, $header['local']) . MIME5::LE . $arr['header'], $rpath);
                 if ($spath) {
                     @ini_restore('sendmail_from');
                 }
                 return $this->_result(array(0 => 'send mail local'), $res);
             } else {
                 if ($delivery == 'client') {
                     $group = array();
                     foreach ($addrs as $addr) {
                         $exp = explode('@', $addr);
                         $group[strtolower($exp[1])][] = $addr;
                     }
                     $ret = true;
                     $reg = count($group) == 1;
                     foreach ($group as $domain => $arrs) {
                         $con = SMTP5::mxconnect($domain, $this->Port, $this->Tout, $this->Name, $this->Context, $debug);
                         if ($reg) {
                             $this->_result(array($domain => $_RESULT));
                         }
                         if ($con) {
                             if (!SMTP5::send($con, $arrs, implode(MIME5::LE, $header['client']) . MIME5::LE . $arr['header'] . MIME5::LE . MIME5::LE . $arr['content'], $this->Path != null ? $this->Path : $from, $debug)) {
                                 $ret = false;
                             }
                             if ($reg) {
                                 $this->_result(array($domain => $_RESULT));
                             }
                             SMTP5::disconnect($con, $debug);
                         } else {
                             $ret = false;
                         }
                     }
                     if (!$reg) {
                         $this->_result(array(0 => 'send mail client'));
                     }
                     return $ret;
                 } else {
                     if ($delivery == 'sendmail' || $delivery == 'qmail') {
                         $ret = false;
                         $comm = ($delivery == 'sendmail' ? $this->SendMail : $this->QMail) . ' -oi' . ($this->Path != null ? ' -f ' . $this->Path : '') . ' -t';
                         if ($con = popen($comm, 'w')) {
                             if (fputs($con, implode(MIME5::LE, $header['client']) . $hbcc . MIME5::LE . $arr['header'] . MIME5::LE . MIME5::LE . $arr['content'])) {
                                 $res = pclose($con) >> 8 & 0xff;
                                 if ($res == 0) {
                                     $ret = true;
                                     $this->_result(array(0 => 'send mail using "' . ucfirst($delivery) . '" program'));
                                 } else {
                                     $this->_result(array(0 => $res));
                                 }
                             } else {
                                 $this->_result(array(0 => 'can not write'));
                             }
                         } else {
                             $this->_result(array(0 => 'can not write line command'));
                         }
                         return $ret;
                     }
                 }
             }
         }
     }
 }
示例#2
0
 public static function puidl($conn = null, $msg = null, $debug = null)
 {
     if (!FUNC5::is_debug($debug)) {
         $debug = debug_backtrace();
     }
     global $_RESULT;
     $_RESULT = array();
     $err = array();
     if (!is_resource($conn)) {
         $err[] = 'invalid resource connection';
     }
     if ($msg == null) {
         $msg = 0;
     }
     if (!(is_int($msg) && $msg >= 0)) {
         $err[] = 'invalid message number';
     }
     if (count($err) > 0) {
         FUNC5::trace($debug, implode(', ', $err));
     } else {
         $ret = false;
         $num = $msg > 0 ? true : false;
         if (!fwrite($conn, 'UIDL' . ($num ? ' ' . $msg : '') . self::CRLF)) {
             $_RESULT[440] = 'can not write';
         } else {
             if (!self::_ok($conn, $resp, $debug)) {
                 $_RESULT[441] = $resp;
             } else {
                 if ($num) {
                     if (count($exp = explode(' ', substr($resp[0], 4, -strlen(self::CRLF)))) == 2) {
                         $val1 = intval($exp[0]);
                         $val2 = trim($exp[1]);
                         if (strval($val1) === $exp[0] && $val2 != '') {
                             $ret = array($val1 => $val2);
                             $_RESULT[444] = $resp;
                         } else {
                             $_RESULT[443] = $resp;
                         }
                     } else {
                         $_RESULT[442] = $resp;
                     }
                 } else {
                     do {
                         if ($res = fgets($conn, self::BLEN)) {
                             if (count($exp = explode(' ', substr($res, 0, -strlen(self::CRLF)))) == 2) {
                                 $val1 = intval($exp[0]);
                                 $val2 = trim($exp[1]);
                                 if (strval($val1) === $exp[0] && $val2 != '') {
                                     $ret[$val1] = $val2;
                                     $_RESULT[446] = $resp;
                                 }
                             } else {
                                 if ($res[0] != '.') {
                                     $_RESULT[445] = $res;
                                     $ret = false;
                                     break;
                                 }
                             }
                         } else {
                             $_RESULT[434] = 'can not read';
                             $ret = false;
                             break;
                         }
                     } while ($res[0] != '.');
                 }
             }
         }
         return $ret;
     }
 }
示例#3
0
文件: SMTP5.php 项目: voitto/dbscript
 public static function recv($conn = null, $code1 = null, $code2 = null, $debug = null)
 {
     if (!FUNC5::is_debug($debug)) {
         $debug = debug_backtrace();
     }
     global $_RESULT;
     $_RESULT = array();
     $ret = false;
     if (!self::_cres($conn, $resp, $code1, $code2, $debug)) {
         $_RESULT[335] = $resp;
     } else {
         $_RESULT[336] = $resp;
         $ret = true;
     }
     return $ret;
 }
示例#4
0
 function test_connection($pop3fetcher_username, $pop3fetcher_password, $pop3fetcher_serveraddress, $pop3fetcher_serverport, $pop3fetcher_ssl)
 {
     define('DISPLAY_XPM4_ERRORS', false);
     // display XPM4 errors
     require_once './plugins/pop3fetcher/XPM4/POP35.php';
     require_once './plugins/pop3fetcher/XPM4/FUNC5.php';
     $pop3fetcher_serverport = intval($pop3fetcher_serverport);
     if ($this->config["debug"]) {
         write_log("pop3fetcher.txt", "TESTING CONNECTION: {$pop3fetcher_username}, {$pop3fetcher_password}, {$pop3fetcher_serveraddress}, {$pop3fetcher_serverport}, {$pop3fetcher_ssl}");
     }
     if ($pop3fetcher_serverport > 0 && FUNC5::is_hostname($pop3fetcher_serveraddress, true)) {
         $c = POP35::connect($pop3fetcher_serveraddress, $pop3fetcher_username, $pop3fetcher_password, $pop3fetcher_serverport, $pop3fetcher_ssl, 100, NULL, false);
         if ($c) {
             if ($this->config["debug"]) {
                 write_log("pop3fetcher.txt", "TESTING CONNECTION: SUCCESS {$pop3fetcher_serveraddress}:{$pop3fetcher_serverport}");
             }
             POP35::disconnect($c, false);
             return true;
         } else {
             if ($this->config["debug"]) {
                 write_log("pop3fetcher.txt", "TESTING CONNECTION: FAIL {$pop3fetcher_serveraddress}:{$pop3fetcher_serverport}");
             }
             return false;
         }
     } else {
         if ($this->config["debug"]) {
             write_log("pop3fetcher.txt", "TESTING CONNECTION: FAIL {$pop3fetcher_serveraddress}:{$pop3fetcher_serverport}");
         }
         return false;
     }
 }
示例#5
0
 public static function fix_eol($str = null, $debug = null)
 {
     if (!FUNC5::is_debug($debug)) {
         $debug = debug_backtrace();
     }
     if (!(is_string($str) && $str != '')) {
         FUNC5::trace($debug, 'invalid content value');
     } else {
         $str = str_replace("\r\n", "\n", $str);
         $str = str_replace("\r", "\n", $str);
         if (self::LE != "\n") {
             $str = str_replace("\n", self::LE, $str);
         }
         return $str;
     }
 }