Click to See Complete Forum and Search --> : display message body only of eMail msg on server


dancerman
09-14-2004, 01:25 AM
I have the this org's web pages hosted as a directory on my web site, wanting to post the org's eMail to their members automatically on their webpage. I worked up a very simple script that reads the eMail text sent to my server and PRINTS it to a file which is displayed the web page as an #include file, dine and fandy, but I need to have a way to read only the message body test, Currently the headers are included, at the beginning of the text diplayed on the page.
I'm not sure that the user's ISP always sends the same number of lines in the header, so I suppose I need help with code that will read every thing AFTER the last header line?
Here's the header text:
####################################
From dancewithdora@comcast.net Sat Sep 11 17:55:57 2004
X-UIDL: ]HM!!DZb!!6p)!!`hk"!
Return-Path:
Received: from sccrmhc11.comcast.net (sccrmhc11.comcast.net [204.127.202.55])
by dcdancenet.com (8.12.10/8.12.10) with ESMTP id i8BLtukY006903
for ; Sat, 11 Sep 2004 17:55:57 -0400
Received: from sccrmhc11.comcast.net (localhost[127.0.0.1])
by comcast.net (sccrmhc11) with ESMTP
id <20040911215602011000s990e>; Sat, 11 Sep 2004 21:56:02 +0000
Received: from DenseFlood (pcp09566374pcs.rtchrd01.md.comcast.net[68.48.42.44])
by comcast.net (sccrmhc11) with SMTP
id <20040911215057011001u21fe>; Sat, 11 Sep 2004 21:51:03
+0000
X-Comment: AT&T Maillennium special handling code - c
From: "Dora Doolittle"
To:
Subject: Every Mon, Tues & Thurs - Learn & Dance with Debbie!
Date: Sat, 11 Sep 2004 17:50:58 -0400
Message-ID: <002d01c49849$6bea0570$1d02a8c0@DenseFlood>
MIME-Version: 1.0
Content-Type: multipart/alternative;
boundary="----=_NextPart_000_0029_01C49827.E4D13980"
X-Priority: 3 (Normal)
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook 8.5, Build 4.71.2173.0
Importance: Normal
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441
Status: U

This is a multi-part message in MIME format.

------=_NextPart_000_0029_01C49827.E4D13980
Content-Type: text/plain;
charset="utf-8"
Content-Transfer-Encoding: 8bit

####################################
#Message text starts with next line:
Dance with Dora
UCWDC Champion / Multiple Top Teacher Winner / Event Promoter
Weekly Dance Organizer / Swing & Hustle Pro Am Instructor / Coach
Blah Blah Blah, etc, and so on............
####################
Thanks!
mike

Jona
09-14-2004, 09:21 AM
Split it by "#" into an array and refer to the second index (1) of the array.

dancerman
09-14-2004, 10:19 AM
hmmmmmmmmmmmmm,
so the script, when the page is loaded,looks into the eMail directory on the server, reads and prints the text on the page. So how does this split get done?
The ### on the example of the eMail on the server included in the original request was added merely to separate the text from the headers for clarifcation in the request for help. They do not appear in the eMil text sent by the client.

NogDog
09-14-2004, 10:51 AM
[Never mind, thought I was in PHP forum and gave a possible PHP solution. :rolleyes: ]

Jona
09-14-2004, 10:58 AM
Originally posted by dancerman
The ### on the example of the eMail on the server included in the original request was added merely to separate the text from the headers for clarifcation in the request for help. They do not appear in the eMil text sent by the client.

So you're saying, there are no #'s in the output? Does anything come after the message?

dancerman
09-14-2004, 11:15 AM
Originally posted by Jona
So you're saying, there are no #'s in the output? Does anything come after the message?

Don't understand. Yes there are no ## in the eMail message.
I just put them there to show the headers separate from the text body.
I copied the ENTIRE text, all of it, that is on the server, there is nothing AFTER the messsage, don't know why you ask that as I want to get rid of the headers, all the lines down to the row of #######
so that what is displayed on the page is the rest of the lines (the eMail text body)

Jona
09-14-2004, 11:21 AM
Instead of outputting the whole thing at once, set it to a variable, then split it at "Content-Transfer-Encoding: 8bit\n" and output the second index of the returned array.

NogDog
09-14-2004, 11:42 AM
Maybe you should look at something like this: http://search.cpan.org/~vparseval/Mail-MboxParser-0.49/MboxParser/Mail/Body.pm

dancerman
09-14-2004, 12:45 PM
Originally posted by NogDog
Maybe you should look at something like this: http://search.cpan.org/~vparseval/Mail-MboxParser-0.49/MboxParser/Mail/Body.pm

THANKS for the reply!
I expect that the MboxParser is way more than what I think I need.
I mentioned the text file being an eMail to indicate that I have no control over the content.
the most I can get the client to do is add an eMail address to their list, so my task is to automate some method of having just the txt of the message, in plain txt form show up on a web page when users want to read the newsletter on line.
(Sure If I couild get them to post it on a form, NO PROBLEM!)
(Sure, If I could remember and devote the time, I could copy n' paste the text to a simple form, etc....)

Butt, as a not too knowledgeable hack at it webmaster, all I want to do is have the script that will print only the msg body text to a file, somehow not printing the header text.
... I know how to get the script to read and print the whole thing, but I do not know the code to get the script to only print part of the file, i.e. from some line down, that is, to only print some of the lines, in this case, <Only> everything AFTER the line:
"Content-Transfer-Encoding: 8bit"

CyCo
09-14-2004, 12:56 PM
Originally posted by dancerman
THANKS for the reply!
... I know how to get the script to read and print the whole thing, but I do not know the code to get the script to only print part of the file, i.e. from some line down, that is, to only print some of the lines, in this case, <Only> everything AFTER the line:
"Content-Transfer-Encoding: 8bit"
Why not post what you have and we will be able to modify the script to do as you wish.

dancerman
09-14-2004, 01:08 PM
Originally posted by CyCo
Why not post what you have and we will be able to modify the script to do as you wish.

Yes, OK! Thanks!

#!/usr/bin/perl
use Text::Wrap;

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

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

open(WRITE,">$filename2") || die "Can't open $filename2!\n";
print WRITE @lines;
close(WRITE);

# Return Link File
print "Location: $redirect\n\n";

Jona
09-14-2004, 03:17 PM
#!C:\Perl\bin\perl.exe

use strict;
use CGI qw(:cgi);
use CGI::Carp qw(fatalsToBrowser);

print header();

open("EMAIL", "email.txt") || die("Cannot open file: $!");
my @emailData = <EMAIL>;
my $data = "";

for my $k (@emailData){
$data .= $k;
}

my @newData = split("Content-Transfer-Encoding: 8bit\n", $data);

print nl2br($newData[1]);

sub nl2br {
(my $str) = @_;
$str =~ s/\n/<br>/g;
return $str;
}


Edit: I wrote that before I saw your latest reply, but it should still help.

CyCo
09-14-2004, 06:55 PM
Just use the script below to replace your original and you should be good to go.
Remember, the script relies on the line below in bold being just above the mail body, so if it's missing.... there's a problem:

Content-Transfer-Encoding: 8bit


#!/usr/bin/perl

use strict;
use Text::Wrap;

my $dat;
my $filename2 = "/usr/local/etc/httpd/htdocs/dancewithdebbie/email.txt";
my $filename = "/var/mail/debbienl";
my $redirect = "http://www.dcdancenet.com/dancewithdebbie/news2.shtml";

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

open(WRITE, ">$filename2") || die "Can't open $filename2!\n";
foreach (@lines) {
$dat .= $_;
}
my @newlines = split(/Content-Transfer-Encoding: 8bit\n/, $dat);
print WRITE $newlines[1];
close(WRITE);

# Return Link File
print "Location: $redirect\n\n";

dancerman
09-14-2004, 07:04 PM
Jona!
Thx so much for your response.
Unfortunately, I cannot get your code to work for me. Admittedly I'm not much good at perl, and have once again discovered that I know even less that I thought I knew.

I wonder if there is a way to insert a snip of code in the code I'm using that works very simply to discard the header text in the sample text file I suppied above and prints the text between the last line of unwanted text to the fist line of the rest of the unwanted text:
Content-Transfer-Encoding: 8bit

and

------=_NextPart_000_0029_01C49827.E4D13980

Don't see the need for anything fancy, having the text result be in plain txt is fine, keeping white space would be best.
don't know what modules my host has installed, strict likely not useful, etc. all I wasnt to do is clean up the text file which is replaced several times each week.

thx for your gracious attention,
mike

dancerman
09-14-2004, 07:16 PM
CyCo!
THANK YEW! THANK YEW!
Most excellent work!
The code you provided does EXACTLY what I had in mind!
(I uploaded and tested it)
Thing is, I goofed, in that I failed to mention it would be even better to shed extraneous text AFTER the mail body text segment.
Don't need the characters beginning with the following line which always comes after the plain text. Don't need/want anything beginning with this line....

------=_NextPart_000_0029_01C49827.E4D13980


Originally posted by CyCo
Just use the script below to replace your original and you should be good to go.
Remember, the script relies on the line below in bold being just above the mail body, so if it's missing.... there's a problem:

Content-Transfer-Encoding: 8bit


#!/usr/bin/perl

use strict;
use Text::Wrap;

my $dat;
my $filename2 = "/usr/local/etc/httpd/htdocs/dancewithdebbie/email.txt";
my $filename = "/var/mail/debbienl";
my $redirect = "http://www.dcdancenet.com/dancewithdebbie/news2.shtml";

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

open(WRITE, ">$filename2") || die "Can't open $filename2!\n";
foreach (@lines) {
$dat .= $_;
}
my @newlines = split(/Content-Transfer-Encoding: 8bit\n/, $dat);
print WRITE $newlines[1];
close(WRITE);

# Return Link File
print "Location: $redirect\n\n";