SMS::Server::Tools - parse SMS Server Tools files


SMS-Server-Tools documentation Contained in the SMS-Server-Tools distribution.

Index


Code Index:

NAME

Top

SMS::Server::Tools - parse SMS Server Tools files

VERSION

Top

Version 0.011

SYNOPSIS

Top

Read file with SMS text message received by SMS Server Tools.

    use SMS::Server::Tools;

    my $file = "/path/to/smsfile";
    my $sms  = SMS::Server::Tools->new({SMSFile => $file});

    $sms->parse;

    my $sender_number      = $sms->From;
    my $datetime_sent      = $sms->Sent;
    my $datetime_received  = $sms->Received;
    my $sms_text           = $sms->Text;

DESCRIPTION

Top

SMS::Server::Tools provides an object-oriented interface to access sms files used by the SMS Server Tools.

The SMS Server Tools send and receive short messages through GSM modems or mobile phones http://smstools.meinemullemaus.de/.

SMS File Format Getter

Top

SMS::Server::Tool parse the sms file and give the access to the following sms file fields.

    $sms->Text;
    $sms->From;    
    $sms->Sent;
    $sms->Received;
    $sms->IMSI;
    $sms->From_TOA;    
    $sms->From_SMSC;
    $sms->Subject;
    $sms->Report;
    $sms->Alphabet;
    $sms->UDH;

For the complete SMS file format used by SMS Server Tools see http://smstools.meinemullemaus.de/fileformat.html

METHODS

Top

new

Create an new sms object.

SMSFile

Set path to sms file.

parse

The parse method read the sms file.

write

The write method write the sms file.

AUTHOR

Top

Thomas Lenz, <tholen at cpan.org>

BUGS

Top

Please report any bugs or feature requests to bug-sms-server-tools at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=SMS-Server-Tools. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SEE ALSO

Top

For more Information about SMS Server Tools follow this links.

http://smstools.meinemullemaus.de/

http://smstools3.kekekasvi.com/

SUPPORT

Top

You can find documentation for this module with the perldoc command.

    perldoc SMS::Server::Tools




You can also look for information at:

* RT: CPAN's request tracker

http://rt.cpan.org/NoAuth/Bugs.html?Dist=SMS-Server-Tools

* AnnoCPAN: Annotated CPAN documentation

http://annocpan.org/dist/SMS-Server-Tools

* CPAN Ratings

http://cpanratings.perl.org/d/SMS-Server-Tools

* Search CPAN

http://search.cpan.org/dist/SMS-Server-Tools/

ACKNOWLEDGEMENTS

Top

COPYRIGHT & LICENSE

Top


SMS-Server-Tools documentation Contained in the SMS-Server-Tools distribution.
package SMS::Server::Tools;
use Log::Log4perl qw(:easy);
Log::Log4perl->easy_init($ERROR);

use warnings;
use strict;

our $VERSION = '0.011';

use base 'Class::Accessor';

SMS::Server::Tools->mk_accessors(qw/
    SMSFile Text From To Sent Received IMSI From_TOA From_SMSC Subject Report
    Alphabet UDH
/);

sub parse {

    my $self  = shift;

    ( ERROR "No SMSFile defined!" and die ) unless $self->SMSFile;
    
    DEBUG "start slurping -> ", $self->SMSFile;

    my @sms = _slurp($self->SMSFile);

    DEBUG "finished slurping -> ", $self->SMSFile;

    DEBUG "start parsing";

    chomp @sms; # remove last linefeed

    $self->{'Text'} = pop @sms; # sms-text from last line
    
    DEBUG "parsed Text: $self->{'Text'}";

    pop @sms; # remove blank line

    foreach (@sms) {
		            
        # get sms header fields
        my ($key, $value) = split/: /;
        $self->{$key} = $value;
        DEBUG "parsed $key: $self->{$key}";

    }

    DEBUG "finished parsing";
}

sub write {

    my $self  = shift;

    ( ERROR "No SMSFile defined!" and die ) unless $self->SMSFile;
    ( ERROR "No To defined!" and die )      unless $self->To;
    ( ERROR "No Text defined!" and die )    unless $self->Text;

    # check 160 chars of Text
    # SMS Server Tools can split large message
    my $text_length = length($self->Text);
    my $length_error = "Text has More than 160 chars!";
    ( ERROR $length_error and die ) unless ( $text_length <= 160 );

    my $outfile = $self->SMSFile;

    open(SMS, '>', $outfile) or die "can't open $outfile";

    print SMS "To: ", $self->To, "\n";
    print SMS "\n";
    print SMS $self->Text, "\n";

    close(SMS);

}

sub _slurp {

    local( $/, @ARGV ) = ( wantarray ? $/ : undef, @_ );
    return <ARGV>;

}

1; # End of SMS::Server::Tools