#!/usr/bin/perl
#
# randmail.pl: 
# it will send a random mail on a random date to a random person.
# You must have `at' installed.
#
# Fri Mar 24 11:54:44 CET 2006
# -  AlpT (@freaknet.org)
#
# thanks to Arfalas, you're my Muse ;*

# Configure this filename. In it you shall put a plain list of email addresses
# (one per line) or a list of alias in the mutt style 
# (i.e. "alias foo bar <foobar@barfoo.foo>"
$ALIAS_FILE="~/.mail_aliases";
$signature=`cat ~/.signature`; #Your signature

$iam=`whoami`;
$date=`date +"%H:%M:%S %d/%B/%Y"`;
$iam  =~ s/\n$//;
$date =~ s/\n$//;
$time = int(rand(43200))%43200+24;

##
### Write your message here
##
$SUBJECT = "Yo! I am $iam. Bla bla... ";
$MSG= <<MSG_BODY;
I am $iam,

this is a mail coming from the past,
it has been created at:
$date.
Exactly after $time hours ago.


bla bla bla

Cya
--
$signature
MSG_BODY

$ALIAS_FILE=`echo $ALIAS_FILE`;
open(FH, "< $ALIAS_FILE") || do { print "Cannot open $ALIAS_FILE: $!"; exit 1 };
@mails = <FH>;
$w1 = $mails[int(rand($#mails))];
if ($w1=~/<(.*)>/) {
	$w1=$1;
} else {
	chomp $w1;
}

open(MAILFD, "> /tmp/rmail");
print MAILFD "cat <<MAIL_MESSAGE | mail -s \"$SUBJECT\" $w1\n$MSG";
$at_cmd=`cat /tmp/rmail | at now + $time hours`;
print $at_cmd;
close(MAILFD);
