3 # Copyright (C) 2009 Thilo-Alexander Ginkel <thilo@ginkel.com>
4 # Copyright 2015 by Jan Vales <jan@jvales.net> (Someone <someone@somenet.org>)
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
23 <?xml version='1.0' encoding='UTF-8' standalone='yes' ?>
31 if (/^DateTime = (.*)/) {
33 } elsif (/^Number = "(.*)"/) {
35 } elsif (/^UDH = 050003(.*)(\p{XDigit}{2})/) {
38 } elsif (/^State = (.*)/) {
41 } elsif ($1 eq "Read") {
44 } elsif (/^Text\d+ = (.*)/) {
46 $encoded =~ s/([0-9A-F]{4})/&utf8(hex($1))/gei;
49 } elsif (/^$/ and defined($address)) {
51 print_message($address, $time, $type, $text);
56 $id = $address . $msgid;
58 if (defined($multipart{$id})) {
59 $msg = $multipart{$id};
61 $msg->{'date'} = $time;
62 $msg->{'address'} = $address;
63 $msg->{'type'} = $type;
66 if (defined($msg->{'parts'})) {
67 $parts = $msg->{'parts'};
70 $parts->{$seqno} = $text;
72 $msg->{'parts'} = $parts;
73 $multipart{$id} = $msg;
85 # output any multipart messages
86 foreach $msg (values %multipart) {
88 my $parts = $msg->{'parts'};
89 foreach $seqno (sort keys %$parts) {
90 $body .= $parts->{$seqno};
92 print_message($msg->{'address'}, $msg->{'date'}, $msg->{'type'}, $body);
97 sub utf8 { local($_)=@_;
98 return $_ < 0x80 ? chr($_) :
99 $_ < 0x800 ? chr($_>>6&0x3F|0xC0) . chr($_&0x3F|0x80) :
100 chr($_>>12&0x0F|0xE0).chr($_>>6&0x3F|0x80).chr($_&0x3F|0x80);
104 my ($address, $date, $type, $text) = @_;
105 $text = encode_entities($text, "<>&'\"");
106 $text =~s/\n/ /g;
108 print "<sms protocol=\"0\" address=\"" . encode_entities($address, "<>&'\"") . "\" date=\"${date}000\" type=\"$type\" subject=\"null\" body=\"".$text."\" toa=\"null\" sc_toa=\"null\" service_center=\"\" read=\"1\" status=\"-1\" />\n";