if ($#ARGV == -1) {
goto mailcon;
$nopts = 1;
} else {
$nopts = 0;
}
####
if (@ARGV) {
$nopts = 0;
} else {
goto mailcon;
$nopts = 1;
}
####
#!/usr/bin/perl -w
=head1 NAME
popcheck - quick, cheap and dirty mail checker
=head1 SYNOPSIS
popcheck [-g msgnum] [-d msgnum] [-h]
Options:
--server Set POP3 server
--user Set POP3 username
--pass Set POP3 password
--get Get message
--del Delete message
--help Show manpage
The usage of (alternate) usernames and passwords are conditional on both the
username and password being specified (on the command line).
=head1 DESCRIPTION
Quick and cheap perl script to check mail on a remote
POP3 server. Born when mutt died ...
=head1 OPTIONS
=over 4
=item --server
The hostname of the POP3 server to contact.
If no default has been set in the script, this option is required.
=item --user
The username to log into the POP3 with.
=item --pass
The password to log into the POP3 with.
=item --get
The number of a message which is to be retrieved.
This option may be specified multiple times.
=item --del
The number of a message which is to be deleted.
This option may be specified multiple times.
=back
=head1 VERSION
$Revision: 1.1 $
=head1 COPYRIGHT
Originally written by Elfyn McBratney L
and released under a "do what you like with it but don't blame me"
type license.
=cut
use strict;
use File::Basename;
use Getopt::Std;
use Net::POP3;
my $pop_host;
GetOptions(
'server=s' => \($pop_host = ''), # defaults could be supplied here
'user=s' => \(my $pop_user = ''),
'pass=s' => \(my $pop_pass = ''),
'get=i' => \(my @opt_get),
'del=i' => \(my @opt_del),
'help' => \(my $opt_help),
) and $pop_host and @ARGV == 0 or pod2usage(-verbose => 1);
pod2usage(-verbose => 2) if $opt_help;
my $pop = Net::POP3->new($pop_host, Timeout => 30)
or die "Failed to connect to server `$pop_host': $!\n";
my $msgnum = $pop->login($pop_user, $pop_pass)
or die "Failed to login on server `$pop_host' as user `$pop_user': $!\n";
print STDERR $msgnum == 0
? "No messages on server\n"
: "$msgnum message(s) on server\n";
my $retrieved_messages = '';
for my $opt_get (@opt_get) {
die "You asked for message $opt_get but there are only $msgnum messages.\n"
if $opt_get > $msgnum;
my $msg = $pop->get($opt_get)
or die "Failed to get message $opt_get: $!\n";
$retrieved_messages .= join '', @$msg;
}
for my $opt_del (@opt_del) {
die "You asked for message $opt_del but there are only $msgnum messages.\n"
if $opt_del > $msgnum;
$pop->delete($opt_del);
}
print $retrieved_messages;
$pop->quit();