#!/usr/bin/perl -w
#
#
$| = 1;  # autoflush

use strict;
use diagnostics;
use LWP::Simple qw( get );
use URI ();

my ($Verbose)="F";
my ($LogFile)="/tmp/Pager.log";

my ($From);
my ($Subject)="  ";
my ($Message)="  ";
my ($Capture)="F";
my ($Phone)=shift;
chomp(my ($Date)=`date`);

#(undef, $From)=split(' ',<>);
#
#while(<>) {
#  chomp;
#  print OUTPUT "\$_ :$_:\n" if ($Verbose eq "T");
##  (undef, $From)=split(' ') if (/^Return-path:/);
#  (undef, $Subject)=split(' ') if (/^Subject:/);
#  $Message.=" $_" if ($Capture eq "T");
#  $Capture="T" if (/^$/);
#}
#
#$From =~ s/( |\<|\>)+//g;
#$Message =~ s/ +/ /g;

#
# Manually set while debugging to eliminate the possibility of bad data from email
#
$Phone="6787581213";
$From="Rob";
$Subject="again";
$Message="Bah";

open(OUTPUT, ">>$LogFile") || die "Can't open $LogFile :$!:\n";
print OUTPUT "Date :$Date:\n";
print OUTPUT "  \$Phone :$Phone:\n";
print OUTPUT "  \$From :$From:\n";
print OUTPUT "  \$Subject :$Subject:\n";
print OUTPUT "  \$Message :$Message:\n";
print OUTPUT "  \n";

## Adjust inside the qq{} as necessary . . .
my $u = URI->new("http://messaging.nextel.com/cgi/iPageExt.dll", [ "http" ] );
#$u->scheme( "http" );
$u->query_form( cmd        => 'sendPage',
                twoWayPTNs => $Phone,
                ignore     => 'tdtext',
                from       => $From,
                subject    => $Subject,
                message    => $Message);
my ($ReturnText)=get( $u ) or die "Couldn't submit URL :$!:\n";

print OUTPUT "URI returned: $ReturnText\n";
print OUTPUT "  \n";
close(OUTPUT);


#my ($URL)="http://messaging.nextel.com/cgi/iPageExt.dll?cmd=sendPage\\&twoWayPTNs=$Phone\\&from=$From\\&subject=$Subject\\&message=Message";
#my ($Command)="/usr/local/bin/lwp-request http://messaging.nextel.com/cgi/iPageExt.dll?cmd=sendPage\\&twoWayPTNs=$Phone\\&from=$From\\&subject=$Subject\\&message=Message";
#my ($Command)="/usr/bin/wget http://messaging.nextel.com/cgi/iPageExt.dll?cmd=sendPage\\&twoWayPTNs=$Phone\\&from=$From\\&subject=$Subject\\&message=Message -O /dev/null";
#my ($Command)="/usr/bin/wget $URL";
#print "\$Command :$Command:\n";
#my ($tmp)=`$Command > /dev/null`;

exit 0;



