Location: PHPKode > projects > The Invisible Mailer (TiM) > tim/filters.php
<?php

include "common.php";
include "template.phpinc";

$title = "TiM Filters";

if (isset($mail)) {
	// we are dealing with a block sender pass-thru
	$contains = "SELECTED";
	$discard = "SELECTED";
	$field = "from";
	$fieldvalue = $mail;
	$text = "Block Sender";
}
if (isset($thread)) {
	// we are dealing with a drop thread pass-thru
	$contains = "SELECTED";
	$discard = "SELECTED";
	$field = "references";
	$fieldvalue = $thread;
	$text = "Drop Thread";
}

$filter_query = $mailstore->rawQuery("select * from filters order by fpriority desc");
$folders_sql = $mailstore->rawQuery("select fid, fname from folders");

$i = 0;
while ($folder = mysql_fetch_array($folders_sql)) {
	$folderarray[$i][0] = $folder['fid'];
	$folderarray[$i][1] = $folder['fname'];
	$i++;
}

// get nuCe setting

$nuce_folder = $mailstore->getnuCeFolder();

$mainbody = '<FORM ACTION="modnuce.php" METHOD="POST">'
			."<B>nuCe setup:</B> Move spam to <SELECT NAME='target'>";

for ($i = 0; $i < sizeof($folderarray); $i++) {
	if ($nuce_folder == $folderarray[$i][0]) { $sel = " SELECTED"; } else { $sel = ""; }
	$mainbody .= "<OPTION VALUE='".$folderarray[$i][0]."'$sel>".$folderarray[$i][1]."</OPTION>\n";
}

if ($nuce_folder != -1)
	$mainbody .= "<OPTION VALUE='-1'>Disable</OPTION></SELECT> <INPUT TYPE=SUBMIT VALUE='Save'></FORM>";
else
	$mainbody .= "<OPTION VALUE='-1' SELECTED>Disable</OPTION></SELECT> <INPUT TYPE=SUBMIT VALUE='Save'></FORM>";

$mainbody .= "<TABLE BORDER=1 WIDTH=100% BORDERCOLOR=black CELLSPACING=0 CELLPADDING=4>
<TR BGCOLOR=#DDDDDD STYLE='font-weight: bold'><TD WIDTH=20%>Header field</TD><TD WIDTH=15%>Rule</TD><TD WIDTH=30%>Data</TD><TD WIDTH=10%>Priority</TD><TD WIDTH=20%>Action</TD><TD WIDTH=5%>&nbsp;</TD></TR>";

while ($filter = mysql_fetch_array($filter_query)) {
	
	$mainbody .= "<TR><FORM ACTION='modfilter.php' METHOD='POST'><TD><INPUT TYPE=TEXT NAME='field' VALUE='".strtolower($filter['ffield'])."' STYLE='font-family: Tahoma,Verdana,Arial,Helvetica,sans-serif; font-size: 10pt; width: 100%'><INPUT TYPE=HIDDEN NAME='fid' VALUE='".$filter['fid']."'></TD>"
			."<TD><SELECT NAME='rule' STYLE='font-family: Tahoma,Verdana,Arial,Helvetica,sans-serif; font-size: 10pt; width: 100%'>";

	if ($filter['ftype'] == "contains") { $mainbody .= "<OPTION VALUE='contains'>contains</OPTION><OPTION VALUE='equals'>is equal to</OPTION>"; }
	else { $mainbody .= "<OPTION VALUE='equals'>is equal to</OPTION><OPTION VALUE='contains'>contains</OPTION>"; }

	$mainbody .= "</SELECT></TD>"
			."<TD><INPUT TYPE=TEXT NAME='data' VALUE='".strtolower($filter['fdata'])."' STYLE='font-family: Tahoma,Verdana,Arial,Helvetica,sans-serif; font-size: 10pt; width: 100%'></TD>"
			."<TD><SELECT NAME='priority' STYLE='font-family: Tahoma,Verdana,Arial,Helvetica,sans-serif; font-size: 10pt; width: 100%'>";
	for ($i = 0; $i < 128; $i++) {
			if ($i != $filter['fpriority'])
				$mainbody .= "<OPTION VALUE='$i'>$i</OPTION>";
			else
				$mainbody .= "<OPTION VALUE='$i' SELECTED>$i</OPTION>";
	}		
	$mainbody .= "<OPTION VALUE='del'>Delete rule</OPTION>";
	$mainbody .= "</SELECT></TD>"
				."<TD><SELECT NAME='moveto' STYLE='font-family: Tahoma,Verdana,Arial,Helvetica,sans-serif; font-size: 10pt; width: 100%'>";

for ($i = 0; $i < sizeof($folderarray); $i++) {

if ($folderarray[$i][0] == $filter['fmoveto'])
	$mainbody .= "<OPTION VALUE='".$folderarray[$i][0]."' SELECTED>Move to ".$folderarray[$i][1]."</OPTION>";
else
	$mainbody .= "<OPTION VALUE='".$folderarray[$i][0]."'>Move to ".$folderarray[$i][1]."</OPTION>";
}

// magic folders ids used for flag/delete rules

if ($filter['fmoveto'] == 65535)
	$mainbody .= "<OPTION VALUE='65535' SELECTED>Flag message</OPTION>";
else
	$mainbody .= "<OPTION VALUE='65535'>Flag message</OPTION>";

if ($filter['fmoveto'] == 65534)
	$mainbody .= "<OPTION VALUE='65534' SELECTED>Discard message</OPTION>";
else
	$mainbody .= "<OPTION VALUE='65534'>Discard message</OPTION>";

if ($filter['fmoveto'] == 65533)
	$mainbody .= "<OPTION VALUE='65533' SELECTED>Bypass nuCe</OPTION>";
else
	$mainbody .= "<OPTION VALUE='65533'>Bypass nuCe</OPTION>";

$mainbody .= "</SELECT></TD>";

$mainbody .= "<TD><INPUT TYPE=SUBMIT VALUE='Update' STYLE='font-family: Tahoma,Verdana,Arial,Helvetica,sans-serif; font-size: 10pt; width: 100%'></TD></TR></FORM>\n";

}

if (isset($text)) {
	$mainbody .= "<TR BGCOLOR=#BBBBBB><TD COLSPAN=6>$text</TD></TR>";
}

$mainbody .= "<TR BGCOLOR=#BBFFBB><FORM ACTION='addfilter.php' METHOD='post'><TD>"
		."<INPUT TYPE=TEXT NAME='field' STYLE='font-family: Tahoma,Verdana,Arial,Helvetica,sans-serif; font-size: 10pt; width: 100%' VALUE='$field'></TD>"
		."<TD><SELECT NAME='rule' STYLE='font-family: Tahoma,Verdana,Arial,Helvetica,sans-serif; font-size: 10pt; width: 100%'><OPTION VALUE='equals'>is equal to</OPTION><OPTION VALUE='contains'$contains>contains</OPTIONS></TD>"
		."<TD><INPUT TYPE=TEXT NAME='data' STYLE='font-family: Tahoma,Verdana,Arial,Helvetica,sans-serif; font-size: 10pt; width: 100%' VALUE='$fieldvalue'></TD>"
		."<TD><SELECT NAME='priority' STYLE='font-family: Tahoma,Verdana,Arial,Helvetica,sans-serif; font-size: 10pt; width: 100%'>";
for ($i = 0; $i < 128; $i++) {
	if ($i != 63)
		$mainbody .= "<OPTION VALUE='$i'>$i</OPTION>";
	else
		$mainbody .= "<OPTION VALUE='$i' SELECTED>$i</OPTION>";
}

$mainbody .= "</SELECT></TD>"
			."<TD><SELECT NAME='moveto' STYLE='font-family: Tahoma,Verdana,Arial,Helvetica,sans-serif; font-size: 10pt; width: 100%'>";

for ($i = 0; $i < sizeof($folderarray); $i++) {

	$mainbody .= "<OPTION VALUE='".$folderarray[$i][0]."'>Move to ".$folderarray[$i][1]."</OPTION>";

}

$mainbody .= "<OPTION VALUE='65535'>Flag message</OPTION>"
		."<OPTION VALUE='65534'$discard>Discard message</OPTION>"
		."<OPTION VALUE='65533'>Bypass nuCe</OPTION>";

$mainbody .= "</SELECT></TD>"
			."<TD><INPUT TYPE=SUBMIT VALUE='Add' STYLE='font-family: Tahoma,Verdana,Arial,Helvetica,sans-serif; font-size: 10pt; width: 100%'></TD>"
			."</TR></FORM>";


$mainbody .= "</TABLE>";

tim_flush();

?>
Return current item: The Invisible Mailer (TiM)