<?php
// +-------------------------------------------------------------+
// | HiveMail™ version 1.3.1
// +-------------------------------------------------------------+
// | HIVEMAIL™ IS NOT FREE SOFTWARE
// | If you have downloaded this software from a website other
// | than Hivemail or if you have otherwise received
// | this software from someone who is not a representative of
// | this organization you are involved in an illegal activity.
// +-------------------------------------------------------------+
// | $RCSfile: rules.block.php,v $ - $Revision: 1.17 $
// | $Date: 2004/07/21 02:49:32 $ - $Author: tubedogg $
// +-------------------------------------------------------------+

error_reporting(E_ALL & ~E_NOTICE);
$templatesused = 'redirect_blocked';
require_once('./global.php');

// ############################################################################
if (!empty($messageid) or $block == 'subject') {
	$message = getinfo('message', $messageid);
	$email = $message['email'];
} else {
	$email = urldecode($email);
}

// ############################################################################
if (!empty($delete)) {
	require_once('./includes/functions_pop.php');
	require_once('./includes/functions_mime.php');
	require_once('./includes/functions_smtp.php');
}

// ############################################################################
if ($block != 'subject') {
	if (!array_contains($email, extract_email($hiveuser['blocked'], true))) {
		$DB_site->query("
			UPDATE hive_user
			SET blocked = ' ".addslashes($email.' '.$hiveuser['blocked'])." '
			WHERE userid = $hiveuser[userid]
		");
	}

	if (!empty($delete)) {
		delete_messages('email = "'.addslashes($email).'" AND folderid = '.intval($delete).' AND userid = '.$hiveuser['userid']);
	}

	$block = 'email address';
}

// ############################################################################
if ($block == 'subject') {
	$getorder = $DB_site->query_first("
		SELECT MAX(display) AS max
		FROM hive_rule
		WHERE userid = $hiveuser[userid]
	");
	$thisorder = $getorder['max'] + 1;

	$DB_site->query("
		INSERT INTO hive_rule
		(ruleid, userid, cond, action, active, display)
		VALUES
		(NULL, $hiveuser[userid], '".$_rules['conds']['subjecteq']."~".addslashes($message['subject'])."', '".$_rules['actions']['delete']."~', 1, $thisorder)
	");

	if (!empty($delete)) {
		delete_messages('subject = "'.addslashes($message['subject']).'" AND folderid = '.intval($delete).' AND userid = '.$hiveuser['userid']);
	}
}

// Delete message
if (empty($delete) and $deletemsg and $message) {
	delete_messages("messageid = $message[messageid]");
}

eval(makeredirect("redirect_blocked", iif(isset($message), INDEX_FILE."?folderid=$message[folderid]", $_SERVER['HTTP_REFERER'])));

?>