| 1 |
Frequently Asked Questions Regarding Mail::POP3Client |
| 2 |
============================================================== |
| 3 |
|
| 4 |
1. Does the module handle attachments? |
| 5 |
2. How do I install it if my ISP won't? |
| 6 |
3. Can I check to see if I have new mail? |
| 7 |
4. How do I tell if the connection worked or not? |
| 8 |
5. My ID and password are correct, why can't I connect? |
| 9 |
6. Can't use an undefined value as a symbol reference [...] during global destruction. |
| 10 |
6. Can't use an undefined value as a symbol reference [...] during global destruction. |
| 11 |
7. How do I use an SSL connection? |
| 12 |
|
| 13 |
|
| 14 |
Answers |
| 15 |
============================================================== |
| 16 |
|
| 17 |
1. Does the module handle attachments? |
| 18 |
|
| 19 |
The module downloads messages in raw format. It does not do anything |
| 20 |
special with attachments. To do that, use MIME::Parser or something |
| 21 |
equivalent. MIME::Parser has a method called parse_data that accepts |
| 22 |
an array of lines. Pass it the results of the Body method as follows: |
| 23 |
|
| 24 |
my $parser = new MIME::Parser; |
| 25 |
$parser->output_dir( $dir ); |
| 26 |
my @lines = $pop->Body( $n ); |
| 27 |
$parser->parse_data( @lines ); |
| 28 |
|
| 29 |
Or you can write straight to a temp file and have the parser process |
| 30 |
that. |
| 31 |
|
| 32 |
my $io = new IO::File; |
| 33 |
if ($io->open( "> $dir/raw-message.$n")) { |
| 34 |
$pop3->HeadAndBodyToFile( $io, $n ); |
| 35 |
$io->close; |
| 36 |
print "Parsing $dir/raw-message.$n...\n"; |
| 37 |
$parser->parse( IO::File->new( "$dir/raw-message.$n") ); |
| 38 |
} |
| 39 |
|
| 40 |
See the perldoc for MIME::Parser for more details. |
| 41 |
|
| 42 |
|
| 43 |
2. How do I install it if my ISP won't? |
| 44 |
|
| 45 |
You have 2 choices. You can go through the installation process using |
| 46 |
a prefix option to the make command like this: |
| 47 |
|
| 48 |
% perl Makefile.PL prefix=/some/other/directory |
| 49 |
|
| 50 |
then just make; make install as above. |
| 51 |
|
| 52 |
Or you can create a directory called Mail somewhere and just put |
| 53 |
POP3Client.pm in there. You will then have to put this directory into |
| 54 |
your include path (@INC) either on the command line or in your code |
| 55 |
(i.e. use lib '/path/to/directory'; ). You need to include the |
| 56 |
directory above Mail and case does matter. |
| 57 |
|
| 58 |
Choice 1 is better because you can track what modules you have |
| 59 |
installed but if you don't have command line access you'll have to go |
| 60 |
with choice 2. |
| 61 |
|
| 62 |
|
| 63 |
3. Can I check to see if I have new mail? |
| 64 |
|
| 65 |
Not directly. You'd have to keep track of the messages read from the |
| 66 |
last connection (using Uidl). It's not something the protocol |
| 67 |
supports. Some mail servers may add a header when a message is |
| 68 |
retrieved. Try looking at the Status header. |
| 69 |
|
| 70 |
|
| 71 |
4. How do I tell if the connection worked or not? |
| 72 |
|
| 73 |
Check the Count() method. A value of -1 means that the connection |
| 74 |
failed. You will have access to the other methods on the object to |
| 75 |
see the Message, etc. This will be changed sometime in the future so |
| 76 |
that the constructor (or the Connect() method) will return undef or 0 |
| 77 |
on failure. |
| 78 |
|
| 79 |
|
| 80 |
5. My ID and password are correct, why can't I connect? |
| 81 |
|
| 82 |
Add AUTH_MODE => 'PASS' to the constructor. Some servers state that |
| 83 |
they support APOP authentication, but it may not work for all |
| 84 |
accounts. |
| 85 |
|
| 86 |
|
| 87 |
6. Can't use an undefined value as a symbol reference [...] during global destruction. |
| 88 |
|
| 89 |
First, add 'use strict' and -w and fix all of the warnings in your |
| 90 |
script. If this error still occurs, please send me the type of server |
| 91 |
you are using (telnet to port 110 on the server and send me the first |
| 92 |
line it sends you). Some POP3 servers drop the connection after a failed |
| 93 |
authentication. The servers I have tested against do not appear to do |
| 94 |
this. |
| 95 |
|
| 96 |
Another possibility that has been suggested is a situation with |
| 97 |
redundant POP servers using DNS round robin. If the first address |
| 98 |
IO::Socket connects to is down, the module will fail to connect. |
| 99 |
|
| 100 |
|
| 101 |
7. How do I use an SSL connection? (Thanks to Jamie LeTual) |
| 102 |
|
| 103 |
my $socket = IO::Socket::SSL->new( PeerAddr => 'pop.host.com', |
| 104 |
PeerPort => 993, |
| 105 |
Proto => 'tcp') || die "Ack! No socket!"; |
| 106 |
my $pop = Mail::POP3Client->new(); |
| 107 |
$pop->User('jamie'); |
| 108 |
$pop->Pass('secret'); |
| 109 |
$pop->Socket($socket); |
| 110 |
$pop->Connect(); |