Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jun 2003
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    automatically scanning the subjects of email while on the server

    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.

  • #2
    New Coder
    Join Date
    Dec 2002
    Location
    Central New York
    Posts
    87
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.
    Code:
    #! /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.
    Timothy Boronczyk


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •