#!/usr/bin/perl -w
#
# $Header: /raid/cvsroot/rt-addons/ScripConditions/OnOwnerChange/insert_condition.pl,v 1.1 2001/06/17 19:18:36 jesse Exp $
# RT is (c) 1996-2000 Jesse Vincent (jesse@fsck.com);
# IncomingEmail Condition by Bruce Campbell

package RT;
use strict;
use vars qw($VERSION $Handle $Nobody $SystemUser $item);

use lib "/home/rt2/lib";
use lib "/home/rt2/etc";

#This drags in  RT's config.pm
use config;
use Carp;

use RT::Handle;
use RT::User;
use RT::CurrentUser;

#connect to the db
$RT::Handle = new RT::Handle($RT::DatabaseType);
$RT::Handle->Connect();


#Put together a current user object so we can create a User object
my $CurrentUser = new RT::CurrentUser();


#now that we bootstrapped that little bit, we can use the standard RT cli
# helpers  to do what we need

use RT::Interface::CLI  qw(CleanEnv LoadConfig DBConnect 
			   GetCurrentUser GetMessageContent);

#Clean out all the nasties from the environment
CleanEnv();

#Load etc/config.pm and drop privs
LoadConfig();

#Connect to the database and get RT::SystemUser and RT::Nobody loaded
DBConnect();


$CurrentUser->LoadByName('RT_System');

# {{{ ScripConditions

# The Argument is a comma-seperate list of patterns to check for in the
# Transaction's first Attachment's Header to decide whether its an Email 
# or not.  Only choose Header lines that you *know* will be added by your
# MTA.
my @ScripConditions = (
		       {
			Name => 'OnIncomingEmail',
			Description =>  'Matches when the transaction was generated via Email',
			ApplicableTransTypes =>  'Any',
			Argument => '^Received, ^Date, ^From',  
			ExecModule => 'IncomingEmail',
		       },
		       
		       
		      );

# }}}
print "Creating ScripConditions...";

use RT::ScripCondition;
for $item (@ScripConditions) {
    my $new_entry = new RT::ScripCondition($CurrentUser);
    my $return = $new_entry->Create(%$item);
    print $return.".";
}

print "done.\n";

$RT::Handle->Disconnect();


1;

