[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

OOPs.. SNPP attachment



I guess in order for an attachment to be considered an attachment, one must
actually attach it. *smile*

Here it is.


daniel

#!/usr/bin/perl

use Net::SNPP;

##### TESTING SECTION

$opts->{'from'} = "Test";

# This message is within acceptable limits
$opts->{'message'} = "This is a test of the emergency broadcast " .
		     "system. In the event of an actual emergency " .
		     "run like mad.";

# This message is NOT within acceptable limits
#$opts->{'message'} = "This message wil be way too long to fit on my " .
#		     "text pager. The function should reject it " .
#		     "because of its length.  In order to make certain " .
#		     "that the message is long enough without being anal " .
#		     "and counting the number of characters I have used " .
#		     "I am just going to keep typing until I am very bored. " .
#		     "Okay... well... I am bored. That didn't last too " .
#		     "long. Well.. unfortunately, it wasn't long enough, " .
#		     "so here I am typing some more. I am certain this is " .
#		     "more than 300 charcters now, so I think it is " .
#		     "relatively safe to stop typing at this point.";



$tminfo{'fromlimit'} = "300"; 
$tminfo{'msglimit'} = "300";
$tminfo{'totlimit'} = "300";
$tminfo{'number'} = "1576921";

&send_snpp($tminfo, $opts, "pagemart.net:444");

print $opts{'errors'} . "\n";

exit;

##### END TESTING





sub send_snpp {

	# $server should be in the format "hostname.com:portnum" i.e.
	# pagemart.net:444
	#
	# 444 is the standard port for SNPP

	my ($tminfo, $opts, $server) = @_;
	
	# Create our SNPP object.
	my $snpp = Net::SNPP->new($server, Timeout => 60);

	# Check for an error
	if (! $snpp) {
		# Populate $opts to account for error and return
		push @{$opts->{'errors'}}, "There was an error contacting the user's text messaging service. The message was most likely not sent."; 
		return;
	} 

	# Since the lesser SNPP servers do not have a method
	# to send From information, and there is no reliable way
	# to test if a server is capable of accepting the information
	# we will just tack it on the beginning of the message.
	my $tmpmsg = "Frm: " . $opts->{'from'} . "; " . $opts->{'message'};

	if (length($tmpmsg) > $tminfo{'totlimit'}) {
		# Populate $opts to account for error and return
		push @{$opts->{'errors'}}, "The message you are sending exceeds the maximum message limit of " . $tminfo{'totlimit'} . " characters. Please try again. ";
		return;
	}
		

	
	my $res = $snpp->send(	Pager   => $tminfo{'number'},
				Message => $tmpmsg
				); 

	# Check for an error
	if (! $res) {
		# Populate $opts to account for error and return
		push @{$opts->{'errors'}}, "There was an error contacting the user's text messaging service. The message was most likely not sent. " . $snpp->message;
		return;
	} else {
		# Clean up and go home
		$snpp->quit;
		return;
	}

}