...

View Full Version : automatically scanning the subjects of email while on the server



akhalsa
06-09-2003, 04:38 PM
I would like to write a program that will periodically scan through the subjects of emails that are on the server. I have been told this can be done with a cgi, but aside from that I have no idea of how to approach this. I would prefer to use a language like perl php, or if necessary c. Thanks alot.

bluephoenix
06-17-2003, 04:04 AM
Well, to be perfectly honest with you I have no idea how a server stores emails before they're retrieved. I've never had the pleasure(?) of working with one. But if they're stored within a directory like any other file then you could use a combination of shell commands and regular expressions.

I threw this script together for a very basic site search engine a while ago... Feel free to look it over and make modifications. Maybe it'll help.

#! /usr/bin/perl

# search.pl - a simple CGI search engine
# Timothy Boronczyk May 7, 2003
#
# Usage:
# command-line: [usr@www]$ search.pl term
# calling from php-enabled page: system("search.pl $term");
#
# Returns: (with HTML formating)
# Your search for [term] resulted in the following matches:
# 1. Page Foo - description of page foo.
# 2. Page Bar - description of page bar.
# 3. Untitled - description of untitled page.
# 4. Page Baz - No description available.

$path = "./"; # path of files in which to search
$no_results = 0; # number of results found
$term = join(' ', @ARGV); # term for which to search

if ($term)
{
print "<p>Your search for <b>$term</b> resulted in the
following matches:</p><ol>";
foreach(@files = `ls -A $path`)
{
if (($page_content = `cat $path$_`) =~ /$term/i)
{
$no_results++;
print "<li style=\"padding: 4px;\"><a href=\"$path$_\">";
if ($page_content =~ /<title>(.*)<\/title>/i)
{
print $1;
}
else
{
print "Untitled";
}
print "</a><br />- ";
if ($page_content =~
/<meta name=[\'\"]description[\'\"] content=[\'\"](.*)[\'\"]/i)
{
print $1;
}
else
{
print "No description available";
}
print "</li>";
}
}
if ($no_results == 0)
{
print "</ol><p><b>Sorry, no results found.</b></p>";
}
else
{
print "</ol>";
}
}
# end script
Good luck... let me know how it works out for ya.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum