#!/usr/local/bin/perl -i

#####################################################################
# gen_random_sig.pl - a perl-based random email signature generator #
# by Paul Duncan <duncanpa@flop.engr.orst.edu>                      # 
#                                                                   #
# to use:                                                           #
# - change the path above to the location of perl on your system    #
# - make a .randsigs folder in your home direcotry containing       #
#   your several random signature quotes.                           #
# - modify your .signature file and add a %%insert_sig%% line       #
#   where you want your quote inserted.                             #
# - configure your email client to pass finished emails through     #
#   the script (you may need to place the script in your bin/       #
#   directory for it to work correctly).                            #
# - pine users: add the full path to the script to your sending     #
#   mail filters in "Settings: Configure"                           #
# - have fun, and please don't sue me if it melts your computer     #
#   or whatever.  let me know if you like it.                       #
#                                                                   #
#####################################################################

$SIG_DIR="$ENV{HOME}/.randsigs";
$DEBUG=0;

$found = 0;

while (<>)
{
	if (/\%\%insert_sig\%\%/)
	{
		opendir DIR, "$SIG_DIR";
		@files = readdir DIR;
		$which = int( rand (@files-2) ) + 2;

		open DFLT,"$SIG_DIR/$files[$which]";
		print while (<DFLT>);
		close DFLT;
		closedir DIR;
		$found++;
		print "$which:\t$files[$which]\n" if ( $DEBUG );
	}
	print;
}

unless ( $found )
{
	open DFLT, "$SIG_DIR/default";
	print while (<DFLT>);
	close DFLT;
}

