Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Text Extraction form the Last message in a sever mail file 1

Status
Not open for further replies.

slolerner

Programmer
Sep 15, 2004
9
US
I have to display a customer's latest eMail drivel on her web page, which I access on my server's mail folder. The code below slpits the text, printing out the body text from the headers and the html mess after, etc.

Thing is, each new message is appended to the file so that I need to get to the LAST messsage to do the extraction.
How do I instruct the scrip to find the LAST instance of the text for splitting?
##################################
Code:
#!/usr/bin/perl

$filename2 = "/usr/local/etc/httpd/htdocs/dancewithdebbie/email.txt";
$filename = "/var/mail/debbienl";
$redirect = "[URL unfurl="true"]http://www.dcdancenet.com/dancewithdebbie/news2.shtml";[/URL]

open(FILE,"$filename");
@lines = <FILE>;
close(FILE);

$start=0;$finish=0;
open(WRITE,">$filename2") || die "Can't open $filename2!\n";
foreach (@lines) {
  chomp;    #now you can ignore the \n
  if ($_ eq "Dance with Debbie") {
     $start=1;
  }
  if ($_ eq "Content-Type: text/html;") {
     last;
  }
  if ($start ==1)  {
    print WRITE "$_\n"; #add it back in
  }
}
close (WRITE);
print "Location: $redirect\n\n";


I started with nothing, and have most of it left
 
There are some possibilities. One is to use indexes:
Code:
#!/usr/bin/perl -w
use strict;

my @lines = qw(this is the text);

my $linenumbers = @lines;
my $lastone = $lines[$linenumbers-1];

print $lastone;
Another one is using list functions:
Code:
#!/usr/bin/perl -w
use strict;

my @lines = qw(this is the text);

my $lastone = pop @lines;

print $lastone2;
and probably others can come up with other ideas...
 
Thanks!
Part of my problem is that the user sends eMail messages of varying length, and there's no way to control their ISP's header content line number and so a line numbe approach won't work will it?

I'm a slolerner, for sure, cause I don't immediately see how your second suggestion will work.
the eMail storage directory on my server holds each alias's incoming data in one big file, leaving it to the eMail client to separates the messages by the headers, etc.
Since
my goal is to have a script open this folder in that eMail directory, which has a whole pile of messages, all in one long text file, last one appended to the bottom (or end) of the file, grab the file, strip off all the text ahead of the message body I want (which will be in the last message in the file), and also strip off useless text after the part I want. There is text that appears in every message, right before and right after the part I want, so these "key" lines my appear more than once in the file of all these messages, but it's the last pair that are to be used to split out or extract the desired text.
Thanks
mike


Before you criticize anyone, walk a mile in their shoes...
That way, when you criticize them, you're a mile away and, you have their shoes
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top