Ok, well I've pulled together some sample code from the net, played around with it a little and I have a version that works!
I'm using pop3 and the always bcc function, deleting the mail from the copy account once it's been announced. The script is running now and is shown for your amusement below. This only really took about an hour, I'm new to perl and there are some parts of this code that I dont actually understand. Perhaps once you have all finished laughing, you can offer a reworked version?
I'll come back to the code tomorrow and try to make something more concise, but for now, rest
PHP Code:#!/usr/bin/perl -w
use Net::POP3;
while () {
print "Checking POP3 Server.... \n";
# Connect to pop3 server
my $pop3 = Net::POP3->new("10.100.100.2") || die "Error : Couldn't log on to server";
# Login to pop3 server
my $Num_Message = $pop3->login("spokenemail", "spokenemail");
my $Messages = $pop3->list();
my ($MsgId, $MsgDate, $MsgFrom, $MsgTo, $MsgCc, $MsgSub);
my ($MsgAttach, $MsgSize, $MsgHeader, $MsgHeadFlg, $MsgBody);
foreach $MsgNo (keys %$Messages)
{
my $MsgContent = $pop3->get($MsgNo);
my $count = 0;
$MsgHeadFlg = 0;
$MsgBody = "";
# Process message data
while()
{
# Exit if last line of mail
if ($count >= scalar(@$MsgContent))
{
last;
}
# Check if end of mail header
if (@$MsgContent[$count] =~ /^n/)
{
$MsgHeadFlg = 1;
}
# Proceed if message header not processed
if (not $MsgHeadFlg)
{
# Split the line
my @LineContent = split /: /, @$MsgContent[$count];
# Check Header Info
SWITCH:
{
# Get message from
$LineContent[0] =~ /From/i && do
{
$MsgFrom = $LineContent[1];
last SWITCH;
};
# Get message to
$LineContent[0] =~ /To/i && do
{
$MsgTo = $LineContent[1];
print $MsgTo;
last SWITCH;
};
# Get message subject
$LineContent[0] =~ /Subject/i && do
{
$MsgSub = $LineContent[1];
last SWITCH;
};
}
}
else
{
# Process message body
$MsgBody .= @$MsgContent[$count];
}
$count++;
}
system "swift 'New message from: $MsgFrom'";
system "swift 'For: $MsgTo'";
system "swift 'Subject is: $MsgSub'";
$pop3->delete($MsgNo);
}
# Disconnect from pop3 server
$pop3->quit();
sleep (30);
}


LinkBack URL
About LinkBacks


