public function init($from = "", $charset = "UTF-8", $log_file = "") { if (!empty($from)) { $this->setFrom($from); } if (!empty($charset)) { $this->charset = $charset; } if (!empty($log_file)) { $this->log_fp = @fopen($log_file, "wb"); } $boundary_str = "mystep_" . Chop("b" . md5(uniqid(time()))) . "_mystep"; $this->boundary["body"] = "===Body_" . $boundary_str . "==="; $this->boundary["attach"] = "===Attach_" . $boundary_str . "==="; $this->boundary["embed"] = "===Embed_" . $boundary_str . "==="; }
function ReadReplyHeadersResponse(&$headers) { $headers = array(); if (strlen($this->error)) { return $this->error; } switch ($this->state) { case "Disconnected": return $this->SetError("1 connection was not yet established"); case "Connected": return $this->SetError("2 request was not sent"); case "ConnectedToProxy": return $this->SetError("2 connection from the remote server from the proxy was not yet established"); case "SendingRequestBody": return $this->SetError("4 request body data was not completely sent"); case "ConnectSent": $connect = 1; break; case "RequestSent": $connect = 0; break; default: return $this->SetError("3 can not get request headers in the current connection state"); } $this->content_length = $this->read_length = $this->read_response = $this->remaining_chunk = 0; $this->content_length_set = $this->chunked = $this->last_chunk_read = $chunked = 0; $this->connection_close = 0; for ($this->response_status = "";;) { $line = $this->GetLine(); if (GetType($line) != "string") { return $this->SetError("4 could not read request reply: " . $this->error); } if (strlen($this->response_status) == 0) { if (!preg_match($match = "#^http/[0-9]+\\.[0-9]+[ \t]+([0-9]+)[ \t]*(.*)\$#i", $line, $matches)) { return $this->SetError("3 it was received an unexpected HTTP response status"); } $this->response_status = $matches[1]; $this->response_message = $matches[2]; } if ($line == "") { if (strlen($this->response_status) == 0) { return $this->SetError("3 it was not received HTTP response status"); } $this->state = $connect ? "GotConnectHeaders" : "GotReplyHeaders"; break; } $header_name = strtolower($this->Tokenize($line, ":")); $header_value = Trim(Chop($this->Tokenize("\r\n"))); if (isset($headers[$header_name])) { if (GetType($headers[$header_name]) == "string") { $headers[$header_name] = array($headers[$header_name]); } $headers[$header_name][] = $header_value; } else { $headers[$header_name] = $header_value; } if (!$connect) { switch ($header_name) { case "content-length": $this->content_length = intval($headers[$header_name]); $this->content_length_set = 1; break; case "transfer-encoding": $encoding = $this->Tokenize($header_value, "; \t"); if (!$this->use_curl && !strcmp($encoding, "chunked")) { $chunked = 1; } break; case "set-cookie": if ($this->support_cookies) { if (GetType($headers[$header_name]) == "array") { $cookie_headers = $headers[$header_name]; } else { $cookie_headers = array($headers[$header_name]); } for ($cookie = 0; $cookie < count($cookie_headers); $cookie++) { $cookie_name = trim($this->Tokenize($cookie_headers[$cookie], "=")); $cookie_value = $this->Tokenize(";"); $domain = $this->request_host; $path = "/"; $expires = ""; $secure = 0; while (($name = trim(UrlDecode($this->Tokenize("=")))) != "") { $value = UrlDecode($this->Tokenize(";")); switch ($name) { case "domain": $domain = $value; break; case "path": $path = $value; break; case "expires": if (preg_match("#^((Mon|Monday|Tue|Tuesday|Wed|Wednesday|Thu|Thursday|Fri|Friday|Sat|Saturday|Sun|Sunday), )?([0-9]{2})\\-(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\\-([0-9]{2,4}) ([0-9]{2})\\:([0-9]{2})\\:([0-9]{2}) GMT\$#", $value, $matches)) { $year = intval($matches[5]); if ($year < 1900) { $year += $year < 70 ? 2000 : 1900; } $expires = "{$year}-" . $this->months[$matches[4]] . "-" . $matches[3] . " " . $matches[6] . ":" . $matches[7] . ":" . $matches[8]; } break; case "secure": $secure = 1; break; } } try { $this->SetCookie($cookie_name, $cookie_value, $expires, $path, $domain, $secure, 1); } catch (http_exception $ex) { $this->error = ""; } } } break; case "connection": $this->connection_close = !strcmp(strtolower($header_value), "close"); break; } } } $this->chunked = $chunked; if ($this->content_length_set) { $this->connection_close = 0; } return ""; }
function ReadReplyHeaders(&$headers) { $headers = array(); if (strlen($this->error)) { return $this->error; } switch ($this->state) { case "Disconnected": return $this->SetError("1 connection was not yet established"); case "Connected": return $this->SetError("2 request was not sent"); case "RequestSent": break; default: return $this->SetError("3 can not get request headers in the current connection state"); } $this->content_length = $this->read_length = $this->read_response = 0; $this->content_length_set = 0; for ($this->response_status = "";;) { $line = $this->GetLine(); if (GetType($line) != "string") { return $this->SetError("4 could not read request reply: " . $this->error); } if (strlen($this->response_status) == 0) { if (!eregi($match = "^http/[0-9]+\\.[0-9]+[ \t]+([0-9]+)", $line, $matches)) { return $this->SetError("3 it was received an unexpected HTTP response status"); } $this->response_status = $matches[1]; } if ($line == "") { if (strlen($this->response_status) == 0) { return $this->SetError("3 it was not received HTTP response status"); } $this->state = "GotReplyHeaders"; break; } $header_name = strtolower($this->Tokenize($line, ":")); $header_value = Trim(Chop($this->Tokenize("\r\n"))); if (isset($headers[$header_name])) { if (GetType($headers[$header_name]) == "string") { $headers[$header_name] = array($headers[$header_name]); } $headers[$header_name][] = $header_value; } else { $headers[$header_name] = $header_value; } switch ($header_name) { case "content-length": $this->content_length = intval($headers[$header_name]); $this->content_length_set = 1; break; case "set-cookie": if ($this->support_cookies) { if (GetType($headers[$header_name]) == "array") { $cookie_headers = $headers[$header_name]; } else { $cookie_headers = array($headers[$header_name]); } for ($cookie = 0; $cookie < count($cookie_headers); $cookie++) { $cookie_name = trim($this->Tokenize($cookie_headers[$cookie], "=")); $cookie_value = $this->Tokenize(";"); $domain = $this->request_host; $path = "/"; $expires = ""; $secure = strtolower($this->protocol) == "https"; while (($name = strtolower(trim($this->Tokenize("=")))) != "") { $value = UrlDecode($this->Tokenize(";")); switch ($name) { case "domain": if ($value == "" || !strpos($value, ".", $value[0] == ".")) { break; } $domain = strtolower($value); break; case "path": if ($value != "" && $value[0] == "/") { $path = $value; } break; case "expires": if (ereg("^((Mon|Monday|Tue|Tuesday|Wed|Wednesday|Thu|Thursday|Fri|Friday|Sat|Saturday|Sun|Sunday), )?([0-9]{2})\\-(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\\-([0-9]{2,4}) ([0-9]{2})\\:([0-9]{2})\\:([0-9]{2}) GMT\$", $value, $matches)) { $year = intval($matches[5]); if ($year < 1900) { $year += $year < 70 ? 2000 : 1900; } $expires = "{$year}-" . $this->months[$matches[4]] . "-" . $matches[3] . " " . $matches[6] . ":" . $matches[7] . ":" . $matches[8]; } break; case "secure": $secure = 1; break; } } $this->cookies[$secure][$domain][$path][$cookie_name] = array("name" => $cookie_name, "value" => $cookie_value, "domain" => $domain, "path" => $path, "expires" => $expires, "secure" => $secure); } } } } switch ($this->response_status) { case "301": case "302": case "303": case "307": if ($this->follow_redirect) { if (!isset($headers["location"]) || strlen($headers["location"]) == 0) { return $this->SetError("3 it was received a redirect without location URL"); } $location = $headers["location"]; //echo $location[0]."<br>"; if (strcmp($location[0], "/")) { $location_arguments = parse_url($location); if (!isset($location_arguments["scheme"])) { $location = dirname($this->request_uri) . "/" . $location; } } if (!strcmp($location[0], "/")) { //if(substr($location,0,1)!="/") // $location = $this->protocol . "://" . $this->host_name . ($this->host_port ? ":" . $this->host_port : "") . $location; } //echo $this->protocol."://".$this->host_name.($this->host_port ? ":".$this->host_port : "").$location; $error = $this->GetRequestArguments($location, $arguments); if (strlen($error)) { return $this->SetError("could not process redirect url: " . $error); } $arguments["RequestMethod"] = "GET"; if (strlen($error = $this->Close()) == 0 && strlen($error = $this->Open($arguments)) == 0 && strlen($error = $this->SendRequest($arguments)) == 0) { $this->redirection_level++; if ($this->redirection_level > $this->redirection_limit) { $error = "it was exceeded the limit of request redirections"; } else { $error = $this->ReadReplyHeaders($headers); } $this->redirection_level--; } $pri_cookies = $this->cookies; $_SESSION['cookies'][$this->host_name] = $pri_cookies; if (strlen($error)) { return $this->SetError($error); } } } return ""; }
function sqimap_parse_RFC822Header($read, $hdr) { $i = 0; /* Set up some defaults */ $hdr->type0 = "text"; $hdr->type1 = "plain"; $hdr->charset = "us-ascii"; $count = count($read); while ($i < $count) { /* unfold multi-line headers */ while ($i + 1 < $count && strspn($read[$i + 1], "\t ") > 0) { $read[$i + 1] = substr($read[$i], 0, -2) . ' ' . ltrim($read[$i + 1]); array_splice($read, $i, 1); $count--; } $line = $read[$i]; $c = strtolower($line[0]); switch ($c) { case 'm': $c2 = strtolower($line[1]); switch ($c2) { case 'i': if (substr($line, 0, 17) == "MIME-Version: 1.0") { $hdr->mime = true; } $i++; break; case 'e': /* MESSAGE ID */ if (strtolower(substr($line, 0, 11)) == "message-id:") { $hdr->message_id = trim(substr($line, 11)); } $i++; break; default: $i++; break; } break; case 'c': $c2 = strtolower($line[1]); switch ($c2) { case 'o': /* Content-Transfer-Encoding */ if (substr(strtolower($line), 0, 26) == "content-transfer-encoding:") { $hdr->encoding = strtolower(trim(substr($line, 26))); $i++; } else { if (strtolower(substr($line, 0, 13)) == "content-type:") { $cont = strtolower(trim(substr($line, 13))); if (strpos($cont, ";")) { $cont = substr($cont, 0, strpos($cont, ";")); } if (strpos($cont, "/")) { $hdr->type0 = substr($cont, 0, strpos($cont, "/")); $hdr->type1 = substr($cont, strpos($cont, "/") + 1); } else { $hdr->type0 = $cont; } $line = $read[$i]; $i++; while (substr(substr($read[$i], 0, strpos($read[$i], " ")), -1) != ":" && trim($read[$i]) != "" && trim($read[$i]) != ")") { str_replace("\n", "", $line); str_replace("\n", "", $read[$i]); $line = "{$line} {$read[$i]}"; $i++; } /* Detect the boundary of a multipart message */ if (eregi('boundary="([^"]+)"', $line, $regs)) { $hdr->boundary = $regs[1]; } /* Detect the charset */ if (strpos(strtolower(trim($line)), "charset=")) { $pos = strpos($line, "charset=") + 8; $charset = trim($line); if (strpos($line, ";", $pos) > 0) { $charset = substr($charset, $pos, strpos($line, ";", $pos) - $pos); } else { $charset = substr($charset, $pos); } $charset = str_replace("\"", "", $charset); $hdr->charset = $charset; } else { $hdr->charset = "us-ascii"; } /* Detect type in case of multipart/related */ if (strpos(strtolower(trim($line)), "type=")) { $pos = strpos($line, "type=") + 6; $type = trim($line); if (strpos($line, ";", $pos) > 0) { $type = substr($type, $pos, strpos($line, ";", $pos) - $pos); } else { $type = substr($type, $pos); } $hdr->type = $type; } } else { if (strtolower(substr($line, 0, 20)) == "content-disposition:") { /* Add better content-disposition support */ $i++; while (substr(substr($read[$i], 0, strpos($read[$i], " ")), -1) != ":" && trim($read[$i]) != "" && trim($read[$i]) != ")") { str_replace("\n", "", $line); str_replace("\n", "", $read[$i]); $line = "{$line} {$read[$i]}"; $i++; } /* Detects filename if any */ if (strpos(strtolower(trim($line)), "filename=")) { $pos = strpos($line, "filename=") + 9; $name = trim($line); if (strpos($line, " ", $pos) > 0) { $name = substr($name, $pos, strpos($line, " ", $pos)); } else { $name = substr($name, $pos); } $name = str_replace("\"", "", $name); $hdr->filename = $name; } } else { $i++; } } } break; case 'c': /* Cc */ if (strtolower(substr($line, 0, 3)) == "cc:") { $hdr->cc = sqimap_parse_address(trim(substr($line, 3, strlen($line) - 4)), true); } $i++; break; default: $i++; break; } break; case 'r': /* Reply-To */ if (strtolower(substr($line, 0, 9)) == "reply-to:") { $hdr->replyto = sqimap_parse_address(trim(substr($line, 9, strlen($line) - 10)), false); } $i++; break; case 'f': /* From */ if (strtolower(substr($line, 0, 5)) == "from:") { $hdr->from = sqimap_parse_address(trim(substr($line, 5, strlen($line) - 6)), false); if (!isset($hdr->replyto) || $hdr->replyto == "") { $hdr->replyto = $hdr->from; } } $i++; break; case 'd': $c2 = strtolower($line[1]); switch ($c2) { case 'a': /* Date */ if (strtolower(substr($line, 0, 5)) == "date:") { $d = substr($read[$i], 5); $d = trim($d); $d = strtr($d, array(' ' => ' ')); $d = explode(' ', $d); $hdr->date = getTimeStamp($d); } $i++; break; case 'i': /* Disposition-Notification-To */ if (strtolower(substr($line, 0, 28)) == "disposition-notification-to:") { $dnt = trim(substr($read[$i], 28)); $hdr->dnt = sqimap_parse_address($dnt, false); } $i++; break; default: $i++; break; } break; case 's': /* SUBJECT */ if (strtolower(substr($line, 0, 8)) == "subject:") { $hdr->subject = trim(substr($line, 8, strlen($line) - 9)); if (strlen(Chop($hdr->subject)) == 0) { $hdr->subject = _("(no subject)"); } } $i++; break; case 'b': /* BCC */ if (strtolower(substr($line, 0, 4)) == "bcc:") { $hdr->bcc = sqimap_parse_address(trim(substr($line, 4, strlen($line) - 5)), true); } $i++; break; case 't': /* TO */ if (strtolower(substr($line, 0, 3)) == "to:") { $hdr->to = sqimap_parse_address(trim(substr($line, 3, strlen($line) - 4)), true); } $i++; break; case ')': /* ERROR CORRECTION */ if (strlen(trim($hdr->subject)) == 0) { $hdr->subject = _("(no subject)"); } if (!is_object($hdr->from) && strlen(trim($hdr->from)) == 0) { $hdr->from = _("(unknown sender)"); } if (strlen(trim($hdr->date)) == 0) { $hdr->date = time(); } $i++; break; case 'x': /* X-PRIORITY */ if (strtolower(substr($line, 0, 11)) == 'x-priority:') { $hdr->priority = trim(substr($line, 11)); } else { if (strtolower(substr($line, 0, 9)) == 'x-mailer:') { $hdr->xmailer = trim(substr($line, 9)); } } $i++; break; case 'u': /* User-Agent */ if (strtolower(substr($line, 0, 10)) == 'user-agent') { $hdr->xmailer = trim(substr($line, 10)); } $i++; break; default: $i++; break; } } return $hdr; }
function getline($file) { $data = Chop(fgets($file, 5000)); return $data; }
function ReadReplyHeaders(&$headers) { switch ($this->state) { case 'Disconnected': return '1 connection was not yet established'; case 'Connected': return '2 request was not sent'; case 'RequestSent': break; default: return '3 can not get request headers in the current connection state'; } $headers = array(); $this->content_length = $this->read_length = 0; $this->content_length_set = 0; for (;;) { $line = $this->GetLine(); if (GetType($line) != 'string') { return '4 could not read request reply'; } if ($line == '') { $this->state = 'GotReplyHeaders'; return ''; } $header_name = strtolower(strtok($line, ':')); $header_value = Trim(Chop(strtok("\r\n"))); if (isset($headers[$header_name])) { if (GetType($headers[$header_name]) == 'string') { $headers[$header_name] = array($headers[$header_name]); } $headers[$header_name][] = $header_value; } else { $headers[$header_name] = $header_value; } switch ($header_name) { case 'content-length': $this->content_length = intval($headers[$header_name]); $this->content_length_set = 1; break; case 'set-cookie': if ($this->support_cookies) { $cookie_name = trim(strtok($headers[$header_name], '=')); $cookie_value = strtok(';'); $domain = $this->request_host; $path = '/'; $expires = ''; $secure = 0; while (($name = strtolower(trim(strtok('=')))) != '') { $value = UrlDecode(strtok(';')); switch ($name) { case 'domain': if ($value == '' || !strpos($value, '.', $value[0] == '.')) { break; } $domain = strtolower($value); break; case 'path': if ($value != '' && $value[0] == '/') { $path = $value; } break; case 'expires': if (preg_match("/^((Mon|Monday|Tue|Tuesday|Wed|Wednesday|Thu|Thursday|Fri|Friday|Sat|Saturday|Sun|Sunday), )?([0-9]{2})\\-(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\\-([0-9]{2,4}) ([0-9]{2})\\:([0-9]{2})\\:([0-9]{2}) GMT\$/i", $value, $matches)) { $year = intval($matches[5]); if ($year < 1900) { $year += $year < 70 ? 2000 : 1900; } $expires = "{$year}-" . $this->months[$matches[4]] . '-' . $matches[3] . ' ' . $matches[6] . ':' . $matches[7] . ':' . $matches[8]; } break; case 'secure': $secure = 1; break; } } $this->cookies[$secure][$domain][$path][$cookie_name] = array('name' => $cookie_name, 'value' => $cookie_value, 'domain' => $domain, 'path' => $path, 'expires' => $expires, 'secure' => $secure); } } } }
function headlines($hid = "", $block = true) { global $NPDS_Prefix; global $Version_Num, $Version_Id, $system, $rss_host_verif, $long_chain; if (file_exists("proxy.conf.php")) { include "proxy.conf.php"; } if ($hid == "") { $result = sql_query("SELECT sitename, url, headlinesurl, hid from " . $NPDS_Prefix . "headlines WHERE status=1"); } else { $result = sql_query("SELECT sitename, url, headlinesurl, hid from " . $NPDS_Prefix . "headlines WHERE hid='{$hid}' AND status=1"); } while (list($sitename, $url, $headlinesurl, $hid) = sql_fetch_row($result)) { $boxtitle = "{$sitename}"; $cache_file = "cache/{$sitename}.cache"; $cache_time = 3600; $items = 0; $max_items = 10; $rss_timeout = 15; $rss_font = "<span style=\"font-size: 10px;\">"; if (!file_exists($cache_file) or filemtime($cache_file) < time() - $cache_time or !filesize($cache_file)) { $rss = parse_url($url); if ($rss_host_verif == true) { $verif = fsockopen($rss['host'], 80, $errno, $errstr, $rss_timeout); if ($verif) { fclose($verif); $verif = true; } } else { $verif = true; } if (!$verif) { $cache_file_sec = $cache_file . ".security"; if (file_exists($cache_file)) { $ibid = rename($cache_file, $cache_file_sec); } themesidebox($boxtitle, "Security Error"); return; } else { if (isset($proxy_url[$hid])) { $fpread = fsockopen($proxy_url[$hid], $proxy_port[$hid], $errno, $errstr, $rss_timeout); fputs($fpread, "GET {$headlinesurl}/ HTTP/1.0\n\n"); } else { $fpread = fopen($headlinesurl, 'r'); } if (!$long_chain) { $long_chain = 15; } if ($fpread) { $fpwrite = fopen($cache_file, 'w'); if ($fpwrite) { fputs($fpwrite, "<ul>\n"); while (!feof($fpread)) { $buffer = ltrim(Chop(fgets($fpread, 512))); if ($buffer == "<item>" && $items < $max_items) { $title = ltrim(Chop(fgets($fpread, 256))); $link = ltrim(Chop(fgets($fpread, 256))); $title = str_replace("<title>", "", $title); $title = str_replace("</title>", "", $title); $link = str_replace("<link>", "", $link); $link = str_replace("</link>", "", $link); if (function_exists("mb_detect_encoding")) { $encoding = mb_detect_encoding($title); } else { $encoding = "UTF-8"; } $title = $look_title = iconv($encoding, cur_charset . "//TRANSLIT", $title); if ($block) { if (strlen($look_title) > $long_chain) { $title = substr($look_title, 0, $long_chain) . " ..."; } } fputs($fpwrite, "<li><a href=\"{$link}\" alt=\"{$look_title}\" title=\"{$look_title}\" target=\"_blank\">{$title}</a></li>\n"); $items++; } } fputs($fpwrite, "</ul>"); fclose($fpwrite); } fclose($fpread); } } } if (file_exists($cache_file)) { ob_start(); $ibid = readfile($cache_file); $boxstuff = $rss_font . ob_get_contents() . "</span>"; ob_end_clean(); } $boxstuff .= "<br /><div align=\"right\"><a href=\"{$url}\" target=\"_blank\"><b>" . translate("read more...") . "</b></a></div>"; if ($block) { themesidebox($boxtitle, $boxstuff); $boxstuff = ""; } else { return $boxstuff; } } }