<?

include_once "./setting.php";

include_once $global["root"] . "/include/handle.php";
include_once $global["root"] . "/include/print_array.php";

include_once $global["root"] . "/module/message/function/etc.php";

//-------------------------------------------------- protection
include_once $global["root"] . "/lib/Site.php";
include_once $global["root"] . "/lib/Address.php";

$Site = new Site;
$Site->init("mail");

extract($_POST);

$Address = new Address;

switch ($_POST["action"]) {

	case ("add") :
		$address = trim($_POST["address_to_block"]);

		// check whether it is valid email address or not.
		if (! $Address->check_valid($address)) {
			goprev();
		}

		$Address = new Address($address);
		$retval = $Address->block_add();

	break;

	case ("remove") :
		if (count($_POST["block_address"]) < 1) {
			goprev();
		}

		$retval = true;

		$Address = new Address;

		while (list($i, $j) = each($_POST["block_address"])) {
			if (! $retval) {
				break;
			} else {
				$retval = $Address->block_remove(false, $j);
			}
		}

	break;

	default :
		$url = "Location: " . $_SESSION["user_www_url"] .
			"/mail?mode=control&control=1&no=1";
		$Site->end1();

		Header($url);
		exit;
}

if ($retval) {
	if ($_POST["post"] == "list") {
		$url = $_SESSION["user_www_url"] . "/mail?mode=dialog&type=100";
	} else {
		$url = $_SESSION["user_www_url"] . "/mail?mode=control&control=1&no=1";
	}

	$Site->end1();

	Header("Location: " . $url);
	exit;
} else {
	if ($_POST["post"] == "list") {
		$url = $_SESSION["user_www_url"] . "/mail?mode=dialog&type=100";

		$Site->end1();

		Header("Location: " . $url);
		exit;
	} else {
		$Site->end1();

		goprev();
	}
}

/*
Description
-----------

Author
------
 Spike^ekipS <spike@spikeekips.net>

Changelog
---------

Usage
-----

*/

?>
