I am using the GT::Mail::POP3 module to hit a POP3 server and verify if a user (and correct password) exist on the server. It is currently setup as a global variable. Here is the code:
sub {
# ------------------------------------------------------------------
# Used to check the Mail server for new messages.
#
use GT::Mail::POP3;
my $tags = GT::Template->tags;
my $id = $tags->{"chpdcmail"};
$id =~ s/\s+$//;
my $password = $tags->{"Password"};
$password =~ s/\s+$//;
open(OLD_STDERR,">&STDERR") or die "Failed to save STDERR";
open(STDERR,">script.err") or die "Failed to redirect STDERR";
# Constructors
my $pop = new GT::Mail::POP3 (
host => 'mail.alliedhealthsystems.com',
port => 110,
user => $id,
pass => $password,
auth_mode => 'PASS',
Timeout => '5',
debug => 1
);
my $count = $pop->connect;
if($count > 0) {
$tags->{home}->{sql}->table('Claims_Users')->update ( { SamePass => '1'}, { Username => $tags->{Username}} );
}
else { $tags->{home}->{sql}->table('Claims_Users')->update ( { SamePass => '0'}, { Username => $tags->{Username}} ); }
$pop->quit;
open(STDERR,">&OLD_STDERR") or die "Failed to restore STDERR";
return $count;
}
When I run the script, it runs correctly but never does what you expect. I captured the STDERR from the script and this is what I got:
GT::Mail::POP3 (6682): Attempting to connect .. at /website/ahs/public_html/code/admin/GT/Mail/POP3.pm line 215.
GT::Mail::POP3 (6682): Connected to mail.alliedhealthsystems.com on port 110 at /website/ahs/public_html/code/admin/GT/Mail/POP3.pm line 233.
GT::Mail::POP3 (6682): Going to login at /website/ahs/public_html/code/admin/GT/Mail/POP3.pm line 241.
GT::Mail::POP3 (6682): Attempting to log in via clear text ... at /website/ahs/public_html/code/admin/GT/Mail/POP3.pm line 288.
GT::Mail::POP3 (6682): --> USER SCALAR(0x97c65e0) at /website/ahs/public_html/code/admin/GT/Mail/POP3.pm line 154.
GT::Mail::POP3 (6682): <-- +OK SCALAR(0x97c65e0) at /website/ahs/public_html/code/admin/GT/Mail/POP3.pm line 163.
GT::Mail::POP3 (6682): --> PASS admin at /website/ahs/public_html/code/admin/GT/Mail/POP3.pm line 154.
GT::Mail::POP3 (6682): <-- -ERR Unknown user or incorrect password at /website/ahs/public_html/code/admin/GT/Mail/POP3.pm line 163.
GT::Mail::POP3 (6682): An error occured while logging in: PASS POP Login failed: -ERR Unknown user or incorrect password at (eval 24) line 31.
GT::Mail::POP3 (6682): --> QUIT at /website/ahs/public_html/code/admin/GT/Mail/POP3.pm line 154.
GT::Mail::POP3 (6682): <-- +OK mail.alliedhealthsystems.com closing connection at /website/ahs/public_html/code/admin/GT/Mail/POP3.pm line 163.
So basically I see the problem... It is sending the text "SCALAR(0x97c65e0)" as the username (and probably the password). Which obviously the mailserver does not understand. So how do I get it to send the actual value of the variable and not the scalar reference???
sub {
# ------------------------------------------------------------------
# Used to check the Mail server for new messages.
#
use GT::Mail::POP3;
my $tags = GT::Template->tags;
my $id = $tags->{"chpdcmail"};
$id =~ s/\s+$//;
my $password = $tags->{"Password"};
$password =~ s/\s+$//;
open(OLD_STDERR,">&STDERR") or die "Failed to save STDERR";
open(STDERR,">script.err") or die "Failed to redirect STDERR";
# Constructors
my $pop = new GT::Mail::POP3 (
host => 'mail.alliedhealthsystems.com',
port => 110,
user => $id,
pass => $password,
auth_mode => 'PASS',
Timeout => '5',
debug => 1
);
my $count = $pop->connect;
if($count > 0) {
$tags->{home}->{sql}->table('Claims_Users')->update ( { SamePass => '1'}, { Username => $tags->{Username}} );
}
else { $tags->{home}->{sql}->table('Claims_Users')->update ( { SamePass => '0'}, { Username => $tags->{Username}} ); }
$pop->quit;
open(STDERR,">&OLD_STDERR") or die "Failed to restore STDERR";
return $count;
}
When I run the script, it runs correctly but never does what you expect. I captured the STDERR from the script and this is what I got:
GT::Mail::POP3 (6682): Attempting to connect .. at /website/ahs/public_html/code/admin/GT/Mail/POP3.pm line 215.
GT::Mail::POP3 (6682): Connected to mail.alliedhealthsystems.com on port 110 at /website/ahs/public_html/code/admin/GT/Mail/POP3.pm line 233.
GT::Mail::POP3 (6682): Going to login at /website/ahs/public_html/code/admin/GT/Mail/POP3.pm line 241.
GT::Mail::POP3 (6682): Attempting to log in via clear text ... at /website/ahs/public_html/code/admin/GT/Mail/POP3.pm line 288.
GT::Mail::POP3 (6682): --> USER SCALAR(0x97c65e0) at /website/ahs/public_html/code/admin/GT/Mail/POP3.pm line 154.
GT::Mail::POP3 (6682): <-- +OK SCALAR(0x97c65e0) at /website/ahs/public_html/code/admin/GT/Mail/POP3.pm line 163.
GT::Mail::POP3 (6682): --> PASS admin at /website/ahs/public_html/code/admin/GT/Mail/POP3.pm line 154.
GT::Mail::POP3 (6682): <-- -ERR Unknown user or incorrect password at /website/ahs/public_html/code/admin/GT/Mail/POP3.pm line 163.
GT::Mail::POP3 (6682): An error occured while logging in: PASS POP Login failed: -ERR Unknown user or incorrect password at (eval 24) line 31.
GT::Mail::POP3 (6682): --> QUIT at /website/ahs/public_html/code/admin/GT/Mail/POP3.pm line 154.
GT::Mail::POP3 (6682): <-- +OK mail.alliedhealthsystems.com closing connection at /website/ahs/public_html/code/admin/GT/Mail/POP3.pm line 163.
So basically I see the problem... It is sending the text "SCALAR(0x97c65e0)" as the username (and probably the password). Which obviously the mailserver does not understand. So how do I get it to send the actual value of the variable and not the scalar reference???