View Single Post
  #69 (permalink)  
Old 20-03-2007, 11:54
Vickie Vickie is offline
Member
 
Join Date: Jan 2007
Location: Northamptonshire
Posts: 37
Default Have you looked at Horde?

To get an idea of what I'm talking about, have you looked at the per-mailbox filtering in Horde? This is a point and click front end to regular expressions, which let you specify whether a subject, To, From or Contents of e-mails contain, or begin with words or letters. So, for example, anything Subject "Rolex" or "******" or "beginning with Vi". The reason I wrote my own program is because the filter front-end in Horde is not sophisticated enough. You might want to look there first.

My previous ISP had a similar front end on a per mailbox basis for users to configure. I ended up configuring it for my users, but it was point and click.

I'm happy to help where I can, but as far as my scripts are concerned, I think that if you aren't a PHP programmer you might find what I have to offer a bit hard to use. This is a fairly blunt tool for my personal testing and use, I don't rely on display or saving a list of deleted headers. My logic is a bit skewey as well, because I am not careful to avoid repeating the filtering.

I sent the following as a private message to eukhost.com last night, suggesting that some of the support staff might be able to refine these for you. Here, below are three functions. A button in an HTML form executes the function named "filterMailbox".

I use the regular expression tester here: www. quanetic.com/regex.php

Try the Horde filters and if this seems right to you, let me know and I'll include you in any developments I manage with exim.

Vickie


function filterMailbox()
{

$fp=fsockopen("your.mailserver.here", 110);
$line =fgets($fp, 1024);
fputs($fp, "USER yourusername@yourdomain.co.uk\r\n");
$line =fgets($fp, 1024);

if (StartsWith($line, "+OK"))
{
fputs($fp,"PASS userspassword\r\n");
$line =fgets($fp, 1024);
if (StartsWith($line, "+OK"))
{
$num = countMessages($fp);
$thisArray = fetchHeader($fp, $num);

echo (count($thisArray)." to be filtered<br>\n");
$k = 0;
for ($i = 0; $i < count($thisArray); $i++)
{
//I filter on To, From or Subject
$filterOnTo = trim($thisArray[$i][0]);
$filterOnFrom = trim($thisArray[$i][2]);
$filterOnSubject = trim($thisArray[$i][3]);



//This dates from when the e-bay server was broken into
if (preg_match("/^vebay/i", $filterOnTo))
{
echo ($i ."is a vebay email<br>");
$toBeDeleted[$k] = $i;
$k++;
}

if (preg_match("/^usurious-bugs/", $filterOnFrom))
{
echo ($i ."is a from usurious email<br>");
$toBeDeleted[$k] = $i;
$k++;
}


if (preg_match("/^\*SPAM\*/i", $filterOnSubject))
{
echo ($i ."is caught by XRBL email<br>");
$toBeDeleted[$k] = $i;
$k++;
}

}
echo (count($toBeDeleted)." to be deleted<br>\n");
for ($j = 0; $j < count($toBeDeleted); $j++)
{
echo($toBeDeleted[$j] ."is to be deleted <br>");
$g = trim($toBeDeleted[$j]);
$g += 1;
fputs($fp, "DELE $g\r\n");
$line =fgets($fp, 1024);
echo("result was ".$line."<br>");

}
}
}
fputs($fp, "QUIT\r\n");
$line3 = fgets($fp,1024);
echo("<br>".$line3);
fclose($fp);
}

function countMessages($fp)
{

$num = -5;
$line1 = "";

fputs($fp,"STAT\r\n");

$line1 =fgets($fp, 1024);
$a = explode(" ", $line1);

$num = (int)$a[1];
echo($num."<br>");

return $num;
}

function fetchHeader($fp, $num)
{
$c = 0;
for ($i = 1; $i <= $num; $i++)
{
fputs($fp, "TOP $i 0\r\n");
$line = fgets($fp, 12;
if ($line[0] == "+")
{
do
{
$line = fgets($fp, 1024);
$lines[$c] = $line;
$c++;
}while ($line[0] !=".");

for($d = 0; $d <= $c; $d++)
{
if ((stristr($lines[$d], "X-Envelope-To:")) || (stristr($lines[$d], "Envelope-To:"))) $result[0] = substr($lines[$d], strpos($lines[$d], ":")+1);
if (stristr($lines[$d], "Delivery-date:")) $result[1] = substr($lines[$d], strpos($lines[$d], ":")+1);
if (stristr($lines[$d], "From:")) $result[2] = substr($lines[$d], strpos($lines[$d], ":")+1);
if (stristr($lines[$d], "Subject:")) $result[3] = substr($lines[$d], strpos($lines[$d], ":")+1);
}
}
$messages[$i-1] = $result;
}
return $messages;
}
Reply With Quote