perlnewbie9292
Programmer
Hello I have the following script with I have been pulling my hair out trying to get the second part working. Please keep in mind I am pretty new to Perl. I am having trouble figuring out how to capture the lines which contain the string "RCPT TO" and add each of the captured lines to the correct section below the To: field. One file will contain sometimes contain one or more data sections. In this example it contains three data sections then what the script does is separates them into three sections, now I want to append all the RCPT lines to it's corresponding sections. This is code I use on a box which saves input from the web. For some reason every time I try to match using the regex for the RCPT line it captures them but then my buffer is empty and only contains the RCPT data. Thanks for the help in advanced.
Keep in mind that these are not email messages just data that users submit, so using a cpan mail module won't do the trick which is why I am taking this route.
So all in all with the code that I have the only additional thing that I am having trouble doing is grabbing the line that starts with ^RCPT TO: for each DATA section and appending it right below the To: line in for each corresponding section.
Thanks for the help!
Using one of the messages as a sample (This is the FIRST message from the __DATA__ section) before and after this is what I am trying to accomplish.
Keep in mind that these are not email messages just data that users submit, so using a cpan mail module won't do the trick which is why I am taking this route.
So all in all with the code that I have the only additional thing that I am having trouble doing is grabbing the line that starts with ^RCPT TO: for each DATA section and appending it right below the To: line in for each corresponding section.
Thanks for the help!
Code:
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
my $lineBufferStatus = 0;
my @rcptBuffer = ();
my @linesBuffer = ();
my $msgUpdateCnt = 0;
while (<DATA>) {
if ( $_ =~ /^DATA(?:\n|\r\n)$/ ) {
print "In second If statement DATA if statement\n";
@linesBuffer = ();
$lineBufferStatus = 0;
}
elsif ( $_ =~ /^\.(?:\n|\r\n)$/ ) {
if ( int(@linesBuffer) > 0 ) {
while( int(@linesBuffer) > 0 ) {
print shift(@linesBuffer);
}
print "\r\n.\r\nQUIT\r\n";
$msgUpdateCnt++;
}
$lineBufferStatus = 1;
}
elsif ( $lineBufferStatus == 0 ) {
push( @linesBuffer, $_ );
}
}
if ( int(@linesBuffer) > 0 ) {
my $perMsgRcptBufCnt = 0;
while( int(@linesBuffer) > 0 ) {
print shift(@linesBuffer);
}
print "\r\n.\r\nQUIT\r\n";
$msgUpdateCnt++;
}
if ( $msgUpdateCnt == 1 ) {
print "---------------------EQUALS 1--------------------\n";
}
elsif ( $msgUpdateCnt > 1 ) {
print "---------------------EQUALS 2--------------------\n";
}
__DATA__
EHLO testdomain.com
MAIL FROM:<outsideuser01@outdomain.com> SIZE=1016 BODY=7BIT
RCPT TO:<testuser01@testdomain.com>
RCPT TO:<testuser02@testdomain.com>
DATA
Received: from 1.1.1.1(helo=mvastnlufgt.mgrjofpxydauvu.info)
by with esmtpa (Exim 4.69)
(envelope-from )
id 1MM6HB-1114fm-3T
for testuser01@testdomain.com; Sun, 9 Jan 2011 23:07:59 +0100
From: "outsideuser01" <outsideuser01@outdomain.com>
To: <testuser01@testdomain.com>
Subject: Re: good evening
Date: Sun, 9 Jan 2011 23:07:59 +0100
MIME-Version: 1.0
Content-Type: multipart/alternative;
boundary="----=_ppstll_21_19_24"
X-Priority: 3
X-Mailer: choakmps.33
Message-ID: <5C74A867.4001970@aclighting.com>
------=_ppstll_21_19_24
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
H i website: [URL unfurl="true"]http://canadianph.tz=[/URL]
hzvebp.ajwcd.ru - CanadianPharmacy
------=_ppstll_21_19_24
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">
<STYLE></STYLE>
</HEAD>
<BODY>
H i <br>
website: [URL unfurl="true"]http://canadianph.tzhzvebp.ajwcd.ru[/URL] - CanadianPharmacy =
</BODY></HTML>
------=_ppstll_21_19_24--
.
RSET
MAIL FROM:<Megan@bankofdeerfield.com> SIZE=1016 BODY=7BIT
RCPT TO:<testuser36@testdomain.com>
RCPT TO:<testuser22@testdomain.com>
RCPT TO:<testuser99@testdomain.com>
DATA
Received: from mdmcfntioehaoqtcmjdmjmcm (192.168.1.33) by wonderware.com (80.149.49.194) with Microsoft SMTP Server id 8.0.685.24; Sun, 9 Jan 2011 23:08:07 +0100
Message-ID: <4D2A2627.204070@pacunion.com>
Date: Sun, 9 Jan 2011 23:08:07 +0100
From: "Megan" <Megan@bankofdeerfield.com>
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.9) Gecko/20100921 Thunderbird/3.1.4
MIME-Version: 1.0
To: <testuser36@testdomain.com>
Subject: good morning
Content-Type: multipart/alternative;
boundary="------------02070800106050608090806"
X-Priority: 3
X-Mailer: choakmps.33
Message-ID: <5C74A867.4001970@aclighting.com>
------=_ppstll_21_19_24
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Hi website: [URL unfurl="true"]http://canadianp=[/URL]
kerur.ru - CanadianPharmacy
------=_ppstll_21_19_24
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">
<STYLE></STYLE>
</HEAD>
<BODY>
H i <br>
website: [URL unfurl="true"]http://canadianp.kerur.ru[/URL] - GermanPharmacy =
</BODY></HTML>
------=_ppstll_21_19_24--
.
RSET
MAIL FROM:<robertson@roberts.com> SIZE=9916 BODY=7BIT
RCPT TO:<testuser2937@testdomain.com>
RCPT TO:<testuser22@testdomain.com>
DATA
Received: from testdomains (172.12.223.44) by wonderware.com (32.34.49.194) with Microsoft 23:08:07 +0100
Message-ID: <4D2A2627.204070@pacunion.com>
Date: Sat, 8 Jan 2011 17:18:27 +0100
From: "Megan" <robertson@roberts.com>
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.9) Gecko/20100921 Thunderbird/3.1.4
MIME-Version: 1.0
To: <testuser2937@testdomain.com>
Subject: morning
Content-Type: multipart/alternative;
boundary="------------02070800106050608090806"
X-Priority: 3
X-Mailer: choakmps.33
Message-ID: <5C74A867.4001970@aclighting.com>
------=_ppstll_21_19_24
Content-Type: text/plain;
.
RSET
Using one of the messages as a sample (This is the FIRST message from the __DATA__ section) before and after this is what I am trying to accomplish.
Code:
--------THIS IS THE CURRENT OUTPUT--------
Received: from 1.1.1.1(helo=mvastnlufgt.mgrjofpxydauvu.info)
by with esmtpa (Exim 4.69)
(envelope-from )
id 1MM6HB-1114fm-3T
for testuser01@testdomain.com; Sun, 9 Jan 2011 23:07:59 +0100
From: "outsideuser01" <outsideuser01@outdomain.com>
To: <testuser01@testdomain.com>
Subject: Re: good evening
Date: Sun, 9 Jan 2011 23:07:59 +0100
MIME-Version: 1.0
Content-Type: multipart/alternative;
boundary="----=_ppstll_21_19_24"
X-Priority: 3
X-Mailer: choakmps.33
Message-ID: <5C74A867.4001970@aclighting.com>
------=_ppstll_21_19_24
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
H i website: [URL unfurl="true"]http://canadianph.tz=[/URL]
hzvebp.ajwcd.ru - CanadianPharmacy
------=_ppstll_21_19_24
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">
<STYLE></STYLE>
</HEAD>
<BODY>
H i <br>
website: [URL unfurl="true"]http://canadianph.tzhzvebp.ajwcd.ru[/URL] - CanadianPharmacy =
</BODY></HTML>
------=_ppstll_21_19_24--
.
--------THIS IS THE DESIRED OUTPUT ( I have captured both
Received: from 1.1.1.1(helo=mvastnlufgt.mgrjofpxydauvu.info)
by with esmtpa (Exim 4.69)
(envelope-from )
id 1MM6HB-1114fm-3T
for testuser01@testdomain.com; Sun, 9 Jan 2011 23:07:59 +0100
From: "outsideuser01" <outsideuser01@outdomain.com>
To: <testuser01@testdomain.com>
To: <testuser01@testdomain.com> *********-----APPENDED RCPT LINE HERE------**********
To: <testuser02@testdomain.com> *********-----APPENDED RCPT LINE HERE------**********
Subject: Re: good evening
Date: Sun, 9 Jan 2011 23:07:59 +0100
MIME-Version: 1.0
Content-Type: multipart/alternative;
boundary="----=_ppstll_21_19_24"
X-Priority: 3
X-Mailer: choakmps.33
Message-ID: <5C74A867.4001970@aclighting.com>
------=_ppstll_21_19_24
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
H i website: [URL unfurl="true"]http://canadianph.tz=[/URL]
hzvebp.ajwcd.ru - CanadianPharmacy
------=_ppstll_21_19_24
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">
<STYLE></STYLE>
</HEAD>
<BODY>
H i <br>
website: [URL unfurl="true"]http://canadianph.tzhzvebp.ajwcd.ru[/URL] - CanadianPharmacy =
</BODY></HTML>
------=_ppstll_21_19_24--
.