Page 1 of 1

Run Script Once Mail Is Received

Posted: Thu Jan 12, 2006 9:00 pm
by Pineriver
Okay everyone,
The problem I am trying to get around is I have several items for sale that require payment through paypal on my web site, once the person that is buying an item completes the paypal payment method, I get an email notifying me that the payment has been made to buy the item with the details.

The items require password and user name generation so that that user can unlock the program and use, things are beginning to pick up pace and would like a way to execute a process script when the paypal email notice has arrived that takes care of all of this for me.

Now, I can create the process script myself no problem but dont know quite how to catch the paypal notice.
Is there an existing service or something that can be created on an apache linux server for this?

Re: Run Script Once Mail Is Received

Posted: Thu Jan 12, 2006 10:17 pm
by josh
Pineriver wrote:Is there an existing service or something that can be created on an apache linux server for this?
sendmail


you'd have to write a script to run on the command line and have sendmail pipe the incoming mail to it. Doesn't paypal have another notification option? Using email would sound pretty silly to me, especially because emails can be spoofed and also do not have a 100% success rate. What happens when sendmail goes down, or a message gets bounced at no fault of yours.. your customers pay you but do not receive their product?

Re: Run Script Once Mail Is Received

Posted: Thu Jan 12, 2006 10:43 pm
by Pineriver
[quote]Doesn't paypal have another notification option?[quote]

Hmm Ill have to look more into that but I didnt see anything

Posted: Thu Jan 12, 2006 10:51 pm
by josh

Posted: Fri Jan 13, 2006 7:21 am
by Chris Corbyn
I set something up yesterday to log all my incoming SPAM/JUNK in a database so I can gather stats and refine my spam filtering options. The basic principle could be used in the same way here though.

This is using the exim system filter (if you're not using exim this won't be much help ;)

The system_filter.exim file

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"
   headers add "X-Spam_new_subject: *****SPAM***** $h_subject:"
   headers remove Subject
   headers remove subject
   headers add "Subject: $h_X-Spam_new_subject:"
   headers remove X-Spam_new_subject

   if $h_X-Spam_score_int is above 100
   then
      fail text "This message looks like SPAM and has not been delivered ($h_X-Spam_score:)"
   endif

   finish
endif
(I also have a spam router that delivers mail with spam score between 5 and ten to the spam mailbox for the user account)

and the pipe I'm using (Yes it's written in PHP for CLI)

Code: Select all

#!/usr/local/bin/php
<?php

$conn = mysql_connect('localhost', 'spam', '******');
mysql_select_db('spamassassin');

if (count($argv) <  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();

?>
You get the idea though, you can send the details of the email to a script which proccess them (all headers and everything).