Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

can't call method without package or object reference

by bwv871 (Initiate)
on Jun 23, 2004 at 14:12 UTC ( #369041=perlquestion: print w/ replies, xml ) Need Help??
bwv871 has asked for the wisdom of the Perl Monks concerning the following question:

Any help greatly appreciated: I am trying to run a script that checks multiple POP3 accounts at once. The script times out, and the error message from the log is "Can't call method "login" without a package or object reference at inbox.pl line 31."

--I'm on a Unix server, running Perl Version 5.006001

--The script can be found here: http://scbr.com/docs/download/mwm.shtml. The instructions (such as they are) can be found here: http://scbr.com/docs/download/mwm_inst.shtml.

--I do not get the error immediately; it takes about 30 or 40 seconds for the "connection error" text to appear.

--When I run the script, everything appears to work fine: by calling mwm.pl I get an html document to log in to, I am then taken to a window with three frames, I can set up new accounts, and all data is written to the "db" files. I can even send mail (/usr/lib/sendmail). Here is the 'inbox.pl' script:

#!/usr/bin/perl use CGI qw(:standard); use myPOP3; if(param('tb')) {printToolbar();exit;} checkLogin(); $account = param("a") || err(); $p_act = param("act") || ""; $p1 = '?'; $pwd = param("pwd") || $p1; readPref('./db'); if(($PREF[2] eq $p1)) { if($pwd eq $p1) { askPwd(); exit; } else { $PREF[2] = $pwd; } } print "Content-type: text/html\n\n"; print "<html>\n"; printScript2(); print "<body topmargin=0 leftmargin=0 marginheight=0 marginwidth=0><fo +nt face=\"times\" size=2>\n<form method=\"post\">\n"; deleteMsg($p_act) if ($p_act =~ /^del\|/); $pop = myPOP3->new($PREF[0]) || print "Connection error.\n"; $count = $pop->login($PREF[1], $PREF[2]); $scr = '<img src="img/scr.gif" width="8" height="16" border="0">'; if(!$count) {print "Login incorrect.\n";} else{ $count = $count * 1; print "&nbsp;Messages: $count\n"; if($count>0){ $tmp = $pop->list(); %sizes = %$tmp; print "<table cellspacing=1>\n"; print "<tr bgcolor=\"\#e0e0e0\"><td>&nbsp;</td><td>$scr</td><t +d><font size=2><b>Subject</b></font></td><td width=40><font size=2><b +>Size</b></font></td><td><font size=2><b>From</b></font></td><td><fon +t size=2><b>Date</b></font></td></tr>\n"; for($i=1;$i<=$count;$i++){ $m = $pop->top($i); %HEAD = undef; &parseHeader($m); local($subj) = $HEAD{'Subject'}; if(length($subj)>50){ $subj = substr($subj,0,40) . '...'; } local($mdate) = formatDate($HEAD{'Date'}); $_ = $HEAD{'From'}; local($mfrom) = $_; $mfrom = $1 if /(.*)</; $_ = $HEAD{'Content-Type'} || ''; local($matt) = '&nbsp;'; $matt = $scr if /multipart/i; print "<tr>\n"; print "<td><input type=\"checkbox\" name=\"selMsg$i\" valu +e=\"$i\" onfocus=\"blur()\"></td>\n"; print "<td><font size=2>$matt</font></td>\n"; print "<td nowrap><font size=2><a href=\"message.pl?a=$acc +ount&m=$i\" target=\"message\" onfocus=\"blur()\" onclick=\"return rc +v($i)\">$subj</a></font></td>\n"; print "<td align=right><font size=2>" . $sizes{$i} . "</fo +nt></td>\n"; print "<td nowrap><font size=2>" . encodeHTML($mfrom) . "< +/font></td>\n"; print "<td nowrap><font size=2>$mdate</font></td>\n"; print "</tr>\n"; } print "</table>\n"; } } $pop->quit; print "<input name=\"act\" value=\"\" type=\"hidden\"><input name=\"fa +dr\" value=\"\" type=\"hidden\">"; print "<input name=\"a\" value=\"$account\" type=\"hidden\"><input typ +e=\"hidden\" name=\"pwd\">"; print "</form>"; print '<form name="frmR" method="post"><input name="m_from" type="hidd +en"><input name="m_to" type="hidden"><input name="m_subj" type="hidde +n"><input name="doc" type="hidden"></form>'; print "<form name=\"frmRcv\" method=\"post\" action=\"message.pl\" tar +get=\"message\"><input type=\"hidden\" name=\"a\" value=\"$account\"> +<input type=\"hidden\" name=\"m\"><input type=\"hidden\" name=\"pwd\" +></form>"; print "\n</font></body>\n</html>\n"; exit; #---------------------------------------------------- sub printToolbar(){ print "Content-type: text/html\n\n"; print "<html>\n"; printScript(); print<<TOOL; <body topmargin=0 leftmargin=0 marginheight=0 marginwidth=0> <table border=0 background="img/bg.gif" width="100%"> <tr> <td ><a href="#" onclick="sendMsg();return false;" onfocus="blur() +"><img src="img/m_new.gif" border="0" alt="Send message"></a ><a href="#" onclick="replMsg();return false;" onfocus="blur() +"><img src="img/m_rep.gif" border="0" alt="Reply message"></a ><a href="#" onclick="fwdMsg();return false;" onfocus="blur()" +><img src="img/m_rep.gif" border="0" alt="Forward message"></a ><a href="#" onclick="delMsg();return false;" onfocus="blur()" +><img src="img/m_del.gif" border="0" alt="Delete message"></a ></td> </tr> </table> </body> </html> TOOL } sub printScript(){ print<<__END; <head> <script language="JavaScript"> function delMsg(){ var f=parent.frames.inbox; if(!f||!f.delMsg) return; f.delMsg(); } function sendMsg(){ window.open("send.pl"); } function replMsg(){ var f=parent.frames.inbox; if(!f||!f.replMsg) return; f.replMsg(); } function fwdMsg(){ var f=parent.frames.inbox; if(!f||!f.fwdMsg) return; f.fwdMsg(); } </script> </head> __END } sub printScript2(){ print<<__END; <head> <script language="JavaScript"> function rcv(i){ var f = document.forms.frmRcv; f.m.value = i; f.pwd.value = top.frames.account.pwds[$account-1]; f.submit(); return false; } function delMsg(){ var f = document.forms[0]; if(!f) return; f.pwd.value = top.frames.account.pwds[$account-1]; var ch=false; var ch0=false; var chn=""; for(i=0;i<f.elements.length;i++){ var b=f.elements[i]; if(b.type!="checkbox") continue; ch0=true; ch = ch || b.checked; if(b.checked) chn=chn+"|"+b.value; } if(!ch){ alert(ch0?"Select a message.":"No messages."); return; } if(confirm("Permanently delete selected messages from server?")){ f.act.value="del"+chn; f.target = ""; f.action = ""; f.submit(); } } function replMsg(){ var f = document.forms.frmR; if(!f) return; var f0=top.frames.message; if(!f0.doc) {alert("No message to reply.\\nRead a message first.") +;return;} f.action="send.pl"; f.target="wnd_repl"; f.m_from.value=f0.m_from; f.m_to.value=f0.m_to; f.m_subj.value=f0.m_subj; f.doc.value=f0.doc; f.submit(); } function fwdMsg(){ var f = document.forms[0]; if(!f) return; f.pwd.value = top.frames.account.pwds[$account-1]; var ch=false; var ch0=false; var chn=""; for(i=0;i<f.elements.length;i++){ var b=f.elements[i]; if(b.type!="checkbox") continue; ch0=true; ch = ch || b.checked; if(b.checked) chn=chn+"|"+b.value; } if(!ch){ alert(ch0?"Select a message.":"No messages."); return; } var fadr = prompt("Enter email address to forward:",""); if(fadr != "") { f.act.value = chn; f.fadr.value = fadr; f.target = "message"; f.action = "forward.pl"; f.submit(); } } </script> </head> __END } sub deleteMsg(){ return if !@_; local($pop, $count, @s); $pop = myPOP3->new($PREF[0]); $count = $pop->login($PREF[1], $PREF[2]); if($count){ @s = split(/\|/, $_[0]); foreach (@s){ $pop->delete($1) if /^(\d+)$/; } } $pop->quit; } sub parseHeader(){ local($a)=$_[0]; local($prev)=undef; foreach (@$a){ if ( /^([a-zA-Z-]+)\:\s*(.*)/ ) {$HEAD{$1} = $2; $prev=$1;} elsif($prev){ if (/^\s*(.+)/) {$HEAD{$prev} .= "\n$1";} else {$prev=undef;} } } } sub formatDate(){ return "" if !$_[0]; $_[0] =~ s/^(\D*)//; $_[0] = substr($_[0], 0, rindex($_[0], ':')); return $_[0]; } sub encodeHTML(){ $_[0] ||= ""; $_[0] =~ s/</&lt;/g; $_[0] =~ s/>/&gt;/g; return $_[0]; } sub checkLogin(){ $_ = $ENV{'HTTP_COOKIE'}; $user = $1 if /user=(\w+)/; err('Access denied.') if !$user; } sub readPref(){ err() if !@_; open(PAGE, "$_[0]/$user.dbx") || err('Error open DB.'); local(@db) = <PAGE>; close(PAGE); local($i)=1; foreach (@db){ if ($i eq $account) {@PREF=split(/\|/, $_);last;} $i++; } err() if !@PREF; } sub err(){ $_[0] ||= " "; print "Content-type: text/html\n\n"; print "&nbsp;$_[0]"; exit; } sub askPwd(){ print<<__END2; Content-type: text/html <html> <body> <form method="post" onsubmit="top.frames.account.pwds[$account-1]=docu +ment.forms[0].pwd.value; return true;"> <input type="hidden" name="a" value="$account"> Password: <input type="password" name="pwd"> <input type="submit" value="Login"> </form> </body> </html> __END2 }

Comment on can't call method without package or object reference
Download Code
Re: perl module for pop3 script
by muntfish (Chaplain) on Jun 23, 2004 at 14:30 UTC

    Quick question - what's wrong with Net::POP3?

    Oh - and please consider use <readmore> tags, that's a heck of a big piece of code...

    s^^unp(;75N=&9I<V@`ack(u,^;s|\(.+\`|"$`$'\"$&\"\)"|ee;/m.+h/&&print$&;
Re: perl module for pop3 script
by arden (Curate) on Jun 23, 2004 at 15:09 UTC
    If you're getting "connection error" then I would take a look at your webserver logs. While you've given us over 1500 lines of code, you haven't told us what operating system you're using, what version of Perl you're using, which webserver you're using, etcetera.

    You mention there are instructions on the website you downloaded this script from, if it's not a pay-ware product, how about letting us know which website. Heck, the author might even be a local monk!

    Take a look at the permissions on the directory you created as well as the scripts. Ensure they all have the correct permissions for the webserver user. Can you view a normal HTML page in a lower directory? Do you get the error immediately or does it take a while to time-out?

    There are still a lot of questions you need to answer before we can really help you much. At this point, I'm guessing the problem isn't the Perl code, but it's in the configuration of the files/server.

    - - arden.

      Apologies... here are the details:

      --I'm on a Unix server, running Perl Version 5.006001

      --The script can be found here: http://scbr.com/docs/download/mwm.shtml. The instructions (such as they are) can be found here: http://scbr.com/docs/download/mwm_inst.shtml.

      --I do not get the error immediately; it takes about 30 or 40 seconds for the "connection error" text to appear.

      --The error message from log file is as folows:

      Can't call method "login" without a package or object reference at inbox.pl line 31.

      --When I run the script, everything appears to work fine: by calling mwm.pl I get an html document to log in to, I am then taken to a window with three frames, I can set up new accounts, and all data is written to the "db" files. I can even send mail (/usr/lib/sendmail).

      --Another respondent to my initial message (sorry it was so long -- was not aware of the readmore tag) -- asked why I did not use the net::pop3 module. I guess the answer is that the script I am having trouble with employs its own module. My server has the CPAN module available, I just do not know if I have the option of using it with the script with which I am having trouble.

      Thanks again for all your assistance. David
Re: perl module for pop3 script
by gellyfish (Monsignor) on Jun 23, 2004 at 16:03 UTC

    I would guess that the configuration of the POP3 server in the ./db/*.db files is incorrect - you should really have got some documentation with the script on how how you should do this.

    /J\

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://369041]
Approved by husker
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2014-09-21 22:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (176 votes), past polls