Small '-w' Question with Net::POP3 
Author Message
 Small '-w' Question with Net::POP3

Hi,
      I've written a small perl script that logs into my pop3 account on my
webserver and checks whether I have any mail waiting or not using Net::POP3.
When I run it and enter the correct username/password it works fine, except
when the password is incorrect it comes back to the browser and tells me.
However, when I use the -w switch it errors out on an invalid password
because further on down the script I'm using a variable that gets
uninitialized due to the bad login. Can someone help me with this so that
when the password is wrong it doesn't throw up an error when the -w is on
because I want to keep that switch on for good programming
practice.....anyway here is the current script below :

 = = = = = = = = = = = = = = = = = = = = = = = = =

#!/usr/bin/perl

use Net::POP3;
use strict;

my $mailserver = www.somedomain.com;
my $username = "someusername";
my $password = "somepassword";
print "Content-type: text/html\n\n";

my $pop = new Net::POP3($mailserver);

unless (defined $pop) {
 print "Error Connecting To Mailserver : $mailserver";
 exit();

Quote:
}

my $num_messages = $pop->login($username, $password);
unless (defined $num_messages) {
 print "Error Authenticating User : $username";
 exit();

Quote:
}

$pop->quit();
print "<font face=Verdana size=2>Waiting : $num_messages</font>";

exit();

 = = = = = = = = = = = = = = = = = = = = = = = = = =



Sat, 24 Apr 2004 17:19:28 GMT  
 Small '-w' Question with Net::POP3

Quote:
>When I run it and enter the correct username/password it works fine, except
>when the password is incorrect it comes back to the browser and tells me.
>However, when I use the -w switch it errors out on an invalid password

                         ^^^^^^^^^^^^^^^^^^^^^^^

This cannot be happening.

Warnings do not change the execution of your program, all they
do is (maybe) make more output on STDERR.

Warnings are not fatal.

Quote:
>#!/usr/bin/perl

>use Net::POP3;
>use strict;

>my $mailserver = www.somedomain.com;

How come you are not asking about the *fatal* error at this point?

(or maybe this _is_ what you are asking about. If so, it has nothing
 to do with warnings being enabled or not.
)

Is this your real code?

Isn't strict complaining about those three bare words?

   my $mailserver = 'www.somedomain.com';  # strings must be quoted

Quote:
>unless (defined $pop) {
> print "Error Connecting To Mailserver : $mailserver";
> exit();

It is conventional to use a *non*-zero exit value for errors.

   exit(1);  

--
    Tad McClellan                          SGML consulting

    Fort Worth, Texas



Sat, 24 Apr 2004 18:11:24 GMT  
 Small '-w' Question with Net::POP3
Yes that is my real code, in regards to the mailserver not being quoted, I
made a typo while posting the code to the NG and changing the real values.
Sorry I didn't spot that.

Yes, for some reason when I enable to warnings on the shebang line and the
password is incorrect I get an 'Error 500' in the browser. When I remove
the -w switch and enter an incorrect password, it says my custom error
message in the browser.

In regards to the exit statement, I will change my programming practice for
that in the future.

Regars,
Mike Mackay.



Sat, 24 Apr 2004 20:46:45 GMT  
 Small '-w' Question with Net::POP3
For some reason the 'Error 500' seems to disappear when I load the Carp
module :
use CGI::Carp qw(fatalsToBrowser);

Hmmmmm, oh well. It still enables me to use the -w on the shebang line.....!



Sat, 24 Apr 2004 21:00:28 GMT  
 Small '-w' Question with Net::POP3

Quote:
> Yes that is my real code, in regards to the mailserver not being quoted, I
> made a typo while posting the code to the NG and changing the real values.
> Sorry I didn't spot that.

YM "Sorry I tried to retype my code rather than cutting and pasting it
into my post."  Retyping often introduces spurious bugs and, due to the
phenomenon called "psychological set," sometimes hides real bugs (you end
up typing what the code should be rather than what it actually is).

Quote:
> Yes, for some reason when I enable to warnings on the shebang line and the
> password is incorrect I get an 'Error 500' in the browser. When I remove
> the -w switch and enter an incorrect password, it says my custom error
> message in the browser.

That suggests that perl is issuing a warning before you've output the
appropriate headers, and your server is getting confused.


Sun, 25 Apr 2004 09:29:14 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Net::POP3 won't authenticate

2. NET::SSH, NET::FTP, NET::POP3 (how to detect)

3. configuring pop3 host for net::pop3

4. Net::POP3 question

5. Net::POP3 Modules question

6. Question on NET::POP3

7. Silly newbie question (Net::POP3)

8. Net::POP3 Array Question

9. question about Net::RawIP's generic ARGPROTO

10. Problem getting 'list' from NET::POP3 to work...

11. Net::FTP 'put' truncates file

12. Just Can't, Can't get Net::Telnet to work

 

 
Powered by phpBB® Forum Software