How do I set up a perl program such as the one below to check mail without hard coding the password in the code? I want to run the job automatically via cron, but I I do not like the idea of leaving the password lying around in clear text. I am pretty new to Perl as you can see from the quality of the code, but it seems the right choice for this application, except for the passwords. -Chuck-




#!/usr/bin/perl

#------------------------------------------------------
# Read LetterRip Daily Statistics email and process
# bounce addresses.
#
# Written April 2004 by Chuck Rice
#------------------------------------------------------


use Mail::Mailer;
use Net::POP3;
use strict;

my $mail_server = "mail.wildrice.com";
my $username = "xxxxxxxx";
my $password = "xxxxxxxx";
my $pop;
my $line;
my @bouncer;
my $listMsgCnt;
my @fields;
my $mailer;
my $from_address = "[EMAIL PROTECTED]";
my $to_address = "[EMAIL PROTECTED],[EMAIL PROTECTED]";
my $subject = "Unsubscribe Bouncers";
my $body = "user [EMAIL PROTECTED] xxxxxxxx\n";

$pop = Net::POP3->new($mail_server)
or die "Can't open connection to $mail_server : $!\n";
defined ($pop->login($username, $password))
or die "Can't authenticate: $!\n";
my $messages = $pop->list
or die "Can't get list of undeleted messages: $!\n";
foreach my $msgid (keys %$messages) {
print $msgid . "\r";
my $message = $pop->get($msgid);
unless (defined $message) {
warn "Couldn't fetch $msgid from server: $!\n";
next;
}
# $message is a reference to an array of lines
$pop->delete($msgid);


foreach $_ (@$message) {

if (/Message posts/) {
@fields = split(/\s+/, $_);
$listMsgCnt = $fields[2];
} if (/unsub \"/) {
my @fields = split(/\s+/, $_);
$fields[$#fields+1] = 0;
$fields[$#fields+1] = 0;
$fields[$#fields+1] = 0;
$fields[$#fields+1] = 0;
$fields[$#fields+1] = 0;
$fields[$#fields+1] = 0;
my $failCnt = $fields[5];
if ($listMsgCnt <= 0 . $failCnt) {
$bouncer[$#bouncer+1] = $_;
}
} }
}
foreach $line (@bouncer) {
print $line;
$body .= $line;
}



$mailer = Mail::Mailer->new("sendmail"); $mailer->open({ From => $from_address, To => $to_address, Subject => $subject }) or die "Can't open: $!\n"; print $mailer $body; $mailer->close(); print "Done"; -- Fight Spam! Join CAUCE! == http://www.cauce.org/

Reply via email to