LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-10-2006, 09:40 PM   #1
exodist
Senior Member
 
Registered: Aug 2003
Location: Portland, Oregon
Distribution: Arch
Posts: 1,374

Rep: Reputation: 47
Question perl Mail::POP3Client script works for 2 of my 3 accounts, fails on third


This script basically connects to all 3 of my e-mail accounts, downloads the messages, and then runs them through a filter before delivering them to the local inbox. The filter works fine so I will not post it, and this script works for 2 accounts, so I am not sure where the problem is, the accoutn that does nto work in the script works fine in thunderbird witht he same settings.

Script (I have removed my passwords):
Code:
#!/usr/bin/perl
use strict;
use Mysql;
use Mail::POP3Client;

sub DoAccount($);


my @Accounts;

$Accounts[0] = {'Name' => 'exodist7@gmail',
				'Server' => 'pop.gmail.com',
				'Username' => 'exodist7',
				'Password' => '********',
				'SSL' => '1',
				'PORT' => '995'};

$Accounts[1] = {'Name' => 'exodist@yifan.net',
				'Server' => 'mail.yifan.net',
				'Username' => 'exodist',
				'Password' => '*********'};
				
$Accounts[2] = {'Name' => 'cgranum@garymckelvey.com',
				'Server' => 'mail.garymckelvey.com',
				'Username' => 'cgranum',
				'Password' => '********'};


MAIN:
{
	foreach my $I (@Accounts)
	{
		print("Account: $I->{'Name'}\n");
		DoAccount($I);
	}
}

sub DoAccount($)
{
	my ($AN) = @_;
	my $CreateString;
	my $Message;
	my $Sender;
	my $Recipient;
	my $Temp;
	my $TMPFile;
	
	$CreateString = "\tUSER => '$AN->{'Username'}',
	PASSWORD => '$AN->{'Password'}',
	HOST => '$AN->{'Server'}'";
	
	$CreateString .= ",\n\tUSESSL => 'true'" if ($AN->{'SSL'});
	$CreateString .= ",\n\tPORT => '$AN->{'PORT'}'" if ($AN->{'PORT'});

	my $pop = new Mail::POP3Client(eval($CreateString));

	print("Logging in....");
	if (!($pop->Login()))
	{
		print("Could not connect to account: $AN->{'Name'}: $!\n");
		return 1;
	}
	print("Logged in!\t");

	print("Total Messages: " . $pop->Count() . "\n");
	
	foreach my $I (1 .. $pop->Count())
	{
		$Message = $pop->HeadAndBody($I);

		foreach my $Line (split(/\n/, $Message))
		{
			if (($Line =~ m/^From:.*$/ig) && (!($Sender)))
			{
				$Temp = $&;
				print("Temp: $Temp\n");
				if ("$Temp" =~ m/[A-Za-z0-9-]+\@[A-Za-z0-9-]+\.[A-Za-z0-9-]+/ig)
				{
					$Sender = $&;
				}
			}
			last if ($Sender);
		}
		
		if (!($Sender))
		{
			print("Error finding sender!\n");
			next;
		}
		
		do
		{
			$TMPFile = "/tmp/MAILSYSTEM-" . rand(1000000000) . ".eml";
		} while (-e $TMPFile);
		
		open(TMP, ">$TMPFile");
		print TMP $Message;
		close(TMP);
		
		if (system("/server/Mailque/bin/newfilter.pl \"$Sender\" \"exodist\@open-exodus.net\" < $TMPFile"))
		{
			print("Error sending message!!!\n");
		}
		else
		{
			$pop->Delete($I);
		}
		unlink($TMPFile);
	}
}

here is the output:
Code:
Account: exodist7@gmail
Logging in....Logged in!        Total Messages: 0

#--------here is the problem-------------
Account: exodist@yifan.net
Use of uninitialized value in pattern match (m//) at /usr/lib/perl5/vendor_perl/5.8.8/Mail/POP3Client.pm line 1075, <GEN1> line 2.
Logging in....Could not connect to account: exodist@yifan.net: 
#--------/problem-------------

Account: cgranum@garymckelvey.com
Logging in....Logged in!        Total Messages: 0
here is the output (for the one that fails only) when debug is passed tot he new POP3Client object:
Code:
Account: exodist@yifan.net
POP3 <- +OK <21130.1155263808@mail.yifansoft.com>
 at ./GetMail.pl line 55
POP3 -> APOP exodist 9bba8c2446b01583cbc25e2fe219c53c
 at ./GetMail.pl line 55
POP3 <- -ERR authorization failed
 at ./GetMail.pl line 55
POP3 -> NOOP
 at ./GetMail.pl line 55
Use of uninitialized value in pattern match (m//) at /usr/lib/perl5/vendor_perl/5.8.8/Mail/POP3Client.pm line 1075, <GEN1> line 2.
Logging in....Could not connect to account: exodist@yifan.net:
 
Old 08-10-2006, 10:08 PM   #2
exodist
Senior Member
 
Registered: Aug 2003
Location: Portland, Oregon
Distribution: Arch
Posts: 1,374

Original Poster
Rep: Reputation: 47
Well, after extensive google searching I foudn that I am not the only one with this problem, that it seems to happen to random users. It suggested manually specifying the AUTH_TYPE option, I did this and that account now works.

In short: Problem solved.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
perl script to report new mail nibbler Programming 1 07-02-2005 09:13 AM
Perl shell-out to script dunna work. Works on command line. Why? jlangelier Linux - Software 1 08-28-2004 02:00 AM
Perl script works with Apache1 but not Apache2, why? m3kgt Linux - Software 7 03-11-2004 12:36 PM
howto send a mail with attachment via perl script ? cccc Programming 24 03-05-2004 07:49 PM
Mail script with Perl & Postfix Bladez Programming 2 02-14-2004 09:59 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:58 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration