Deseree wrote:d11wtq wrote:You're way off. That valiases directory contains aliases for the actaul emails to be passed on to another address (email address, not script).
You need to use a transport protocol that will likely be referred to as "pipe" in your MTA. I don't know what MTA you're using but I know it's trivial in exim once you get your head around it. I've always found MTA's to be damn tricky things to configure (immensely moreso than apache or ftp) but you can do some fun things
What Mail Transfer Agent are you running?
Cpanel/WHM, so Exim is the mail processor.....
OK if exim is the mail proccessor I'll show you how I currently use it to pass SPAM mail on my server to a PHP script to log it in a MySQL database.... you'll see the idea.
In exim.conf (usually /etc/exim/exim.conf but may vary):
Code: Select all
#This goes at the top of the config file... the path to system_filer.exim may vary
system_filter = /etc/exim/system_filter.exim
system_filter_pipe_transport = mysql_spamlog
#Down towards the bottom in the transports section
#Change the command to whatever your PHP script is (it needs a shebang in the script)
mysql_spamlog:
driver = pipe
command = /usr/local/bin/spam-mail-log
user = mail
group = mail
Now in system_filter.exim
Code: Select all
if
"${if def:header_X-Spam_flag: {there}}" is "there"
then
pipe "/usr/local/bin/spam-mail-log $sender_address $recipients $h_Subject: $message_body $h_X-Spam_report: $h_X-Spam_score: $message_id"
endif
If that filter is looking for spam in my case.... if you actually want to pass *all* emails through the pipe (your php script then just put the line that starts with "pipe" by itself, outside of any conditions).
The variables available to you are $h_Header-name, $message_body, $recipients, $sender_address (the full list is in the manual).
Now all that's left to do it to write your PHP script to pipe your mail to:
Code: Select all
#!/usr/local/bin/php
<?php
$conn = mysql_connect('localhost', 'user', 'pass');
mysql_select_db('spamassassin');
if (count($argv) < 8) die();
$copy = array();
foreach ($argv as $v) $copy[] = mysql_real_escape_string($v);
$pre_query = "select * from spamlog where message_id = '$copy[7]'";
$pre_result = mysql_result($pre_query);
if (mysql_num_rows($pre_result) > 0) die();
$query = "
insert into
spamlog (
sender,
recipient,
subject,
body,
report,
score,
message_id,
delivery_time)
values (
'$copy[1]',
'$copy[2]',
'$copy[3]',
'$copy[4]',
'$copy[5]',
'$copy[6]',
'$copy[7]',
now())";
mysql_query($query);
mysql_close();
?>
I've used a CLI-style PHP script, made executable and placed the path to the PHP interpreter in the shebang at the top.... you can probably just change the pipe command in exim to call the PHP interpreter itself though.
If you get stuck just ask (on here)
