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 ;).
< Scripts starts here > #!/usr/bin/perl use Mysql; undef $/; $incoming = <>; @data = $incoming; ($dbh) = Mysql->connect('localhost','bushmail','root',''); ($inHeader, $inMessage) = split(/\n\n/,$incoming,2); chop $inMessage; @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:/; } #### $inMessage is the var. that contains the message that I'm interested in. ## Write email to DB my ($sql) = "insert into emails (to_mail,from_mail,subject,type,new,date) values ('$to','$from','$subject','in','y','$date' my ($sth) = $dbh->query($sql); < Scripts Ends here > This is what the email looks like. <Email Message> ----------------- >From [EMAIL PROTECTED] Fri Nov 8 17:53:05 2002 Return-Path: <[EMAIL PROTECTED]> Received: from Tink ([10.0.0.1]) by localhost.localdomain (8.12.6/8.12.6) with SMTP id gA8Fr5r8007705 for <[EMAIL PROTECTED]>; Fri, 8 Nov 2002 17:53:05 +0200 Message-ID: <002d01c2872e$5eaa2710$0100000a@Tink> From: "Steph" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Subject: Email Test..... Date: Fri, 8 Nov 2002 15:54:34 +0200 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_002A_01C2873F.2226E920" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 This is a multi-part message in MIME format. ------=_NextPart_000_002A_01C2873F.2226E920 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable #### < Needs to extract everything below up until END > #### This is an email test. Testing 1234 Kind Regards Blah BLah #### < END > #### ------=_NextPart_000_002A_01C2873F.2226E920 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META http-equiv=3DContent-Type content=3D"text/html; = charset=3Diso-8859-1"> <META content=3D"MSHTML 6.00.2800.1106" name=3DGENERATOR> <STYLE></STYLE> </HEAD> <BODY bgColor=3D#ffffff> <DIV><FONT face=3DArial size=3D2>This is an email test.</FONT></DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV><FONT face=3DArial size=3D2>Testing 1234</FONT></DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV><FONT face=3DArial size=3D2>Kind Regards</FONT></DIV> <DIV><FONT face=3DArial size=3D2>Blah BLah</FONT></DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV> </DIV></BODY></HTML> ------=_NextPart_000_002A_01C2873F.2226E920--