#!/usr/bin/perl

#######################################################################################
#                                                                                     #
#  icq_webhandler - Perl helper application to handle the application/x-icq mimetype  #
#                                                                                     #
#  Copyright (c) 2003 by Jason Keirstead <jason@keirstead.org>                        #
#                                                                                     #
#  Kopete    (c) 2002 by the Kopete developers  <kopete-devel@kde.org>                #
#                                                                                     #
#######################################################################################
#                                                                                     #
#  This program is free software; you can redistribute it and/or modify               #
#  it under the terms of the GNU General Public License as published by               #
#  the Free Software Foundation; either version 2 of the License, or                  #
#  (at your option) any later version.                                                #
#                                                                                     #
#######################################################################################

# Open the file
my $file = shift;

open(INFILE,"$file");

until( $actionLine =~ /\[.*\]/ ) {
	$actionLine = <INFILE>;
}
if ( $actionLine =~ /\[(.*)\]/ ) {
	$action = $1;
}

print $action;

# Get our variables
while( <INFILE> ) {
	if( /UIN=(.*)\r?\n/ ) {
		$uin = $1;
	} elsif ( /NickName=(.*)\r?\n/ ) {
		$nickName = $1;
	}
}

# Execute Action
if( $action eq "ICQ User" ) {

	`dcop kopete KopeteIface addContact "ICQ" "$uin" "$nickName"`;

} elsif ($action eq "ICQ Message User" ) {

	`dcop kopete KopeteIface addContact "ICQ" "$uin" "$nickName"`;
}
