public function attach($content = null, $type = null, $name = null, $charset = null, $encoding = null, $disposition = null, $id = null, $debug = null) { if (!FUNC5::is_debug($debug)) { $debug = debug_backtrace(); } $err = array(); if (!(is_string($content) && $content != '')) { $err[] = 'invalid content type'; } if ($type != null) { if (!is_string($type)) { $err[] = 'invalid type value'; } else { $type = trim(FUNC5::str_clear($type)); if (strlen($type) < 4) { $err[] = 'invalid type value'; } } } if ($name != null) { if (!is_string($name)) { $err[] = 'invalid name type'; } else { $name = trim(FUNC5::str_clear($name)); if ($name == '') { $err[] = 'invalid name value'; } } } if ($charset != null) { if (!is_string($charset)) { $err[] = 'invalid charset type'; } else { if (!(strlen($charset) >= 2 && FUNC5::is_alpha($charset, true, '-'))) { $err[] = 'invalid charset value'; } } } if ($encoding == null) { $encoding = 'base64'; } else { if (is_string($encoding)) { $encoding = strtolower($encoding); if (!isset(MIME5::$mencarr[$encoding])) { $err[] = 'invalid encoding value'; } } else { $err[] = 'invalid encoding type'; } } if ($disposition == null) { $disposition = 'attachment'; } else { if (is_string($disposition)) { $disposition = strtolower(FUNC5::str_clear($disposition)); if (!($disposition == 'inline' || $disposition == 'attachment')) { $err[] = 'invalid disposition value'; } } else { $err[] = 'invalid disposition type'; } } if ($id != null) { if (!is_string($id)) { $err[] = 'invalid id type'; } else { $id = FUNC5::str_clear($id, array(' ')); if ($id == '') { $err[] = 'invalid id value'; } } } if (count($err) > 0) { FUNC5::trace($debug, implode(', ', $err)); } else { $this->Attach[] = array('content' => $content, 'type' => $type, 'name' => $name, 'charset' => $charset, 'encoding' => $encoding, 'disposition' => $disposition, 'id' => $id); return $this->_result(array(0 => 'add attachment'), true); } }
public static function auth($conn = null, $user = null, $pass = null, $type = null, $debug = null) { if (!FUNC5::is_debug($debug)) { $debug = debug_backtrace(); } global $_RESULT; $_RESULT = $err = array(); if (!is_resource($conn)) { $err[] = 'invalid resource connection'; } if (!is_string($user)) { $err[] = 'invalid username type'; } else { if (($user = FUNC5::str_clear($user)) == '') { $err[] = 'invalid username value'; } } if (!is_string($pass)) { $err[] = 'invalid password type'; } else { if (($pass = FUNC5::str_clear($pass)) == '') { $err[] = 'invalid password value'; } } if ($type == null) { $type = 'login'; } if (!is_string($type)) { $err[] = 'invalid authentication type'; } else { $type = strtolower(trim($type)); if (!($type == 'login' || $type == 'plain' || $type == 'cram-md5')) { $err[] = 'invalid authentication type value'; } } if (count($err) > 0) { FUNC5::trace($debug, implode(', ', $err)); } else { $ret = false; if ($type == 'login') { if (!fwrite($conn, 'AUTH LOGIN' . self::CRLF)) { $_RESULT[310] = 'can not write'; } else { if (!self::_cres($conn, $resp, 334, null, $debug)) { $_RESULT[311] = $resp; } else { if (!fwrite($conn, base64_encode($user) . self::CRLF)) { $_RESULT[312] = 'can not write'; } else { if (!self::_cres($conn, $resp, 334, null, $debug)) { $_RESULT[313] = $resp; } else { if (!fwrite($conn, base64_encode($pass) . self::CRLF)) { $_RESULT[314] = 'can not write'; } else { if (!self::_cres($conn, $resp, 235, null, $debug)) { $_RESULT[315] = $resp; } else { $_RESULT[316] = $resp; $ret = true; } } } } } } } else { if ($type == 'plain') { if (!fwrite($conn, 'AUTH PLAIN ' . base64_encode($user . chr(0) . $user . chr(0) . $pass) . self::CRLF)) { $_RESULT[317] = 'can not write'; } else { if (!self::_cres($conn, $resp, 235, null, $debug)) { $_RESULT[318] = $resp; } else { $_RESULT[319] = $resp; $ret = true; } } } else { if ($type == 'cram-md5') { if (!fwrite($conn, 'AUTH CRAM-MD5' . self::CRLF)) { $_RESULT[200] = 'can not write'; } else { if (!self::_cres($conn, $resp, 334, null, $debug)) { $_RESULT[201] = $resp; } else { if (strlen($pass) > 64) { $pass = pack('H32', md5($pass)); } if (strlen($pass) < 64) { $pass = str_pad($pass, 64, chr(0)); } $pad1 = substr($pass, 0, 64) ^ str_repeat(chr(0x36), 64); $pad2 = substr($pass, 0, 64) ^ str_repeat(chr(0x5c), 64); $chal = substr($resp[count($resp) - 1], 4); $innr = pack('H32', md5($pad1 . base64_decode($chal))); if (!fwrite($conn, base64_encode($user . ' ' . md5($pad2 . $innr)) . self::CRLF)) { $_RESULT[202] = 'can not write'; } else { if (!self::_cres($conn, $resp, 235, null, $debug)) { $_RESULT[203] = $resp; } else { $_RESULT[204] = $resp; $ret = true; } } } } } } } return $ret; } }
public static function auth($conn = null, $user = null, $pass = 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 (!is_string($user)) { $err[] = 'invalid username type'; } else { if (($user = FUNC5::str_clear($user)) == '') { $err[] = 'invalid username value'; } } if (!is_string($pass)) { $err[] = 'invalid password type'; } else { if (($pass = FUNC5::str_clear($pass)) == '') { $err[] = 'invalid password value'; } } if (count($err) > 0) { FUNC5::trace($debug, implode(', ', $err)); } else { $ret = false; if (!fwrite($conn, 'USER ' . $user . self::CRLF)) { $_RESULT[404] = 'can not write'; } else { if (!self::_ok($conn, $resp, $debug)) { $_RESULT[405] = $resp; } else { if (!fwrite($conn, 'PASS ' . $pass . self::CRLF)) { $_RESULT[405] = 'can not write'; } else { if (!self::_ok($conn, $resp, $debug)) { $_RESULT[406] = $resp; } else { $_RESULT[407] = $resp; $ret = true; } } } } return $ret; } }
public static function split_header($str = null, $debug = null) { if (!FUNC5::is_debug($debug)) { $debug = debug_backtrace(); } if (!(is_string($str) && $str != '')) { FUNC5::trace($debug, 'invalid header value'); } else { $str = str_replace(array(";\r\n\t", "; \r\n\t", ";\r\n ", "; \r\n "), '; ', $str); $str = str_replace(array(";\n\t", "; \n\t", ";\n ", "; \n "), '; ', $str); $str = str_replace(array("\r\n\t", "\r\n "), '', $str); $str = str_replace(array("\n\t", "\n "), '', $str); $arr = array(); foreach (explode("\n", $str) as $line) { $line = trim(FUNC5::str_clear($line)); if ($line != '') { if (count($exp1 = explode(':', $line, 2)) == 2) { $name = rtrim($exp1[0]); $val1 = ltrim($exp1[1]); if (strlen($name) > 1 && FUNC5::is_alpha($name, true, '-') && $val1 != '') { $name = ucfirst($name); $hadd = array(); if (substr(strtolower($name), 0, 8) == 'content-') { $exp2 = explode('; ', $val1); $cnt2 = count($exp2); if ($cnt2 > 1) { for ($i = 1; $i < $cnt2; $i++) { if (count($exp3 = explode('=', $exp2[$i], 2)) == 2) { $hset = trim($exp3[0]); $hval = trim($exp3[1], ' "'); if ($hset != '' && $hval != '') { $hadd[strtolower($hset)] = $hval; } } } } } $val2 = count($hadd) > 0 ? trim($exp2[0]) : $val1; $arr[] = array('name' => $name, 'value' => $val2, 'content' => $hadd); } } } } if (count($arr) > 0) { return $arr; } else { FUNC5::trace($debug, 'invalid header value', 1); } } }