View file getmail.php

File size: 14.29Kb
<?
Error_Reporting(E_ALL & ~E_NOTICE);

$email[user]='mail@list.ru';
$email[pass]='password';
$email[server]='pop.list.ru';
$email[port]=110;

include'includes/a.charset.php';

function validate($s) 
{
$s = str_replace ('$', '$$', $s);
$s = str_replace (' ', '', $s);
$s = str_replace ('Admin', 'ya-looser', $s);
$s = str_replace ('admin', 'ya-looser', $s);
$s = str_replace ('blya', 'ya-looser', $s);
$s = str_replace ('Blya', 'ya-looser', $s);
$s = str_replace ('pizd', 'ya-looser', $s);
$s = str_replace ('Pizd', 'ya-looser', $s);
$s = str_replace ('eba', 'ya-looser', $s);
$s = str_replace ('Eba', 'ya-looser', $s);
$s = str_replace ('ebu', 'ya-looser', $s);
$s = str_replace ('Ebu', 'ya-looser', $s);
$s = str_replace ('pidor', 'ya-looser', $s);
$s = str_replace ('Pidor', 'ya-looser', $s);
$s = str_replace ('mudak', 'ya-looser', $s);
$s = str_replace ('Mudak', 'ya-looser', $s);
$s = str_replace ('Huj', 'ya-looser', $s);
$s = str_replace ('huj', 'ya-looser', $s);
$s = str_replace ('Xyu', 'ya-looser', $s);
$s = str_replace ('xyu', 'ya-looser', $s);
$s = str_replace ('Xyj', 'ya-looser', $s);
$s = str_replace ('Xyj', 'ya-looser', $s);
$s = str_replace ('chat', 'ya-looser', $s);
$s = addslashes ($s);
$s= htmlspecialchars($s,ENT_NOQUOTES );
$s=trim($s);
$s = str_replace ('&', '', $s);
return $s;
}

function mailtime($timeStamp) {
	return date("m.d.Y H:i:s", $timeStamp);
}
function uc($s)
{
$tr = array(
"Ђ"=>"A"," "=>"a","Ѓ"=>"Р‘","Ў"=>"Р±","‚"=>"B",
"ў"=>"РІ","ѓ"=>"Р“","Ј"=>"Рі","„"=>"Р”","¤"=>"Рґ",
"…"=>"E","Ґ"=>"e","р"=>"РЃ","†"=>"Р–","¦"=>"Р¶",
"‡"=>"3","§"=>"Р·","€"=>"Р?","Ё"=>"Рё","‰"=>"Р™",
"©"=>"Р№","Љ"=>"K","Є"=>"Рє","‹"=>"Р›","«"=>"Р»",
"Њ"=>"M","¬"=>"Рј","Ќ"=>"H","­"=>"РЅ","Ћ"=>"O",
"®"=>"Рѕ","Џ"=>"Рџ","Ї"=>"Рї","ђ"=>"P","а"=>"p",
"‘"=>"C","б"=>"c","’"=>"Рў","в"=>"С‚","“"=>"РЈ",
"г"=>"y","”"=>"Р¤","д"=>"С„","•"=>"X","е"=>"x",
"–"=>"Р¦","ж"=>"С†","—"=>"Р§","з"=>"С‡",
"и"=>"С€","™"=>"Р©","й"=>"С‰","љ"=>"РЄ","к"=>"СЉ",
"›"=>"Р«","л"=>"С‹","њ"=>"Р¬","м"=>"СЊ","ќ"=>"Р­",
"н"=>"СЌ","ћ"=>"Р®","о"=>"СЋ","џ"=>"РЇ","п"=>"СЏ",
"с"=>"С‘","ь"=>"в„–","?"=>"РЁ"
);
return strtr(convert_cyr_string(charset_x_win($s), "w", "a"),$tr);
}

function uc2($s)
{
$tr = array(
"Ђ"=>"A"," "=>"a","Ѓ"=>"Р‘","Ў"=>"Р±","‚"=>"B",
"ў"=>"РІ","ѓ"=>"Р“","Ј"=>"Рі","„"=>"Р”","¤"=>"Рґ",
"…"=>"E","Ґ"=>"e","р"=>"РЃ","†"=>"Р–","¦"=>"Р¶",
"‡"=>"3","§"=>"Р·","€"=>"Р?","Ё"=>"Рё","‰"=>"Р™",
"©"=>"Р№","Љ"=>"K","Є"=>"Рє","‹"=>"Р›","«"=>"Р»",
"Њ"=>"M","¬"=>"Рј","Ќ"=>"H","­"=>"РЅ","Ћ"=>"O",
"®"=>"Рѕ","Џ"=>"Рџ","Ї"=>"Рї","ђ"=>"P","а"=>"p",
"‘"=>"C","б"=>"c","’"=>"Рў","в"=>"С‚","“"=>"РЈ",
"г"=>"y","”"=>"Р¤","д"=>"С„","•"=>"X","е"=>"x",
"–"=>"Р¦","ж"=>"С†","—"=>"Р§","з"=>"С‡",
"и"=>"С€","™"=>"Р©","й"=>"С‰","љ"=>"РЄ","к"=>"СЉ",
"›"=>"Р«","л"=>"С‹","њ"=>"Р¬","м"=>"СЊ","ќ"=>"Р­",
"н"=>"СЌ","ћ"=>"Р®","о"=>"СЋ","џ"=>"РЇ","п"=>"СЏ",
"с"=>"С‘","ь"=>"в„–","?"=>"РЁ"
);
return strtr(convert_cyr_string($s, "w", "a"),$tr);
}

function getHeaders($headerArray) {
	for ($i = 0; $i < sizeof($headerArray); $i++) {
		$parts = explode(": ", $headerArray[$i], 2);
		$headers[strtolower($parts[0])] = $parts[1];
	}

	return $headers;
}
function getSender($sender) {
	$senderParts["name"] = $sender;

	if (($pos = strrpos($sender, "<")) && substr($sender, -1) == ">") {
		$senderParts["name"] = substr($sender, 0, $pos - 1);
		$senderParts["email"] = substr($sender, $pos);
	}

	$firstChar = substr($senderParts["name"], 0, 1);
	$lastChar = substr($senderParts["name"], -1);
	if ($firstChar == "\"" || $firstChar == "'") $senderParts["name"] = substr($senderParts["name"], 1);
	if ($lastChar == "\"" || $lastChar == "'") $senderParts["name"] = substr($senderParts["name"], 0, -1);

	return $senderParts;
}
function mimeHeaderDecode($string) {
	if (strstr($string, "=?")) {
		$explode = explode("=?", $string);
		$newString = $explode[0];
		for ($i = 1; $i < sizeof($explode); $i++) {
			$explode2 = explode("?", $explode[$i]);

			$newString .= (strtolower($explode2[1]) == "q") ? quoted_printable_decode($explode2[2]) : base64_decode($explode2[2]);
			$newString .= substr($explode2[3], 1);
		}
	}
	else return $string;

	return $newString;
}
function removeLineBreaks($string) {
	return strtr($string, "\r\n", "  ");
}
function getLine() {
	global $fp;
	return substr(fgets($fp, 1024), 0, -2);
}
function command($command) {
	global $fp;

	fwrite($fp, removeLineBreaks($command)."\r\n");
	if (substr($line = getLine(), 0, 1) != "+") return false;

	return $line;
}
function headerInfo($string) {
	$lookingFor = array("contentType" => "Content-Type: ", "boundary" => "boundary=", "charSet" => "charset=", "name" => "name=", "contentTransferEncoding" => "Content-Transfer-Encoding: ", "contentDisposition" => "Content-Disposition: ", "fileName" => "filename=");
	$getValue = "[\"']?([^\"';\r]+)";

	reset($lookingFor);
	while (list($key, $value) = each($lookingFor)) {
		ereg("$value$getValue", $string, $matches);
		$info[$key] = $matches[1];

		unset($matches);
	}

	return $info;
}
function showInLine($contentType, $showImagesInLine = true) {
	$returnValue = false;

	$category = substr($contentType, 0, strpos($contentType, "/"));
	if ($category == "text" || $category == "message") $returnValue = true;

	if ($showImagesInLine) {
		$inLineImages = array("image/png", "image/jpeg", "image/gif");
		if (in_array($contentType, $inLineImages)) $returnValue = true;
	}

	return $returnValue;
}

$fp = fsockopen($email[server], $email[port], $errorNumber, $errorMessage, 25);
getLine();
		command("USER $email[user]");
		command("PASS $email[pass]");

if(empty($a))
            {
include'ini.php';            
include'includes/header.php';

$p=validate($p);
$id=intval($id);
$dbid=intval($_GET['dbid']);
$room=intval($room);

list($login,$id,$pass,$level,$kicked,$kicktime,$mrooms)=mysql_fetch_array(mysql_query("select login,id,pass,level,kicked,kicktime,mrooms from users where id='".$id."';"));
if($pass!=$p || empty($id) || empty($p))die('<card title="Error!"><p><small>'.$lang['incorrect_pass_id'].'<br/><anchor>'.$lang['back'].'<prev/></anchor></small></p></card></wml>');

if($level<7) die('<card title="Error!"><p><small>'.$lang['denied'].'</small></p></card></wml>');

echo'<card title="foto"><p><small><b>'.$email[user].'</b><br/>---<br/>';
$numMessages = command("STAT");
$numMessages = explode(" ", $numMessages);
$numMessages = $numMessages[1];

if(!empty($del)) 
{
$del=intval($del);
command("DELE $del\r\n");
command("QUIT\r\n");
echo uc2("Письмо удалено!<br/>");
echo uc2('---<br/><a href="c.php?id='.$id.'&amp;lg='.$lg.'&amp;p='.$p.'&amp;room='.$room.'">Обратно в чат</a>');
print "</small></p></card></wml>";
exit;
}
else

if ($numMessages == 0) {
	echo uc2("Нет писем<br/>");
}

for ($i = $numMessages; $i >= 1; $i--) {
	command("TOP $i 0");

	while (($headerArray[] = getLine()) != ".")

	$headers = getHeaders($headerArray);

	$subject = (!empty($headers["subject"])) ? htmlspecialchars(mimeHeaderDecode($headers["subject"])) : uc2("[no subject]");

	$sender = getSender($headers["from"]);
	$xsender = mimeHeaderDecode($headers["reply-to"]);
    $sender = (!empty($xsender) ? mimeHeaderDecode($headers["reply-to"]) : $sender["name"]);
	echo uc('<a href="'.$SCRIPT_NAME.'?a=1&amp;id='.$i.'&amp;uid='.$id.'&amp;lg='.$lg.'&amp;p='.$p.'&amp;room='.$room.'">'.$subject.'</a>');
	echo uc2(' от ');
	echo uc("<b>".htmlspecialchars($sender)."</b>");
	echo uc("(".mailtime(strtotime($headers["date"])).")<a href=\"$SCRIPT_NAME?del=$i&amp;id=$id&amp;lg=$lg&amp;p=$p&amp;room=$room\">[del]</a><br/>");
	unset($headerArray);
}
echo uc2('---<br/><a href="c.php?id='.$id.'&amp;lg='.$lg.'&amp;p='.$p.'&amp;room='.$room.'">Обратно в чат</a>');
print "</small></p></card></wml>";
}
elseif($a==1)
{
include'ini.php';            
include'includes/header.php';

$p=validate($p);
$uid=intval($uid);
$dbid=intval($_GET['dbid']);
$room=intval($room);

list($login,$uid,$pass,$level,$kicked,$kicktime,$mrooms)=mysql_fetch_array(mysql_query("select login,id,pass,level,kicked,kicktime,mrooms from users where id='".$uid."';"));
if($pass!=$p || empty($uid) || empty($p))die('<card title="Error!"><p><small>'.$lang['incorrect_pass_id'].'<br/><anchor>'.$lang['back'].'<prev/></anchor></small></p></card></wml>');

if($level<7) die('<card title="Error!"><p><small>'.$lang['denied'].'</small></p></card></wml>');

echo'<card title="foto"><p><small>';
function showBody($body) {
	global $formatText;

	$body = nl2br(htmlspecialchars($body));
	$body = str_replace("  ", "&nbsp;&nbsp;", $body);
	$body = str_replace("\t", "&nbsp;&nbsp;&nbsp;&nbsp;", $body);

	if ($formatText) {
		# Making bold text out of *text*:
		$body = eregi_replace(" \*([a-z0-9]+[^*]*[a-z0-9]+)\*", " <b>\\1</b>", $body);
		# Making italic text out of /text/:
		$body = eregi_replace(" /([a-z0-9]+[^/]*[a-z0-9]+)/", " <i>\\1</i>", $body);
		# Making underlined text out of _text_:
		$body = eregi_replace(" _([a-z0-9]+[^_]*[a-z0-9]+)_", " <u>\\1</u>", $body);
	}

	# Yes, the top level domain can indeed be up to 6 characters
	# long (".museum").
	$body = eregi_replace("([a-z0-9._-]+@[a-z0-9.-]+\.[a-z]{2,6})", "<u>\\1</u>", $body);

	$body = eregi_replace("((f|ht)tps?://[^ \r]*[^ \r,.:!?)])", "<a href=\"\\1\">\\1</a>", $body);

	return $body;
}
command("RETR $id");
		
		while (($headerArray[] = getLine()) != "")

$headers = getHeaders($headerArray);

$subject = htmlspecialchars(mimeHeaderDecode($headers["subject"]));
if(empty($subject)) $subject=uc2('[no subject]');

$date = strtotime($headers["date"]);

$sender = getSender($headers["from"]);
$sender = (isset($sender["email"])) ? $sender["name"]." ".$sender["email"] : $sender["name"];
$sender = htmlspecialchars(mimeHeaderDecode($sender));

$recipient = getSender($headers["to"]);
$recipient = (isset($recipient["email"])) ? $recipient["name"]." ".$recipient["email"] : $recipient["name"];
$recipient = htmlspecialchars(mimeHeaderDecode($recipient));

if (isset($headers["user-agent"])) $userAgent = $headers["user-agent"];
if (isset($headers["x-mailer"])) $userAgent = $headers["x-mailer"];
if (isset($headers["x-newsreader"])) $userAgent = $headers["x-newsreader"];


echo uc2("<b>Тема:</b>"); echo uc("$subject<br/>");
echo uc2("<b>Дата:</b>"); echo mailtime($date).'<br/>';
echo uc2("<b>Отправитель:</b>"); echo uc(htmlspecialchars(mimeHeaderDecode($headers["reply-to"]))).'<br/>';

$partInfo[1]["headers"] = headerInfo(implode("\r\n", $headerArray));
while (($line = getLine()) != ".") $partInfo[1]["body"] .= "$line\r\n";

if (isset($partInfo[1]["headers"]["boundary"])) {


	$parts = explode("--".$partInfo[1]["headers"]["boundary"], $partInfo[1]["body"]);
	$loopUpTo = sizeof($parts) - 1;
	for ($i = 1; $i < $loopUpTo; $i++) {
		$pos = strpos($parts[$i], "\r\n\r\n");
		$partInfo[$i]["headers"] = headerInfo(substr($parts[$i], 2, $pos - 2));
		$partInfo[$i]["body"] = substr($parts[$i], $pos + 4);

		if ($i > 1) {
			$inLine = (showInLine($partInfo[$i]["headers"]["contentType"])) ? "true" : "false";

			if (isset($partInfo[$i]["headers"]["fileName"])) $partInfo[$i]["attachmentName"] = $partInfo[$i]["headers"]["fileName"];
			if (isset($partInfo[$i]["headers"]["name"])) $partInfo[$i]["attachmentName"] = $partInfo[$i]["headers"]["name"];
			else $partInfo[$i]["attachmentName"] = uc2("[filename unknown]");
			
			$body = $partInfo[$i]["body"];
if ($partInfo[$i]["headers"]["contentType"] != "text/html") $body = showBody($body);

//print (strlen($partInfo[$i]["body"])/1024);

$format=explode('/',$partInfo[$i]["headers"]["contentType"]);
if($format[1]=='jpeg') $format[1]='jpg';
$formats=array('jpg','gif','png');
if(in_array($format[1],$formats)) $format[1]='jpg';
//{
$fname='temp/'.time().'.'.$format[1];
$fp=fopen($fname,"w");
fputs($fp, base64_decode(htmlspecialchars($partInfo[$i]["body"])));        
fclose($fp);
@chmod($fname, 0644);
$size=round((filesize($fname)/1024),1);
echo uc2("<a href=\"$fname\">Прикрепленный файл</a>($size kb)<br/>");
echo uc2("<a href=\"$SCRIPT_NAME?a=2&amp;accept=$fname&amp;uid=$uid&amp;lg=$lg&amp;p=$p&amp;room=$room\">Одобрить...</a><br/>");
//}
//else echo uc2("<b><u>Внимание!</u></b> Прикрепленный файл не является изображением! Процедура декодирования содержимого отклонена!<br/>");
}
}
}
else echo uc2("<b><u>Внимание!</u></b> Письмо не содержит прикрепленных файлов!<br/>");
//echo base64_decode($body);
echo htmlspecialchars(stripslashes(uc($partInfo[1]["body"])));
echo uc2('<br/>---<br/><a href="c.php?id='.$uid.'&amp;lg='.$lg.'&amp;p='.$p.'&amp;room='.$room.'">Обратно в чат</a>');
print "</small></p></card></wml>";
}
elseif($a==2)
{
include'ini.php';            
include'includes/header.php';

$p=validate($p);
$uid=intval($uid);
$dbid=intval($_GET['dbid']);
$room=intval($room);

list($login,$uid,$pass,$level,$kicked,$kicktime,$mrooms)=mysql_fetch_array(mysql_query("select login,id,pass,level,kicked,kicktime,mrooms from users where id='".$uid."';"));
if($pass!=$p || empty($uid) || empty($p))die('<card title="Error!"><p><small>'.$lang['incorrect_pass_id'].'<br/><anchor>'.$lang['back'].'<prev/></anchor></small></p></card></wml>');

if($level<7) die('<card title="Error!"><p><small>'.$lang['denied'].'</small></p></card></wml>');

echo'<card title="add foto"><p><small>';
if(!file_exists($accept)) die(uc2('файл не существует! попробуйте открыть заново письмо</small></p></card></wml>'));
if(!isset($add))
{
echo uc2('Ник юзера:');
echo'<br/></small><input name="nick" maxlength="50"/><br/>';
echo'<small><anchor>go<go href="'.$SCRIPT_NAME.'?a=2&amp;accept='.$accept.'&amp;add&amp;uid='.$uid.'&amp;lg='.$lg.'&amp;p='.$p.'&amp;room='.$room.'" method="post"><postfield name="nick" value="$(nick)"/></go></anchor><br/>';
}
else
{
$formats=array('jpg','gif','png');
$fname=basename($accept);
$format=explode('.',$fname);
//if(!in_array($format[1],$formats)) die(uc2('неизвестная ошибка</small></p></card></wml>'));
rename($accept,'foto/'.$fname);
@chmod('foto/'.$fname, 0644);
list($old_foto)=mysql_fetch_array(mysql_query("select foto from users where login='".validate($nick)."';"));
@unlink($old_foto);
mysql_query("update users set foto='foto/".$fname."' where login='".validate($nick)."';");
echo uc2('Сделано!<br/>');
}
echo uc2('---<br/><a href="c.php?id='.$uid.'&amp;lg='.$lg.'&amp;p='.$p.'&amp;room='.$room.'">Обратно в чат</a>');
print "</small></p></card></wml>";
}
?>