<?php
/************************************************************************
	UebiMiau is a GPL'ed software developed by 
	 - Aldoir Ventura - aldoir@users.sourceforge.net
	 - http://uebimiau.sourceforge.net SåÐ Paulo - Brasil
   		
	***********************************************************************
	Version 3.2.0 Upgrades and templates developed by
	 - Todd Henderson - Lead Developer - http://tdah.us 
	 - Dave Rodgers - Developer - http://www.manvel.net 
	 - Laurent (AdNovea) - Developer - http://adnovea.free.fr
	 
	***********************************************************************
	 - Special thanks to the developers at 
	codeworxtech.com, tinymce.moxiecode.com
	telaen.org, phptoys.com, winged.info, ngcoders.com
	without help this project wouldn't be possible 
	
	***********************************************************************
	- File:			spam_address.php
	- Developer: 	Todd Henderson / Mods by Laurent (AdNovea)
	- Date:			November 4, 2008
	- version:		(3.2.0) 1.0
	- Description:  

*************************************************************************/
  
require('./inc/inc.php');
	
	if(!isset($ix) || !isset($folder)) redirect_and_exit("index.php?err=3", true);
	
	$filename = $userfolder.DB_FILTERS;
	$myfile = $UM->_read_file($filename);
	$filters = Array();
	
	if($myfile != "") 
		$filters = unserialize(base64_decode($myfile));
	
	function is_in_filter($email) {
		global $filters;
		foreach($filters as $filter) {
			if($filter["type"] == FL_TYPE_SPAM && $filter["match"] == $email)
				return true;
		}
		return false;
	}
	
	$mail_info = $sess["headers"][base64_encode(strtolower($folder))][$ix];
	
	$emails = Array();
	$from = $mail_info["from"];
	$to = $mail_info["to"];
	$cc = $mail_info["cc"];
	
	
	for($i=0;$i<count($from);$i++) {
		if(!is_in_filter($from[$i]["mail"])) {
			$from[$i]["index"] = $i;
			$emails[] = $from[$i];
		}
	}
	$aval = array();
	
	
	if(isset($fFilter)) {
		for($i=0;$i<count($fFilter);$i++) {
	
			$filters[] = Array(
						"type" 		=> 3,
						"field"		=> 1,
						"match"		=>  $emails[$fFilter[$i]]["mail"],
						);
		}
	
		$UM->_save_file($filename,base64_encode(serialize($filters)));
	
		echo('
		<script language="javascript" type="text/javascript">
			self.close();
		</script>
		');
		redirect($refreshurl);
		exit;
		
	} else {
	
// Set SMARTY variables for templates and display
		$smarty->assign("umFolder",$folder);
		$smarty->assign("umIx",$ix);
		$smarty->assign("umAvailableAddresses",count($emails));
		$smarty->assign("umAddressList",$emails);
	
		$smarty->display("$selected_theme/".HTML_SPAM_ADDRESS);
	}

?>
