#!/usr/bin/perl
#
# MailPlex v1.1
# (l) Peter Baudis <pasky@ji.cz> 2001
#
# Manage main mailbox
#
# Parameters: mailget.pl [get]
#
# Defaultly print zero if no mails waiting,
# otherwise undefined non-zero number
#
# With get parameter, print and delete the first mail from mailbox
#

# Configuration:

$uname=getpwuid($<);      # nope, this isn't any configurable value, ignore it
$mbox="/var/mail/$uname"; # /home/$uname/Mailbox for qmail,
                          # /var/spool/mail/$uname might be
                          # another interesting choice

#### End of configuration
#### You shouldn't be interested in the rest of file, really, unless you know
#### what are you doing.

use Mail::Util qw(read_mbox);

@mailbox=read_mbox($mbox);

if ($ARGV[0] eq "get") {
  foreach(@{$mailbox[0]}){print "$_";}
  open (MBOX, ">".$mbox) or die "Cannot open mailbox!";
  shift(@mailbox);
  foreach (@mailbox){foreach(@{$_}){print MBOX "$_";}}
  close MBOX;
} else {
  print @mailbox."\n";
}
