If you're with EE, see here to earn points for answering this. I've been looking into solutions like Qmail Scanner and simscan but none seem to be able to do the following. I run Red Hat Enterprise Linux v3 (PHP4+ and MySQL 3+) and need to set up a mail server soon. I'd like to use Qmail but there is one requirement I have: I need to be able to scan mail content, subject or header would be enough, for certain phrases (regular expression support ideally) and upon finding a match I need to trigger a custom action. Qmail Scanner and simscan etc. can do the first part but only allow actions like 'quarantine', 'delete', 'drop' etc. I typically need to do a GET or some other means of instructing PHP or a web service. Basically, I receive emails from a 3d party service which contain a unique ID and a value. Say 12345 - Yes. I want to sniff incoming mail (just one account is fine) and if it's from this certain IP/From: then I need to break down the email to strip out the ID and the value then update the Mysql database entry for that ID, probably via PHP. There's a tutorial here http://www.devarticles.com/c/a/PHP/Incoming-Mail-and-PHP/1/ on how PHP can do it. I even contacted the author to clarify a few things but he reckons it really only works when PHP is compiled as CGI binary whereas mine is an Apache module. Is there a solution to my needs? I was hoping to use Qmail but sendmail or exim are fine too.
Do you have shell access to the server? You could translate the php script into a sh script or whatever your server runs. Or compile an additional php as a cgi binary, you can then continue running the mod_php for the webserver.
I do have shell access indeed. Would you mind elaborating on the sh script option? What MTA and or plug in would be able to call a user defined shell script? The mail scanners and agents I examined can only do so many actions based on reg exps. What setup would I need to call the shell script? Dankjewel.
What you are looking for is easily handlable with qmail out of the box. You can use a dot qmail file to pass the email onto a program prior to delivery, and optionally deliver the mail as normal. You can use perl to scan the e-mail and take action as necessary. The exact steps to take are not something I would know off the top of my head, but it shouldn't be too difficult if you do a little research and see some examples of .qmail files on the web. Some people use .qmail to enable spam assassin on a user by user basis. I use it to pass my mail through maildrop which gives me some extra filtering capabilities. example of what a .qmail file looks like for maildrop usage for a particular user | maildrop -d /path/to/my/maildir Code (markup): Now that I've thought about it a little more... you could pipe your message to a small perl prog that posts stdin to your page using curl. You can search around for some code to do this, I'm sure there's something out there. Basically, curl with the -d option will post data, but it has to be urlencoded. Pseudocode for post.pl 1) take stdin as a variable 2) urlencode that variable 3) run curl -d and post to the php page .qmail file: | post.pl /path/to/regular/delivery/address Code (markup):
Thanks nevetS, I always wondered why such a seemingly simple thing wouldn't be available as standard. Every time I looked into it I never managed to find out how or whether it's even possible. So I can basically use a .qmail file with theoretically something that says: if FROM: = "him@them.com" send email to script.sh AND don't bother delivering it so never mind adding it to the mail queue... Then script.sh takes the headers and body pretty much as plain text and can do all the usual stuff one can like reading line by line, exploding by space etc... Right? That would be just what I want.
Actually, I misspoke. .qmail files contain delivery information, and aren't conditional. So you can't optionally deliver the message with just a .qmail file. You could use something like maildrop to filter out the messages you don't want, and then also pass your mail message to a shell script or perl script. The shell script or perl script will also have to parse the mail headers though. Clear as mud, right? Do you follow me?
Sh / Bourne would be the OS'es native shell environment (probably bash specifically if you run Linux) so you wouldn't need to configure php to run shell scripts. This may be the only way if you have limited shell access to the server. My idea was to follow the tutorial you gave but instead of using the php script, translate it into sh. If you have full root access it will be easier to install a php as a binary that can execute shell scripts parallel to the one (mod_php) you use for serving web pages. You would then be able to completely follow the tutorial. There is probably some package you can install for the Linux distribution you use. Be careful it doesn't mess with your webserver configuration though (I see nevetS has also responded while I was writing this reply. qmail is a very good program and perl is likely to be already installed on the server. So that solution may be better.)
The server is ours so I can do with it what I want. Full access. But it is a live production environment so I don't want to risk dropping current functionality. Hence my reluctance to run another copy of PHP which already in my mind complicates matters. I might just build such an environment on a spare box to test it. Perl is running already as well. What I found is that if you run all emails through some parsing script it can take up quite some CPU power. Hence my wish to only pick out some accounts or only sone mails based on where they came from (address or IP). Then do some trickery with those and either deliver them or drop them altogether, I don't mind. It seems like you can either do something to all or to none. Not conditionally perform actions on just some. Can qmail files be set up per account at all?
yes. You just name the files something like .qmail-tops30 I imagine you are going to go the vpopmail route, so in that case you just put them in the domain folder - ~vpopmail/domains/yourdomain/.qmail-tops30
I'm quite new to all this actually. With vpopmail I guess you mean Inter7's vpopmail? http://www.inter7.com/index.php?page=vpopmail I might just hire a real MTA guru to do all this.
Yes. vpopmail allows you to do virtual hosting - so you can have mail come into one server for several domains. I believe it's the most common way to do it. I actually hired inter7 to do some work for me. They were extremely reasonable as far as price, and quick to do anything on the menu. I asked for custom work and ended up doing it myself because they could never get back to me with even a price quote.