Location: PHPKode > projects > Laikwan WMC > wmc_20070325/hail/getAttachment.php
<?


// wmc lib
require("../wmcLib/mime.php");

// hail lib
require("MailFolderItem.class.php");
require("MailFolder.class.php");
require("HTTPMail.class.php");

// pear mimeDecode
require_once 'Mail/mimeDecode.php';


function get_attachment($hm, $url, $attach_num){

	$url = urldecode($url);
	$msg = $hm->get_email($url);
//print($url."\n\n");
//print($msg."\n\n");

	// setup mail_mimedecode
	$params['include_bodies'] = true;
	$params['decode_bodies']  = true;
	$params['decode_headers'] = true;
	$decoder = new Mail_mimeDecode($msg);
	$structure = $decoder->decode($params);

	$attached = wmcMime_getAttachment($structure, $attach_num);
	if($attached){

//		header("Content-type: text/html; charset=utf-8");  
		header("Content-type: ".$attached['contenttype']);  

		// todo: no cache while in dev - remove no cache when done
		header("Expires: " . gmdate("D, d M Y H:i:s") . " GMT");
		header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
		header("Cache-Control: no-store, no-cache, must-revalidate");
		header("Cache-Control: post-check=0, pre-check=0", false);
		header("Pragma: no-cache");

		print $attached['data'] ;
		return 0;
	}else{
		return "Invalid Attachment";
	}

}




@ini_set("session.use_cookies",	 0);
@ini_set("session.use_trans_sid", 1);					 
session_start();

/*
header("Content-type: text/xml; charset=utf-8");  // must use text/xml for ajax/xmlhttp to work :(
header("Expires: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n\n";
*/


flush();

$err;

if (isset($_SESSION['hail']['hm'])){
	if( array_key_exists('mail_url',$_GET) && array_key_exists('attach_num',$_GET)){

		$err = get_attachment($_SESSION['hail']['hm'], $_GET['mail_url'], $_GET['attach_num']);
	}else{
		$err = "No email/attachment selected.";
	}

}  else {   // not logged in
	$_SESSION['hail']['sess_user'] = "";
	$_SESSION['hail']['sess_pass'] = "";
	$err = "Your login expired.";
}


if($err){
	
	header("Content-type: text/html; charset=utf-8");  // must use text/xml for ajax/xmlhttp to work :(
	header("Expires: " . gmdate("D, d M Y H:i:s") . " GMT");
	header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
	header("Cache-Control: no-store, no-cache, must-revalidate");
	header("Cache-Control: post-check=0, pre-check=0", false);
	header("Pragma: no-cache");

	print "<html><body>". $err . "</body></html>\n";


}
?>


Return current item: Laikwan WMC