The script will filter and slice any standard input and forward it to GSM phone as SMS, via the WWW-SMS gateway. It
is very Croatian specific, with primitive filtering, but it works. I wish the gateway itself would work as efficiently. I modified it a bit and translated from my original version, but I think it can be easily tailored to suit anyone's needs. You can use "Send SMS to UK phones (.pm package) by SuperCruncher" to connect to the WWW gateway.
The script can be used from procmail like
:0
| formail -I "" | vip <options>
to send the body or
| formail -X <headers> | vip <options>
to send specific headers (see man formail).
Vip is, of course, named after my GSM operator. :)
#!/usr/local/bin/perl
use Getopt::Std;
getopts("s:l:d:Ca", \%args);
if (-t STDIN && -t STDOUT) {
print << "DO_KRAJA";
vip v0.06 - a tool to forward e-mail to GSM mobile phones
vip [-Ca] [-s max_sms] [-l max_length] [-d sleep/s]
Options:
-s : max. number of SMS messages to generate (default 5, all: 0 or -a
+)
-l : max. message length in characters (136)
-d : number of seconds to sleep after sending each message (10)
-C : convert text to lowercase (a friend of mine screams a lot :)
-a : send whole mail (equivalent to -s 0, overrides -s)
Input comes from STDIN.
To use from procmail (sends mail body to the script):
:0
| formail -I "" | vip -s 5 -l 136
Sends From and Subject fields in max. 1 SMS message:
:0
| formail -X"From:" -X "Subject:" | vip -s 1
DO_KRAJA
exit;
};
$cookie = ""; # <this is the cookie to send to www<->sms gateway>
$authorization = ""; # <again, depends on the gateway>
# See Send SMS to UK phones (.pm package) by SuperCruncher for more
$broj = "0123456";
$ext = "+38598";
$max_web_length = 140;
$max_sms = defined ($args{s}) ? $args{s} : 5;
if (defined ($args{a})) {$max_sms = 0;};
$max_len = defined ($args{l}) ? ( ($args{l}<=136) ? $args{l} : 136 ) :
+ 136;
$dream = defined ($args{d}) ? $args{d} : 10;
$message = "";
# This is to skip reply and sigs and ...
while (<>) {
chomp;
next if /^$/;
next if /^>/;
next if /^=>/;
last if /^====/;
last if /^--.*/;
last if /^__.*/;
# ovo generalno konvertira iso8859-2 varijante (Micro i ostali)
tr/èæ~Z~^ðÈÆ~JÐ~N¹¾©®/ccszdCCSZDszSZ/;
# ovo generalno konvertira Smiljanov encoding
s/=E8/c/g;
s/=E6/c/g;
s/=B9/s/g;
s/=A9/S/g;
s/=BE/z/g;
s/=20/ /g;
s/=//g;
push (@tekst,split(/\s+/,$_));
}
$final_message = "";
if ( @tekst ) {
foreach $word (@tekst) {
$word =~ s/([a-z?!\.])\1{2,}/$1/ig; # ubij uzvike tipa AAAAA,
+!!!!
$word =~ s/\s+//g; # ubij niz spejsova
$word =~ s/(http|ftp):\/\/.*/URL/g; # ubij URLove
next if ($word eq "");
next if ($word =~ m/^(,|\.|;)/);
if (defined ($args{C})) { $word = lc($word) };
$final_message .= $word . " ";
}
chop ($final_message);
use POSIX;
@final_text = unpack("A$max_len" x (ceil(length($final_message)/$max_l
+en)), $fin
al_message);
$total_lines = @final_text;
$current = 1;
for $line (@final_text) {
$count_line = "$current"."/".$total_lines;
send_as_sms($count_line,$line);
last if ($current == $max_sms);
$current++;
}
}
sub send_as_sms {
my ($count_line,$poruka) = @_;
$poruka = $count_line." ".$poruka;
$len = length($poruka);
# Uncomment this to see what will be sent
# print $poruka."\n\n";
$left = $max_web_length - $len;
$message = $poruka;
# See Send SMS to UK phones (.pm package) by SuperCruncher for more...
use HTTP::Request::Common;
use LWP::UserAgent;
my $ua = LWP::UserAgent->new;
my $request = POST <url-to-send-sms>,
[ ext => $ext,
subject => $broj,
body => $message,
# .........
# ......... parameters of POST request...
] ;
$request->header('Referer' => <trick the webserver> );
$request->header('Host' => <hostname - HTTP/1.1> );
$request->header('Authorization' => $authorization);
$request->header('Cookie' => $cookie);
$response = $ua->request($request);
# sleep for a while...
sleep($dream);
}