#!/usr/bin/perl
our $VERSION = '0.90';
use POSIX qw(strftime);
$startmsg = <>;
while (<>) {
    $msg .= $_;
    next unless /$startmsg/ or eof;
    die "-->$msg<--\n" unless $msg=~s/^(IN|OUT)\n(?:MSG|URL|FILE|CONTACT|SMS|CONT|NOTE|AUTH)\n(\d+)\n(\d+)\n//s;
    $prefix = $1 eq 'IN' ? ' > ' : '';
    print strftime((' 'x61)."[%e %b %Y %H:%M]\n", localtime($1 eq 'IN' ? $2 : $3));
    $msg=~s/\r//g;
    $msg=~s/\[continued\]\n//g;
    $msg=~s/\G(.*?)(?=[^\n]{60})(.{0,58})\s/$1$2\n/gs;
    $msg=~s/\s*$//;
    print $prefix,$_,"\n" for split /\n/, $msg;
    undef $msg;
}
