#-SMS Gateway over SMTP e-mail protocol:
#-(c)ode by Brodie Ponas
#-
#- User Socket, and Select Packages:
use IO::Socket;
use IO::Select;
use Socket;
use Net::SMTP;
#-first arg is ip address
#-2nd arg is port:
foreach $arg (@ARGV)
{
$_ = $arg;
#-Address:
if (m/\-addr\:(.+)/i)
{$address = $1;}
#-Port:
if (m/\-port\:(.+)/i)
{$port = $1;}
}
#-Setup sockets:
$ConnectionSocket = new IO::Socket::INET(Listen => 1, LocalHost => $address ,LocalPort => $port);
$SelectHandle = new IO::Select( $ConnectionSocket );
print "iLs SMS SMTP Gateway Listening...\r\n";
print "LocalAddr: $address\r\n";
print "LocalPort: $port\r\n";
$isRecvData = 0;
while(@Connections = $SelectHandle->can_read)
{
foreach $SocketHandle (@Connections)
{
#-Incomming Connection:
if($SocketHandle == $ConnectionSocket)
{
# Create a new socket
$NewClient = $ConnectionSocket->accept;
$SelectHandle->add($NewClient);
print "Client Connect ", $NewClient->peerhost, ":", $NewClient->peerport, "\r\n";
#-Tell mail client we are ready:
print $NewClient "220\r\n";
}
#-Established Connections:
else
{
# Process socket data:
#-We are recv'n the actual SMTP DATA field now, we don't want to send anythign back to the client:
if ($isRecvData == 1)
{
$Data = <$SocketHandle>;
$_ = $Data;
#-End of Data: reset flag: send OK:
if (m/\./i)
{
print $SocketHandle "250\r\n";
$isRecvData = 0;
}
print "$Data\r\n";
next;
}
#-Recv Stream:
$Data = <$SocketHandle>;
$_ = $Data;
if (m/QUIT/i)
{
print $SocketHandle "221\r\n";
$SelectHandle->remove($SocketHandle);
$SocketHandle->close;
}
#-Start of DATA:
elsif(m/DATA/i)
{
print $SocketHandle "250\r\n";
$isRecvData = 1;
}
#-Any other command we just give them an OK we just care about the data messaage and sender address for now:
else
{print $SocketHandle "250\r\n";}
print "$Data";
}
$Data = "";
}
}
####
------------------------------------
EHLO mailx05.tmomail.net
MAIL From:<1231231234@tmomail.net>
RCPT To:
DATA
RSET
QUIT
------------------------------------
####
------------------------------------
EHLO alnrmhc13.comcast.net
MAIL FROM:
RCPT TO:
DATA
Received: from myserver (c-67-168-213-7.hsd1.wa.comcast.net[67.168.213.7])
by comcast.net (alnrmhc13) with SMTP
id <20070509184137b1300do65ie>; Wed, 9 May 2007 18:41:37 +0000
From: "bponas"
To:
Subject: RE: COMCAST PLAINTEST SEND FROM SERVER TEST
Date: Wed, 9 May 2007 11:38:48 -0700
Message-ID:
MIME-Version: 1.0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
X-Priority: 3 (Normal)
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2910.0)
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527
Importance: Normal
In-Reply-To:
TADAH DOES MY STUFF WORK?
.
QUIT
-------------------------------------