Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

My2Way Pager

by Mr. Muskrat (Canon)
on Apr 05, 2003 at 14:26 UTC ( [id://248293]=sourcecode: print w/replies, xml ) Need Help??
Category: E-mail Programs
Author/Contact Info /msg Mr. Muskrat
Description: Send an email to a Metrocall My2Way pager using their messaging gateway. See Metrocall My2Way for more details.
#!/usr/bin/perl
use strict;
use warnings;
use Tk;
use Tk::DialogBox;
use Tk::Balloon;
use HTTP::Request::Common qw(POST);
use LWP::UserAgent;

my $main = MainWindow->new(-title => "My2Way Pager");

$b = $main->Balloon();

my $menu_bar = $main->Frame(-relief => 'groove', -borderwidth => 3)->p
+ack(-side => 'top', -fill => 'x');

my $file_mb = $menu_bar->Menubutton(-text => 'File', -tearoff => 0)->p
+ack(-side => 'left');
$file_mb->command(-label => 'Exit', -command => sub { exit; });

my $help_mb = $menu_bar->Menubutton(-text => 'Help', -tearoff => 0)->p
+ack(-side => 'right');
$help_mb->command(-label => 'Help', -command => \&help_txt);
$help_mb->command(-label => 'About', -command => \&about_txt);

my $form = $main->Frame()->pack(-side => 'top', -fill => 'both', -padx
+ => 5, -pady => 5);

my $entries = $form->Frame()->pack(-side => 'left', -fill => 'y', -pad
+x => 5, -pady => 5);
my $to = $entries->Frame()->pack(-side => 'top', -fill => 'x', -padx =
+> 5, -pady => 5);
$to->Label(-text => 'To:')->pack(-side => 'left');
my $to_val = $to->Entry()->pack(-side => 'right');
$b->attach($to_val, -msg => 'Enter the email address (without @my2way.
+com)');

my $from = $entries->Frame()->pack(-side => 'top', -fill => 'x', -padx
+ => 5, -pady => 5);
$from->Label(-text => 'From:')->pack(-side => 'left');
my $from_val = $from->Entry()->pack(-side => 'right');
$b->attach($from_val, -msg => "Enter your name");

my $address = $entries->Frame()->pack(-side => 'top', -fill => 'x', -p
+adx => 5, -pady => 5);
$address->Label(-text => 'Email address:')->pack(-side => 'left');
my $address_val = $address->Entry()->pack(-side => 'right');
$b->attach($address_val, -msg => "Enter your complete email address");

my $subject = $entries->Frame()->pack(-side => 'top', -fill => 'x', -p
+adx => 5, -pady => 5);
$subject->Label(-text => 'Subject:')->pack(-side => 'left');
my $subject_val = $subject->Entry()->pack(-side => 'right');
$b->attach($subject_val, -msg => "Enter the subject of the email");

my $message = $form->Frame()->pack(-side => 'right', -fill => 'both', 
+-padx => 5, -pady => 5);
$message->Label(-text => 'Message:')->pack(-side => 'left');
my $message_val = $message->Text(-height => 5, -width => 40)->pack(-si
+de => 'right');
$b->attach($message_val, -msg => "Enter the text of your email here");

my $responses = $main->Frame()->pack(-side => 'top', -fill => 'both', 
+-padx => 5, -pady => 5);

my $responseT = $responses->Frame()->pack(-side => 'top', -fill => 'y'
+);
$responseT->Label(-text => 'Responses:')->pack(-side => 'top');
my $response_val_1 = $responseT->Entry()->pack(-side => 'right');
$b->attach($response_val_1, -msg => "A custom response");
my $response_val_2 = $responseT->Entry()->pack(-side => 'right');
$b->attach($response_val_2, -msg => "A custom response");
my $response_val_3 = $responseT->Entry()->pack(-side => 'right');
$b->attach($response_val_3, -msg => "A custom response");

my $responseB = $responses->Frame()->pack(-side => 'top');
my $response_val_4 = $responseB->Entry()->pack(-side => 'right');
$b->attach($response_val_4, -msg => "A custom response");
my $response_val_5 = $responseB->Entry()->pack(-side => 'right');
$b->attach($response_val_5, -msg => "A custom response");
my $response_val_6 = $responseB->Entry()->pack(-side => 'right');
$b->attach($response_val_6, -msg => "A custom response");


my $buttons = $main->Frame()->pack(-side => 'bottom');
my $sendbutton = $buttons->Button(-text => 'Send It!',
  -command => sub { submit_form() } )->pack(-side => 'top');

CenterWindow($main);

$to_val->focus();

MainLoop();

sub submit_form() {
  my $ua = LWP::UserAgent->new;
  push @{$ua->requests_redirectable}, 'POST';
  my $req = POST 'http://www.my2way.com/gw.wwwMsgSubmit', [
    gw_pin => $to_val->get,
    from_string => $from_val->get,
    subject_string => $subject_val->get,
    mesg_to_send => $message_val->get('1.0','end'),
    resp_a_string => $response_val_1->get,
    resp_b_string => $response_val_2->get,
    resp_c_string => $response_val_3->get,
    resp_d_string => $response_val_4->get,
    resp_e_string => $response_val_5->get,
    resp_f_string => $response_val_6->get,
    resp_route => 'Email',
    resp_addr => $address_val->get,
    confirm_receipt_str => "confirm_page_delivery",
    confirm_urgent_string => "",
    sub_name => "",
    max_msg_size => "    500",
    pager_type_features => "   E",
    user_features => "     695",
    form_type => "M2WY",
  ];

  my $res = $ua->request($req)->as_string;

  $res =~ s/.*(<html>.*)/$1/is;
  $res =~ s/<body bgcolor="#FFFFFF" onload=".*" leftmargin="0" topmarg
+in="0">/<body onload="javascript:document.xyzzy.submit();">/i;
  $res =~ s/<form /<form name="xyzzy" /is;
  $res =~ s/action="g/action="http:\/\/www.my2way.com\/g/is;
  
    
  open(HTML, ">", "confirm.html");
  print HTML $res;
  close(HTML);

  system('start confirm.html');
  sleep(15);
  unlink('confirm.html');
  exit;
}

sub about_txt {
  my $popup=$main->DialogBox(-title => "About", -buttons => ["OK"],);
  $popup->add("Label", -text => qq(My2Way Pager\nversion 0.3\nby Mr. M
+uskrat))->pack;
  $popup->Show;
}

sub help_txt {
 my $popup=$main->DialogBox(-title => "Help", -buttons => ["OK"],);
 $popup->add("Label", -text => qq(Hover the mouse pointer over a field
+ to get help.))->pack;
 $popup->Show;
}

sub CenterWindow {
# Don't remember where I got this subroutine but I use it often
# Args: (0) window to center
#       (1) [optional] desired width
#       (2) [optional] desired height
   my ($window, $width, $height) = @_;
   $window->idletasks;
   $width  = $window->reqwidth  unless $width;
   $height = $window->reqheight unless $height;
   my $x = int(($window->screenwidth  / 2) - ($width  / 2));
   my $y = int(($window->screenheight / 2) - ($height / 2));
   $window->geometry($width . "x" . $height . "+" . $x . "+" . $y);
}

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: sourcecode [id://248293]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (6)
As of 2024-04-19 07:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found