File: email2smssend

package info (click to toggle)
smssend 3.4-2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 2,232 kB
  • ctags: 114
  • sloc: sh: 11,314; ansic: 2,368; perl: 104; makefile: 58
file content (157 lines) | stat: -rwxr-xr-x 4,434 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#!/usr/bin/perl
#
# email2smssend - send your emails to your GSM with smssend
# Copyright (C) 2000 Jean-Baptiste Sarrodie (jaiguru@maldoror.freesurf.fr)
#
# Security problem fixed 2002-03-11 thanks to Ruslan Ermilov
#
# Security problem fixed again (hopefully better) 2002-05-23 by Michal Cihar
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#

use strict;

# Configure the name and path of smssend
my $sms_bin = "smssend";

# Don't edit after here
my $version = "0.4.2";
my $header = 1;
my $line;
my $is_after;
my ($from, $subject, $from_subject);
my ($message, @tmp_messages, @messages);
my ($limit_size, $limit_sms);
my ($show_index, $reverse, $diff, $opt);
my ($total_nb, $cpt, $prepend, @before, @after);
my (@args);

# Display usage help.
sub Usage {
        print <<eof;
Usage: email2smssend [options] -- [smssend options]
  -ms, --msg-size       Maximum number of characters per message.
  -mm, --max-msg        Maximum number of SMS by email (less than 9).
  -i, --index           Prefix the sms with sequence number
  -r, --reverse         Send SMS in reverse order (some providers need it)
  -h, --help            Display this help message.
  -V, --version         Display version number.
  smssend options       See "smssend --help" for list of options.

eof
	exit;
}

# Assign some vars
$show_index = 0;
$reverse = 0;
$diff = 1;

# Check command line args
Usage if (scalar(@ARGV) == 0);

while ($opt = shift (@ARGV)) {
	if ($opt eq "-h" or $opt eq "--help") {
		Usage;
	} elsif ($opt eq "-ms" or $opt eq "--msg-size") {
		$limit_size = shift (@ARGV);
		die "msg_size need to be an integer.\n" if (!($limit_size =~/^[0-9]+$/));
	} elsif ($opt eq "-mm" or $opt eq "-max-msg") {
		$limit_sms = shift (@ARGV);
		die "max_msg need to be an integer.\n" if (!($limit_sms =~/^[0-9]+$/));
		die "max_msg must be less than 9.\n" if ($limit_sms > 9);
	} elsif ($opt eq "-i" or $opt eq "--index") {
		$show_index = 1;
	} elsif ($opt eq "-r" or $opt eq "--reverse") {
		$reverse = 1;
	} elsif ($opt eq "-V" or $opt eq "--version") {
		print <<eof;
email2smssend version $version

Copyright (C) 2000 Jean-Baptiste Sarrodie.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE,
to the extent permitted by law.
eof
		exit;
	} elsif ($opt eq "--") {
		last;
	} else {
		die "Unrecognize option: $opt\n";
	}
}

# Check msg_size and msg_max
die "msg_size needs to be defined.\n" if (! defined($limit_size));
die "max_msg needs to be defined.\n" if (! defined($limit_sms));

# Now, options in @ARGV are for smssend

while (<STDIN>) {
	chomp ($line = $_);

	if ($header == 1) {
        	if ($line =~ /^From:.*$/) {
			$from = (split (/^From: /, $line))[1];
		} elsif ($line =~ /^Subject:.*$/) {
			$subject = (split (/^Subject: /, $line))[1];
		} elsif ($line =~ /^$/) {
			$header = 0;
			$from_subject = "From: $from - Subject: $subject - ";
		}
	} else {
		$message .= "$line ";
	}
}

$limit_size -= 5 if ($show_index == 1);

(@tmp_messages) = (split (/(.{$limit_size})/, $from_subject . $message));
foreach (@tmp_messages) {
	if (!($_ =~ /^ *$/) && ($limit_sms-- > 0)) {
		push (@messages, $_);
	}
}

# Search if a parameter is "--"
$is_after = 0;
while ($opt = shift (@ARGV)) {
    if ($opt eq "--") { $is_after = 1; }
    if ($is_after) {
        push (@after, $opt);
    } else {
        push (@before, $opt);
    }
}
        
# Initialize cpt
$total_nb = scalar(@messages);
$cpt = 1;

if ($reverse == 1) {
    @messages = reverse (@messages) if ($reverse == 1);
    $cpt = $total_nb;
    $diff = -1;
}

foreach (@messages) {
    $prepend = $cpt . "/$total_nb: " if ($show_index == 1);
    $cpt += $diff;
    @args = ($sms_bin, @before, $prepend.$_, @after);
    system(@args);
}