#!/usr/bin/perl -w
#
# oolongclient -- mail-to-bot interface for oolong, the
#                 LiveJournal support notification IRC bot
#
# Copyright 2003, Rich Lafferty <rich@lafferty.ca>
#
# This is free software with ABSOLUTELY NO WARRANTY. You may reproduce
# and use this software under the same terms as Perl itself -- specifically,
# either under the Artistic License of Perl 5.8, or the General Public
# License, version 2 or later.
#
# $Id: notifyclient.pl,v 1.2 2003/07/29 13:25:46 rich Exp $ 

use strict;
use IO::Socket;

my $VERSION = "0.9";

my $s = IO::Socket::INET->new(PeerAddr => '127.0.0.1',
                              PeerPort => '16667',
                              Proto    => "tcp",
                              Type     => SOCK_STREAM)
    or die "Couldn't connect to listener: $@\n";


my $in_header = 1;

while (<>) {
    chomp;

    if ($in_header) {
        $in_header = 0 if /^$/;
        next;
    }
 
    # beginning of content of ticket
    last if /^=+$/;

    if (/^Category:\s+(.*)\s*$/) {
        print "Got category\n";
        print $s "Category: $1\n";
    }
    elsif (/^Subject:\s+(.*)\s*$/) {
        print "Got subject\n";
        print $s "Subject: $1\n";
    }
    elsif (/see_request\.bml\?id=(\d+)/) {
        print "Got request\n";
        print $s "Request: $1\n";
    }
}

print $s "end\n";
print <$s>;

close ($s);

