Stephan Viljoen wrote: > > Hi , I need to write an email that will port incomming emails directly > to a Mysql DB. I'm running Linux with sendmail. Here's what I did so far > , I'm forwarding all incoming emails to an alias that's piped to the perl > script. Everything works fine , my only problem is to extract the message > body properly. Doing the headers (To,From,Subject , etc) was easy . The > problem comes in to remove all the HTML and other unused stuff from the > message body. Help will be apreaciated. I'm only starting out doing > programing in any form for a few weeks now. So please don't laught to hard
CPAN has modules that will strip HTML and handle MIME attachments. http://search.cpan.org > < Scripts starts here > > #!/usr/bin/perl use warnings; use strict; > use Mysql; > > undef $/; Probably better to do: local $/; > $incoming = <>; > @data = $incoming; This is the same as: $data[0] = $incoming; Are you even using @data anywhere? > ($dbh) = Mysql->connect('localhost','bushmail','root',''); > > ($inHeader, $inMessage) = split(/\n\n/,$incoming,2); Probably better as: my ( $inHeader, $inMessage ) = split /\n\n+/, $incoming, 2; And split on two or more newlines, so $inMessage doesn't start with a newline. > chop $inMessage; chop() is rarely used in Perl5, better to use chomp(). > @headers = split(/\n/,$inHeader); > foreach $header (@headers) { > ($junk, $subject) = split(/: /,$header) if $header =~ >m/^Subject:/; > ($junk, $from) = split(/: /,$header) if $header =~ m/^From:/; > ($junk, $to) = split(/: /,$header) if $header =~ m/^To:/; > ($junk, $date) = split(/: /,$header) if $header =~ m/^Date:/; > } There is no need for a loop here: my ($subject) = $inHeader =~ /^Subject:\s*(.*)/im; my ($from) = $inHeader =~ /^From:\s*(.*)/im; my ($to) = $inHeader =~ /^To:\s*(.*)/im; my ($date) = $inHeader =~ /^Date:\s*(.*)/im; John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]