FutureQuest, Inc. FutureQuest, Inc. FutureQuest, Inc.

FutureQuest, Inc.
Go Back   FutureQuest Community > General Site Owner Support (All may read/respond) > Email & Mailing List Management
User Name
Password  Lost PW

Reply
 
Thread Tools Search this Thread Display Modes
Old 03-13-2005, 11:08 AM   Postid: 129168
MikeSD
Site Owner

Forum Notability:
10 pts: User-friendly
[Post Feedback]
 
Join Date: Nov 2001
Posts: 124
I need a special email filter

I want an email filter that does the following:

1) Runs all emails from a specific address only, through a filter.
2) Based on email contents, it will execute a PHP script.
3) The PHP script will not modify the original email.
3) Return with status to process the mail normally.

Basically this will do nothing to the email itself but will execute a PHP script to do some email scanning for certain content that I send in my email and save it to an external file.

Is that possible? What is the best method? Would that be a "Simple filter" or a "processor filter"? Anyone have a basic shell for this? I prefer to use PHP.

Thanks,
MikeSD is offline   Reply With Quote
Old 03-13-2005, 11:39 AM   Postid: 129169
sheila
Site Owner
 
sheila's Avatar

Forum Notability:
0 pts: Even-handed
[Post Feedback]
 
Join Date: Aug 1999
Location: Metro Los Angeles Area
Posts: 7,398
Re: I need a special email filter

Quote:
Originally Posted by MikeSD
I want an email filter that ...

Basically this will do nothing to the email itself but will execute a PHP script to do some email scanning for certain content that I send in my email and save it to an external file.

Is that possible? What is the best method? Would that be a "Simple filter" or a "processor filter"? Anyone have a basic shell for this? I prefer to use PHP.
You want to run a Simple Filter. A "processor" is used to modify the email, which you say you do not want to do.

Quote:
Originally Posted by MikeSD
1) Runs all emails from a specific address only, through a filter.
You can't run the filter based on the from email address. A filter is set up on one of your POP are Alias email addies, and EVERY email delivered TO that address will trigger the filter.

You will need to have the filter script detect the FROM address and only take the desired actions if the approprate FROM address is in the email.


Quote:
Originally Posted by MikeSD
2) Based on email contents, it will execute a PHP script.
You want the filter to call another PHP script? I would suggest incorporating them into a single script.

Quote:
Originally Posted by MikeSD
3) The PHP script will not modify the original email.
If I understand your request correctly, all you want to do is write the text of the email to a file if it comes from a certain FROM address?

Quote:
Originally Posted by MikeSD
3) Return with status to process the mail normally.
Unless an error condition is encountered when the script runs, or your script sets a particular action on exit, the default is for the mail system to process the mail normally when the script finishes execution.

Basically, here is what the script would need to do...

An email filter is provided the raw message text as standard input. Read standard input into some variable at the beginning of your script.

Parse the message somehow to find the From email address.

If it matches your target address, then open the file you want to write to (in append mode).

Write out the pertinent content from the email message in your stored variable to the file.

Close the file.

End of script.
__________________
sheila
http://www.thinkspot.net/sheilaruns/
sheila is offline   Reply With Quote
Old 03-13-2005, 11:45 AM   Postid: 129170
MikeSD
Site Owner

Forum Notability:
10 pts: User-friendly
[Post Feedback]
 
Join Date: Nov 2001
Posts: 124
Re: I need a special email filter

Yes, that pretty much sums it up. What I was hoping for was someone that could point me to a basic shell for such a script? Can these be done in PHP? If not PL is ok.

I see that there are some one line scripts on the FQ tutorial but are there some more advanced examples that show the entire script?

Here is exactly what I wish to do:
  • Send an email to one of my accounts. Ex: data@mydomain.com
  • Have the script look at all emails to that account and check for special code in the "subject".
  • If the correct code is there, then it will save the text to a file and if there is an attachment, save that attachment as a new file within a special folder. Both text and attachment would be saved to the same folder.
  • Return with the proper error code to process the mail as normal, regardless of mail content.
I would like to find a basic script that can serve as an beginning. I would modify the script to handle my situation. Preferably in PHP but if not, in Perl.

Last edited by MikeSD : 03-13-2005 at 12:47 PM.
MikeSD is offline   Reply With Quote
Old 03-13-2005, 11:57 AM   Postid: 129171
sheila
Site Owner
 
sheila's Avatar

Forum Notability:
0 pts: Even-handed
[Post Feedback]
 
Join Date: Aug 1999
Location: Metro Los Angeles Area
Posts: 7,398
Re: I need a special email filter

There are many examples of email filters posted in these forums. I would suggest searching the forums for examples.

There aren't many (or any?) in PHP, although it is possible to use PHP. Most of them are either in Perl or Python.

Here are some links to get you started:

http://www.thinkspot.net/sheila/arti...40804114357117
http://www.aota.net/forums/showthread.php?t=17989
http://www.aota.net/forums/showthread.php?t=16707
http://www.aota.net/forums/showthread.php?t=14220

Note that references in older material to .qmail files can be ignored, as our mail system no longer uses these. Simply paste the full path to the script into your CNC panel, making sure that the command that you paste does actually run from the command line (either make the command executable, or pass the script to the interpreter as an argument).
__________________
sheila
http://www.thinkspot.net/sheilaruns/
sheila is offline   Reply With Quote
Old 03-13-2005, 12:03 PM   Postid: 129173
sheila
Site Owner
 
sheila's Avatar

Forum Notability:
0 pts: Even-handed
[Post Feedback]
 
Join Date: Aug 1999
Location: Metro Los Angeles Area
Posts: 7,398
Re: I need a special email filter

Your statement that we have only one-line examples in our tutorial, makes me think you haven't seen this one, which provides examples written in Perl and Python and also explains a bit about how custom filters work:

http://service.FutureQuest.net/?_a=k...ndetails&_i=98
__________________
sheila
http://www.thinkspot.net/sheilaruns/
sheila is offline   Reply With Quote
Old 03-13-2005, 01:19 PM   Postid: 129176
kitchin
Site Owner

Forum Notability:
1163 pts: A True Crowd-pleaser!
[Post Feedback]
 
Join Date: Jan 2001
Location: Virginia
Posts: 2,992
Re: I need a special email filter

This will get you started. You have 3 sources of data about the mail: $_SERVER, $_ENV and Standard Input, which has the whole message. $_SERVER duplicates stuff in $_ENV.

The first character of the file should be the shebang, #.
PHP Code:
#!/usr/local/bin/php 
<?php

## This is a sample Custom Email Filter for the FutureQuest CNC.
## Replace YOURACCOUNT below with your actual name in your account's path.
## 1. Upload this file as text to
##    /big/dom/xYOURACCOUNT/filterdirectory/test.php
## 2. Make this Simple Filter for the email address:
##    /big/dom/xYOURACCOUNT/filterdirectory/test.php
## 3. Upload a blank (or test) file to this:
$filename'/big/dom/xYOURACCOUNT/filterdirectory/test.txt';
## 4. CHMOD the above test.txt file to at least 664 (-rw-rw-r--)
## 5. Send a test message to the email address.

$datedate('r');
ob_start();
// phpinfo();
print "\n_SERVER:\n"print_r($_SERVER);
print 
"\n_ENV:\n"print_r($_ENV);
$buffer ob_get_contents();
ob_end_clean(); 

$buffer2'';
if (
$handlefopen('php://stdin','r')) {
  while (!
feof($handle)) {
    
$buffer2.= fgets($handle);
  }
  
fclose($handle);
}
$buffer.= "\nSTDIN:\n" $buffer2;

// if you are viewing $filename in html, use this:
$bufferhtmlspecialchars($buffer);

if (
$handle fopen($filename'w')) {
   
fwrite($handle"test $date\n");
   
fwrite($handle$buffer);
   
fclose($handle);
}

exit(
0);
?>
You may want to be careful to trap errors. I don't know what exit codes they produce.
kitchin is offline   Reply With Quote
Old 03-13-2005, 01:41 PM   Postid: 129178
MikeSD
Site Owner

Forum Notability:
10 pts: User-friendly
[Post Feedback]
 
Join Date: Nov 2001
Posts: 124
Re: I need a special email filter

Thanks, that should get me started. The pervious examples helped too. I have already tested a simple script that prints out environment varialbles.

These are the tasks that I have to add to the script:

1) Search "Subject:" for code (ex: 12345)
2) If found continue, if not found exit to step 4
3) If code is found...
a) save body of text (without header) to a file
b) save the attachment as file
c) both of these saved to /big/com/mydomain/www/SavedFolder
4) return with exit code for normal mail handling

I wish this filter to behave this way so that I can email text and attachments that will be placed in a folder that anyone can look at, without having to send through emails.

I will work this out but for those that are thouroughly familar with PL or PHP maybe you could save me a bit of time.

Thanks for the help
MikeSD is offline   Reply With Quote
Old 03-13-2005, 01:45 PM   Postid: 129179
sheila
Site Owner
 
sheila's Avatar

Forum Notability:
0 pts: Even-handed
[Post Feedback]
 
Join Date: Aug 1999
Location: Metro Los Angeles Area
Posts: 7,398
Re: I need a special email filter

Quote:
Originally Posted by MikeSD
I wish this filter to behave this way so that I can email text and attachments that will be placed in a folder that anyone can look at, without having to send through emails.

I will work this out but for those that are thouroughly familar with PL or PHP maybe you could save me a bit of time.
As an alternative method of accomplishing the same goal...
Have you considered perhaps to forward emails with a certain characteristic to a mailing list with archiving enabled, and use Mhonarc to display the archive on the web?

(Discussions of Mhonarc are in these forums. Search on Mhonarc will turn them up.)

Just thinking that might be a lot quicker for you to implement and may accomplish the same goal.
__________________
sheila
http://www.thinkspot.net/sheilaruns/
sheila is offline   Reply With Quote
Old 03-13-2005, 01:49 PM   Postid: 129182
MikeSD
Site Owner

Forum Notability:
10 pts: User-friendly
[Post Feedback]
 
Join Date: Nov 2001
Posts: 124
Re: I need a special email filter

Yes, but ultimately I will be formatting all the messages (in the same script) to build a web page. The web page will be added to with each successive email.

What I need to get me started is what is listed in the previous post. I'm sure I'll figure this all out but I'm a bit rusty on Perl and searches. I'm completely new at parsing for attachments and such.

Once I have these two elements solved, the rest will be simply modifications to produce the desired web look.

Any help will be greatly appreciated.

Mike
MikeSD is offline   Reply With Quote
Old 03-14-2005, 05:49 PM   Postid: 129220
VicCa.
Site Owner
 
VicCa.'s Avatar

Forum Notability:
10 pts: User-friendly
[Post Feedback]
 
Join Date: Jul 2004
Location: Midwest, USA
Posts: 34
Re: I need a special email filter

Mike, have you explored PHP's built in file upload?

It would be a lot simpler to write a web-based admin app in PHP that lets you enter some text and upload a file. It should be easier for you to use (you can validate all the fields interactively, and have meaningful directions on the web page). If you have Welling & Thomson's PHP and MySQL Web Development, chapter 16 has a detailed file upload example.

The approach you've described is ok, but why add all the complexity of parsing email, when PHP already has a nice clean file upload capability?
__________________
"All you have to do is tell them they are being attacked and denounce the pacifists for lack of patriotism and exposing the country to danger. It works the same way in any country."
- Herman Goering at the Nuremberg trials
VicCa. is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 visitors)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -4. The time now is 09:37 PM.


Running on vBulletin®
Copyright © 2000 - 2013, Jelsoft Enterprises Ltd.
Hosted & Administrated by FutureQuest, Inc.
Images & content copyright © 1998-2013 FutureQuest, Inc.
FutureQuest, Inc.