line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package SMS::Server::Tools; |
2
|
3
|
|
|
3
|
|
160652
|
use Log::Log4perl qw(:easy); |
|
3
|
|
|
|
|
131521
|
|
|
3
|
|
|
|
|
23
|
|
3
|
|
|
|
|
|
|
Log::Log4perl->easy_init($ERROR); |
4
|
|
|
|
|
|
|
|
5
|
3
|
|
|
3
|
|
2201
|
use warnings; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
97
|
|
6
|
3
|
|
|
3
|
|
17
|
use strict; |
|
3
|
|
|
|
|
11
|
|
|
3
|
|
|
|
|
176
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
SMS::Server::Tools - parse SMS Server Tools files |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 VERSION |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
Version 0.011 |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=cut |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our $VERSION = '0.012'; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 SYNOPSIS |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
Read file with SMS text message received by SMS Server Tools. |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
use SMS::Server::Tools; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
my $file = "/path/to/smsfile"; |
27
|
|
|
|
|
|
|
my $sms = SMS::Server::Tools->new({SMSFile => $file}); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
$sms->parse; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
my $sender_number = $sms->From; |
32
|
|
|
|
|
|
|
my $datetime_sent = $sms->Sent; |
33
|
|
|
|
|
|
|
my $datetime_received = $sms->Received; |
34
|
|
|
|
|
|
|
my $sms_text = $sms->Text; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head1 DESCRIPTION |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
SMS::Server::Tools provides an object-oriented interface to access sms files used by the SMS Server Tools. |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
The C send and receive short messages through GSM modems or mobile phones L. |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head1 SMS File Format Getter |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
SMS::Server::Tool parse the sms file and give the access to the following sms file fields. |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
$sms->Text; |
47
|
|
|
|
|
|
|
$sms->From; |
48
|
|
|
|
|
|
|
$sms->Sent; |
49
|
|
|
|
|
|
|
$sms->Received; |
50
|
|
|
|
|
|
|
$sms->IMSI; |
51
|
|
|
|
|
|
|
$sms->From_TOA; |
52
|
|
|
|
|
|
|
$sms->From_SMSC; |
53
|
|
|
|
|
|
|
$sms->Subject; |
54
|
|
|
|
|
|
|
$sms->Report; |
55
|
|
|
|
|
|
|
$sms->Alphabet; |
56
|
|
|
|
|
|
|
$sms->UDH; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
For the complete SMS file format used by SMS Server Tools see L |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=cut |
61
|
|
|
|
|
|
|
|
62
|
3
|
|
|
3
|
|
19
|
use base 'Class::Accessor'; |
|
3
|
|
|
|
|
25
|
|
|
3
|
|
|
|
|
3303
|
|
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
SMS::Server::Tools->mk_accessors(qw/ |
65
|
|
|
|
|
|
|
SMSFile Text From To Sent Received IMSI From_TOA From_SMSC Subject Report |
66
|
|
|
|
|
|
|
Alphabet UDH |
67
|
|
|
|
|
|
|
/); |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head1 METHODS |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head2 new |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
Create an new sms object. |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head2 SMSFile |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
Set path to sms file. |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head2 parse |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
The parse method read the sms file. |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=cut |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub parse { |
86
|
|
|
|
|
|
|
|
87
|
2
|
|
|
2
|
1
|
75
|
my $self = shift; |
88
|
|
|
|
|
|
|
|
89
|
2
|
50
|
0
|
|
|
10
|
( ERROR "No SMSFile defined!" and die ) unless $self->SMSFile; |
90
|
|
|
|
|
|
|
|
91
|
2
|
|
|
|
|
43
|
DEBUG "start slurping -> ", $self->SMSFile; |
92
|
|
|
|
|
|
|
|
93
|
2
|
|
|
|
|
58
|
my @sms = _slurp($self->SMSFile); |
94
|
|
|
|
|
|
|
|
95
|
2
|
|
|
|
|
15
|
DEBUG "finished slurping -> ", $self->SMSFile; |
96
|
|
|
|
|
|
|
|
97
|
2
|
|
|
|
|
33
|
DEBUG "start parsing"; |
98
|
|
|
|
|
|
|
|
99
|
2
|
|
|
|
|
18
|
chomp @sms; # remove last linefeed |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
# We find the index of the first void line, before the text |
102
|
2
|
|
|
|
|
10
|
my $idx = (grep { $sms[$_] =~ /^$/ } 0..$#sms)[0]; |
|
16
|
|
|
|
|
43
|
|
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
# We collect the multiple lines into text |
105
|
2
|
|
|
|
|
15
|
$self->{'Text'} = join("\n", @sms[$idx+1..$#sms]); |
106
|
|
|
|
|
|
|
|
107
|
2
|
|
|
|
|
15
|
DEBUG "parsed Text: $self->{'Text'}"; |
108
|
|
|
|
|
|
|
|
109
|
2
|
|
|
|
|
18
|
foreach (@sms[0..$idx-1]) { |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
# get sms header fields |
112
|
11
|
|
|
|
|
97
|
my ($key, $value) = split/: /; |
113
|
11
|
|
|
|
|
36
|
$self->{$key} = $value; |
114
|
11
|
|
|
|
|
54
|
DEBUG "parsed $key: $self->{$key}"; |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
2
|
|
|
|
|
20
|
DEBUG "finished parsing"; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head2 write |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
The write method write the sms file. |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=cut |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
sub write { |
128
|
|
|
|
|
|
|
|
129
|
1
|
|
|
1
|
1
|
538
|
my $self = shift; |
130
|
|
|
|
|
|
|
|
131
|
1
|
50
|
0
|
|
|
5
|
( ERROR "No SMSFile defined!" and die ) unless $self->SMSFile; |
132
|
1
|
50
|
0
|
|
|
19
|
( ERROR "No To defined!" and die ) unless $self->To; |
133
|
1
|
50
|
0
|
|
|
12
|
( ERROR "No Text defined!" and die ) unless $self->Text; |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
# check 160 chars of Text |
136
|
|
|
|
|
|
|
# SMS Server Tools can split large message |
137
|
1
|
|
|
|
|
16
|
my $text_length = length($self->Text); |
138
|
1
|
|
|
|
|
10
|
my $length_error = "Text has More than 160 chars!"; |
139
|
1
|
50
|
0
|
|
|
5
|
( ERROR $length_error and die ) unless ( $text_length <= 160 ); |
140
|
|
|
|
|
|
|
|
141
|
1
|
|
|
|
|
5
|
my $outfile = $self->SMSFile; |
142
|
|
|
|
|
|
|
|
143
|
1
|
50
|
|
|
|
73
|
open(SMS, '>', $outfile) or die "can't open $outfile"; |
144
|
|
|
|
|
|
|
|
145
|
1
|
|
|
|
|
5
|
print SMS "To: ", $self->To, "\n"; |
146
|
1
|
|
|
|
|
24
|
print SMS "\n"; |
147
|
1
|
|
|
|
|
4
|
print SMS $self->Text, "\n"; |
148
|
|
|
|
|
|
|
|
149
|
1
|
|
|
|
|
58
|
close(SMS); |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
sub _slurp { |
154
|
|
|
|
|
|
|
|
155
|
2
|
50
|
|
2
|
|
38
|
local( $/, @ARGV ) = ( wantarray ? $/ : undef, @_ ); |
156
|
2
|
|
|
|
|
210
|
return ; |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head1 AUTHOR |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
Thomas Lenz, C<< >> |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=head1 BUGS |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
167
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
168
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=head1 SEE ALSO |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
For more Information about SMS Server Tools follow this links. |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
L |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
L |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=head1 SUPPORT |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
perldoc SMS::Server::Tools |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
You can also look for information at: |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=over 4 |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
L |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
L |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=item * CPAN Ratings |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
L |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=item * Search CPAN |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
L |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
=back |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
Copyright 2009 Thomas Lenz, all rights reserved. |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
216
|
|
|
|
|
|
|
under the same terms as Perl itself. |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
=cut |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
1; # End of SMS::Server::Tools |