Просмотр файла filetomail/filetomail.php

Размер файла: 15.28Kb
<?

if(!function_exists('utf_to_win')){
function utf_to_win($a){
return strtr($a,array('РЃ'=>'Ё','С‘'=>'ё','Рђ'=>'А','Р‘'=>'Б','Р’'=>'В','Р“'=>'Г','Р”'=>'Д','Р•'=>'Е','Р–'=>'Ж','Р—'=>'З','Р?'=>'И','Р™'=>'Й','Рљ'=>'К','Р›'=>'Л','Рњ'=>'М','Рќ'=>'Н','Рћ'=>'О','Рџ'=>'П','Р '=>'Р','РЎ'=>'С','Рў'=>'Т','РЈ'=>'У','Р¤'=>'Ф','РҐ'=>'Х','Р¦'=>'Ц','Р§'=>'Ч','РЁ'=>'Ш','Р©'=>'Щ','РЄ'=>'Ъ','Р«'=>'Ы','Р¬'=>'Ь','Р­'=>'Э','Р®'=>'Ю','РЇ'=>'Я','Р°'=>'а','Р±'=>'б','РІ'=>'в','Рі'=>'г','Рґ'=>'д','Рµ'=>'е','Р¶'=>'ж','Р·'=>'з','Рё'=>'и','Р№'=>'й','Рє'=>'к','Р»'=>'л','Рј'=>'м','РЅ'=>'н','Рѕ'=>'о','Рї'=>'п','СЂ'=>'р','СЃ'=>'с','С‚'=>'т','Сѓ'=>'у','С„'=>'ф','С…'=>'х','С†'=>'ц','С‡'=>'ч','С€'=>'ш','С‰'=>'щ','СЉ'=>'ъ','С‹'=>'ы','СЊ'=>'ь','СЌ'=>'э','СЋ'=>'ю','СЏ'=>'я'));}}
$Host=preg_replace('/:\d+/s','',getenv('HTTP_HOST'));
header("Cache-Control: no-cache");
header("Content-Type: text/vnd.wap.wml; charset=utf-8");
echo'<?xml version="1.0" encoding="utf-8"?><!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.3//EN" "http://www.wapforum.org/DTD/wml13.dtd"><wml>';
if(!file_exists('f'))@mkdir('f',0777);
if(!is_dir('f'))die('<card title="&#x41f;a&#x43d;e&#x43b;&#x44c; &#x43d;ac&#x442;po&#x439;&#x43a;&#x438; c&#x43a;p&#x438;&#x43f;&#x442;a"><pre>O&#x448;&#x438;&#x431;&#x43a;a!
B&#x44b; &#x43d;e co&#x437;&#x434;a&#x43b;&#x438; &#x434;&#x438;pe&#x43a;&#x442;op&#x438;&#x44e; f !
&#x414;&#x43b;&#x44f; pa&#x431;o&#x442;&#x44b; &#x44d;&#x442;o&#x433;o c&#x43a;p&#x438;&#x43f;&#x442;a &#x43d;y&#x436;&#x43d;o co&#x437;&#x434;a&#x442;&#x44c; &#x432; o&#x434;&#x43d;o&#x439; &#x434;&#x438;pe&#x43a;&#x442;op&#x438;&#x438; c &#x43d;&#x438;&#x43c; &#x434;&#x438;pe&#x43a;&#x442;op&#x438;&#x44e; f &#x434;a&#x432; e&#x439; &#x43f;pa&#x432;a 777</pre></card></wml>');
if(!isset($yes))die('<card title="&#x41f;pe&#x434;y&#x43f;pe&#x436;&#x434;e&#x43d;&#x438;e"><p align="center"><small><b>B&#x43d;&#x438;&#x43c;a&#x43d;&#x438;e!</b><br/>:::::::<br/>He&#x43b;&#x44c;&#x437;&#x44f; o&#x442;&#x43f;pa&#x432;&#x43b;&#x44f;&#x442;&#x44c; &#x444;a&#x439;&#x43b;&#x44b; &#x431;o&#x43b;&#x44c;&#x448;e 500 K&#x438;&#x43b;o&#x411;a&#x439;&#x442;<br/>He&#x43b;&#x44c;&#x437;&#x44f; c&#x43f;a&#x43c;&#x438;&#x442;&#x44c; &#x447;y&#x436;&#x438;e &#x43f;oc&#x442;-&#x431;o&#x43a;c&#x44b;!!!<br/>:::::::<br/>Ka&#x436;&#x434;a&#x44f; o&#x442;c&#x44b;&#x43b;&#x43a;a o&#x442;c&#x43b;e&#x436;&#x438;&#x432;ae&#x442;c&#x44f;,&#x43f;o&#x44d;&#x442;o&#x43c;y &#x43d;apy&#x448;&#x438;&#x442;e&#x43b;&#x44f;&#x43c; &#x431;y&#x434;e&#x442; &#x437;a&#x43a;p&#x44b;&#x442; &#x434;oc&#x442;y&#x43f; &#x43a; &#x434;a&#x43d;&#x43d;o&#x439; yc&#x43b;y&#x433;e &#x43d;a&#x432;ce&#x433;&#x434;a &#x438;&#x43b;&#x438; &#x434;o &#x432;&#x44b;&#x44f;c&#x43d;e&#x43d;&#x438;&#x44f; &#x432;cex o&#x431;c&#x442;o&#x44f;&#x442;e&#x43b;&#x44c;c&#x442;&#x432;<br/>Co&#x433;&#x43b;ac&#x43d;&#x44b;?<br/><a href="'.basename($_SERVER['PHP_SELF']).'?yes">&#x414;a</a> &#x438;&#x43b;&#x438; <a href="/index.php">He&#x442;</a></small></p></card></wml>');
if(isset($send)):
if(0==preg_match("/^[0-9a-z\-._]+@[0-9a-z_\-.]+\.[a-z]{2,3}$/si", $mail))die('<card title="O&#x448;&#x438;&#x431;&#x43a;a"><p align="center"><small>M&#x44b;&#x43b;o &#x43d;a&#x43f;&#x438;ca&#x43d;o &#x44f;&#x432;&#x43d;o &#x43d;e &#x432; &#x432;&#x438;&#x434;e [email protected] !!!</small></p></card></wml>');
$name=basename($url);
@Copy($url,"f/".$name);
if(!file_exists("f/".$name))die('<card title="O&#x448;&#x438;&#x431;&#x43a;a"><p align="center"><small>O&#x448;&#x438;&#x431;&#x43a;a! A&#x434;pec &#x444;a&#x439;&#x43b;a &#x43d;e&#x432;epe&#x43d;!</small></p></card></wml>');
$m=@filesize("f/$name");
if($m==0){
@unlink("f/$name");
die('<card title="O&#x448;&#x438;&#x431;&#x43a;a"><p align="center"><small>O&#x448;&#x438;&#x431;&#x43a;a! A&#x434;pec &#x444;a&#x439;&#x43b;a &#x43d;e&#x432;epe&#x43d;!</small></p></card></wml>');}
if(strpos($name,".txt") || strpos($name,".dat"))$o="text/plain";
if(strpos($name,".gif"))$o="image/gif";
if(strpos($name,".jpg") || strpos($name,".jpeg"))$o="image/jpeg";
if(strpos($name,".png"))$o="image/png";
if(strpos($name,".zip"))$o="archive/zip";
if(strpos($name,".&#x43f;a&#x43f;"))$o="archive/rar";
if(strpos($name,".midi"))$o="media/midi";
if(strpos($name,".mid"))$o="media/midi";
if(strpos($name,".mmf"))$o="media/mmf";
if(strpos($name,".jar"))$o="archive/jar";
if(strpos($name,".jad"))$o="archive/jar";
if(strpos($name,".thm"))$o="archive/vnd.eri";
if(strpos($name,".nth"))$o="archive/vnh.nth";
if(strpos($name,".3gp"))$o="video/3gpp";
if(strpos($name,".avi"))$o="video/avi";
if(strpos($name,".mp3"))$o="media/mp3";
if(strpos($name,".mp4"))$o="video/mpeg";
if($o==""){
@unlink("f/$name");
die('<card title="O&#x448;&#x438;&#x431;&#x43a;a"><p>He&#x432;ep&#x43d;&#x44b;&#x439; &#x442;&#x438;&#x43f; &#x444;a&#x439;&#x43b;a!<br/>&#x41f;o&#x434;&#x434;ep&#x436;&#x438;&#x432;a&#x44e;&#x442;c&#x44f; &#x444;a&#x439;&#x43b;&#x44b;: txt, dat, gif, jpeg, jpg, png, midi, mmf, mp3, rar, zip, 3gp, avi, mp4, thm. thm.</p></card></wml>');}
?><?php

/*


	this class encapsulates the PHP mail() function.
	implements CC, Bcc, Priority headers


@version	1.3 

- added ReplyTo( $address ) method
- added Receipt() method - to add a mail receipt
- added optionnal charset parameter to Body() method. this should fix charset problem on some mail clients
	     
@example

	include "libmail.php";
	
	$m= new Mail; // create the mail
	$m->From( "[email protected]" );
	$m->To( "[email protected]" );
	$m->Subject( "the subject of the mail" );	

	$message= "Hello world!\nthis is a test of the Mail class\nplease ignore\nThanks.";
	$m->Body( $message);	// set the body
	$m->Cc( "[email protected]");
	$m->Bcc( "[email protected]");
	$m->Priority(4) ;	// set the priority to Low 
	$m->Attach( "/home/leo/toto.gif", "image/gif" ) ;	// attach a file of type image/gif
	$m->Send();	// send the mail
	echo "the mail below has been sent:<br><pre>", $m->Get(), "</pre>";

	
LASTMOD
	Fri Oct  6 15:46:12 UTC 2000

@author	Leo West - [email protected]

*/


class Mail
{
	/*
	list of To addresses
	@var	array
	*/
	var $sendto = array();
	/*
	@var	array
	*/
	var $acc = array();
	/*
	@var	array
	*/
	var $abcc = array();
	/*
	paths of attached files
	@var array
	*/
	var $aattach = array();
	/*
	list of message headers
	@var array
	*/
	var $xheaders = array();
	/*
	message priorities referential
	@var array
	*/
	var $priorities = array( '1 (Highest)', '2 (High)', '3 (Normal)', '4 (Low)', '5 (Lowest)' );
	/*
	character set of message
	@var string
	*/
	var $charset = "us-ascii";
	var $ctencoding = "7bit";
	var $receipt = 0;
	

/*

	Mail contructor
	
*/

function Mail()
{
	$this->autoCheck( true );
	$this->boundary= "--" . md5( uniqid("myboundary") );
}


/*		

activate or desactivate the email addresses validator
ex: autoCheck( true ) turn the validator on
by default autoCheck feature is on

@param boolean	$bool set to true to turn on the auto validation
@access public
*/
function autoCheck( $bool )
{
	if( $bool )
		$this->checkAddress = true;
	else
		$this->checkAddress = false;
}


/*

Define the subject line of the email
@param string $subject any monoline string

*/
function Subject( $subject )
{
	$this->xheaders['Subject'] = strtr( $subject, "\r\n" , "  " );
}


/*

set the sender of the mail
@param string $from should be an email address

*/
 
function From( $from )
{

	if( ! is_string($from) ) {
		echo "Class Mail: error, From is not a string";
		exit;
	}
	$this->xheaders['From'] = $from;
}

/*
 set the Reply-to header 
 @param string $email should be an email address

*/ 
function ReplyTo( $address )
{

	if( ! is_string($address) ) 
		return false;
	
	$this->xheaders["Reply-To"] = $address;
		
}


/*
add a receipt to the mail ie.  a confirmation is returned to the "From" address (or "ReplyTo" if defined) 
when the receiver opens the message.

@warning this functionality is *not* a standard, thus only some mail clients are compliants.

*/
 
function Receipt()
{
	$this->receipt = 1;
}


/*
set the mail recipient
@param string $to email address, accept both a single address or an array of addresses

*/

function To( $to )
{

	// TODO : test validitй sur to
	if( is_array( $to ) )
		$this->sendto= $to;
	else 
		$this->sendto[] = $to;

	if( $this->checkAddress == true )
		$this->CheckAdresses( $this->sendto );

}


/*		Cc()
 *		set the CC headers ( carbon copy )
 *		$cc : email address(es), accept both array and string
 */

function Cc( $cc )
{
	if( is_array($cc) )
		$this->acc= $cc;
	else 
		$this->acc[]= $cc;
		
	if( $this->checkAddress == true )
		$this->CheckAdresses( $this->acc );
	
}



/*		Bcc()
 *		set the Bcc headers ( blank carbon copy ). 
 *		$bcc : email address(es), accept both array and string
 */

function Bcc( $bcc )
{
	if( is_array($bcc) ) {
		$this->abcc = $bcc;
	} else {
		$this->abcc[]= $bcc;
	}

	if( $this->checkAddress == true )
		$this->CheckAdresses( $this->abcc );
}


/*		Body( text [, charset] )
 *		set the body (message) of the mail
 *		define the charset if the message contains extended characters (accents)
 *		default to us-ascii
 *		$mail->Body( "mйl en franзais avec des accents", "iso-8859-1" );
 */
function Body( $body, $charset="" )
{
	$this->body = $body;
	
	if( $charset != "" ) {
		$this->charset = strtolower($charset);
		if( $this->charset != "us-ascii" )
			$this->ctencoding = "8bit";
	}
}


/*		Organization( $org )
 *		set the Organization header
 */
 
function Organization( $org )
{
	if( trim( $org != "" )  )
		$this->xheaders['Organization'] = $org;
}


/*		Priority( $priority )
 *		set the mail priority 
 *		$priority : integer taken between 1 (highest) and 5 ( lowest )
 *		ex: $mail->Priority(1) ; => Highest
 */
 
function Priority( $priority )
{
	if( ! intval( $priority ) )
		return false;
		
	if( ! isset( $this->priorities[$priority-1]) )
		return false;

	$this->xheaders["X-Priority"] = $this->priorities[$priority-1];
	
	return true;
	
}


/*	
 Attach a file to the mail
 
 @param string $filename : path of the file to attach
 @param string $filetype : MIME-type of the file. default to 'application/x-unknown-content-type'
 @param string $disposition : instruct the Mailclient to display the file if possible ("inline") or always as a link ("attachment") possible values are "inline", "attachment"
 */

function Attach( $filename, $filetype = "", $disposition = "inline" )
{
	// TODO : si filetype="", alors chercher dans un tablo de MT connus / extension du fichier
	if( $filetype == "" )
		$filetype = "application/x-unknown-content-type";
		
	$this->aattach[] = $filename;
	$this->actype[] = $filetype;
	$this->adispo[] = $disposition;
}

/*

Build the email message

@access protected

*/
function BuildMail()
{

	// build the headers
	$this->headers = "";
//	$this->xheaders['To'] = implode( ", ", $this->sendto );
	
	if( count($this->acc) > 0 )
		$this->xheaders['CC'] = implode( ", ", $this->acc );
	
	if( count($this->abcc) > 0 ) 
		$this->xheaders['BCC'] = implode( ", ", $this->abcc );
	

	if( $this->receipt ) {
		if( isset($this->xheaders["Reply-To"] ) )
			$this->xheaders["Disposition-Notification-To"] = $this->xheaders["Reply-To"];
		else 
			$this->xheaders["Disposition-Notification-To"] = $this->xheaders['From'];
	}
	
	if( $this->charset != "" ) {
		$this->xheaders["Mime-Version"] = "1.0";
		$this->xheaders["Content-Type"] = "text/plain; charset=$this->charset";
		$this->xheaders["Content-Transfer-Encoding"] = $this->ctencoding;
	}

	$this->xheaders["X-Mailer"] = "Php/libMailv1.3";
	
	// include attached files
	if( count( $this->aattach ) > 0 ) {
		$this->_build_attachement();
	} else {
		$this->fullBody = $this->body;
	}

	reset($this->xheaders);
	while( list( $hdr,$value ) = each( $this->xheaders )  ) {
		if( $hdr != "Subject" )
			$this->headers .= "$hdr: $value\n";
	}
	

}

/*		
	fornat and send the mail
	@access public
	
*/ 
function Send()
{
	$this->BuildMail();
	
	$this->strTo = implode( ", ", $this->sendto );
	
	// envoie du mail
	$res = @mail( $this->strTo, $this->xheaders['Subject'], $this->fullBody, $this->headers );

}



/*
 *		return the whole e-mail , headers + message
 *		can be used for displaying the message in plain text or logging it
 */

function Get()
{
	$this->BuildMail();
	$mail = "To: " . $this->strTo . "\n";
	$mail .= $this->headers . "\n";
	$mail .= $this->fullBody;
	return $mail;
}


/*
	check an email address validity
	@access public
	@param string $address : email address to check
	@return true if email adress is ok
 */
 
function ValidEmail($address)
{
	if( ereg( ".*<(.+)>", $address, $regs ) ) {
		$address = $regs[1];
	}
 	if(ereg( "^[^@  ]+@([a-zA-Z0-9\-]+\.)+([a-zA-Z0-9\-]{2}|net|com|gov|mil|org|edu|int|ru|ua|eu)\$",$address) ) 
 		return true;
 	else
 		return false;
}


/*

	check validity of email addresses 
	@param	array $aad - 
	@return if unvalid, output an error message and exit, this may -should- be customized

 */
 
function CheckAdresses( $aad )
{
	for($i=0;$i< count( $aad); $i++ ) {
		if( ! $this->ValidEmail( $aad[$i]) ) {
			echo "Class Mail, method Mail : invalid address $aad[$i]";	
			exit;
		}
	}
}


/*
 check and encode attach file(s) . internal use only
 @access private
*/

function _build_attachement()
{

	$this->xheaders["Content-Type"] = "multipart/mixed;\n boundary=\"$this->boundary\"";

	$this->fullBody = "This is a multi-part message in MIME format.\n--$this->boundary\n";
	$this->fullBody .= "Content-Type: text/plain; charset=$this->charset\nContent-Transfer-Encoding: $this->ctencoding\n\n" . $this->body ."\n";
	
	$sep= chr(13) . chr(10);
	
	$ata= array();
	$k=0;
	
	// for each attached file, do...
	for( $i=0; $i < count( $this->aattach); $i++ ) {
		
		$filename = $this->aattach[$i];
		$basename = basename($filename);
		$ctype = $this->actype[$i];	// content-type
		$disposition = $this->adispo[$i];
		
		if( ! file_exists( $filename) ) {
			echo "Class Mail, method attach : file $filename can't be found"; exit;
		}
		$subhdr= "--$this->boundary\nContent-type: $ctype;\n name=\"$basename\"\nContent-Transfer-Encoding: base64\nContent-Disposition: $disposition;\n  filename=\"$basename\"\n";
		$ata[$k++] = $subhdr;
		// non encoded line length
		$linesz= filesize( $filename)+1;
		$fp= fopen( $filename, 'r' );
		$ata[$k++] = chunk_split(base64_encode(fread( $fp, $linesz)));
		fclose($fp);
	}
	$this->fullBody .= implode($sep, $ata);
}


} // class Mail


?>
<?php
$subj="Vam fajl ot $Host";
$mess=utf_to_win($mess);
$mess=convert_cyr_string($mess, "w","k");
$m=new Mail;
$m->From("files@$Host");
$m->To("$mail");
$m->Subject("$subj");
$m->Body($mess);
$m->Priority(4);
$m->Attach(@realpath("f/$name"),"$o");
$m->Send();
@unlink("f/$name");
die('<card title="&#x423;c&#x43f;e&#x448;&#x43d;o"><p>&#x423;c&#x43f;e&#x448;&#x43d;o O&#x442;oc&#x43b;a&#x43d;o!<br/>:::::::<br/><a href="/index.php">'.$Host.'</a></p></card></wml>');
endif;
if(isset($yes))die('<card title="&#x424;a&#x439;&#x43b;&#x44b;-M&#x44b;&#x43b;&#x44c;&#x43d;&#x438;&#x43a;o&#x43c; :)"><p><small>URL &#x444;a&#x439;&#x43b;a &#x432; &#x438;&#x43d;e&#x442;e:</small><br/><input name="url" title="url" value="http://"/><br/><small>Ko&#x43c;y &#x448;&#x43b;e&#x43c; &#x444;a&#x439;&#x43b;:</small><br/><input name="mail" title="mail" value="@"/><br/><small>Coo&#x431;&#x449;e&#x43d;&#x438;e:</small><br/><input name="mess" title="mess" value=""/><br/><anchor title="send">O&#x442;&#x43f;pa&#x432;&#x438;&#x442;&#x44c;!<go href="'.basename($_SERVER['PHP_SELF']).'?send=go&amp;yes=agreement" method="post"><postfield name="url" value="$(url)"/><postfield name="mail" value="$(mail)"/><postfield name="mess" value="$(mess)"/></go></anchor><small><br/>:::::::<br/><a href="/">'.$Host.'</a></small></p></card></wml>');
?>