1Net::POP3(3) User Contributed Perl Documentation Net::POP3(3)
2
3
4
6 Net::POP3 - Post Office Protocol 3 Client class (RFC1939)
7
9 use Net::POP3;
10
11 # Constructors
12 $pop = Net::POP3->new('pop3host');
13 $pop = Net::POP3->new('pop3host', Timeout => 60);
14 $pop = Net::POP3->new('pop3host', SSL => 1, Timeout => 60);
15
16 if ($pop->login($username, $password) > 0) {
17 my $msgnums = $pop->list; # hashref of msgnum => size
18 foreach my $msgnum (keys %$msgnums) {
19 my $msg = $pop->get($msgnum);
20 print @$msg;
21 $pop->delete($msgnum);
22 }
23 }
24
25 $pop->quit;
26
28 This module implements a client interface to the POP3 protocol,
29 enabling a perl5 application to talk to POP3 servers. This
30 documentation assumes that you are familiar with the POP3 protocol
31 described in RFC1939. With IO::Socket::SSL installed it also provides
32 support for implicit and explicit TLS encryption, i.e. POP3S or
33 POP3+STARTTLS.
34
35 A new Net::POP3 object must be created with the new method. Once this
36 has been done, all POP3 commands are accessed via method calls on the
37 object.
38
39 The Net::POP3 class is a subclass of Net::Cmd and (depending on
40 avaibility) of IO::Socket::IP, IO::Socket::INET6 or IO::Socket::INET.
41
42 Class Methods
43 "new([$host][, %options])"
44 This is the constructor for a new Net::POP3 object. $host is the
45 name of the remote host to which an POP3 connection is required.
46
47 $host is optional. If $host is not given then it may instead be
48 passed as the "Host" option described below. If neither is given
49 then the "POP3_Hosts" specified in "Net::Config" will be used.
50
51 %options are passed in a hash like fashion, using key and value
52 pairs. Possible options are:
53
54 Host - POP3 host to connect to. It may be a single scalar, as
55 defined for the "PeerAddr" option in IO::Socket::INET, or a
56 reference to an array with hosts to try in turn. The "host" method
57 will return the value which was used to connect to the host.
58
59 Port - port to connect to. Default - 110 for plain POP3 and 995
60 for POP3s (direct SSL).
61
62 SSL - If the connection should be done from start with SSL,
63 contrary to later upgrade with "starttls". You can use SSL
64 arguments as documented in IO::Socket::SSL, but it will usually use
65 the right arguments already.
66
67 LocalAddr and LocalPort - These parameters are passed directly to
68 IO::Socket to allow binding the socket to a specific local address
69 and port. For compatibility with older versions ResvPort can be
70 used instead of LocalPort.
71
72 Domain - This parameter is passed directly to IO::Socket and makes
73 it possible to enforce IPv4 connections even if IO::Socket::IP is
74 used as super class. Alternatively Family can be used.
75
76 Timeout - Maximum time, in seconds, to wait for a response from the
77 POP3 server (default: 120)
78
79 Debug - Enable debugging information
80
81 Object Methods
82 Unless otherwise stated all methods return either a true or false
83 value, with true meaning that the operation was a success. When a
84 method states that it returns a value, failure will be returned as
85 undef or an empty list.
86
87 "Net::POP3" inherits from "Net::Cmd" so methods defined in "Net::Cmd"
88 may be used to send commands to the remote POP3 server in addition to
89 the methods documented here.
90
91 "host()"
92 Returns the value used by the constructor, and passed to
93 IO::Socket::INET, to connect to the host.
94
95 "auth($username, $password)"
96 Attempt SASL authentication.
97
98 "user($user)"
99 Send the USER command.
100
101 "pass($pass)"
102 Send the PASS command. Returns the number of messages in the
103 mailbox.
104
105 "login([$user[, $pass]])"
106 Send both the USER and PASS commands. If $pass is not given the
107 "Net::POP3" uses "Net::Netrc" to lookup the password using the host
108 and username. If the username is not specified then the current
109 user name will be used.
110
111 Returns the number of messages in the mailbox. However if there are
112 no messages on the server the string "0E0" will be returned. This
113 is will give a true value in a boolean context, but zero in a
114 numeric context.
115
116 If there was an error authenticating the user then undef will be
117 returned.
118
119 "starttls(%sslargs)"
120 Upgrade existing plain connection to SSL. You can use SSL
121 arguments as documented in IO::Socket::SSL, but it will usually use
122 the right arguments already.
123
124 "apop([$user[, $pass]])"
125 Authenticate with the server identifying as $user with password
126 $pass. Similar to "login", but the password is not sent in clear
127 text.
128
129 To use this method you must have the Digest::MD5 or the MD5 module
130 installed, otherwise this method will return undef.
131
132 "banner()"
133 Return the sever's connection banner
134
135 "capa()"
136 Return a reference to a hash of the capabilities of the server.
137 APOP is added as a pseudo capability. Note that I've been unable
138 to find a list of the standard capability values, and some appear
139 to be multi-word and some are not. We make an attempt at
140 intelligently parsing them, but it may not be correct.
141
142 "capabilities()"
143 Just like capa, but only uses a cache from the last time we asked
144 the server, so as to avoid asking more than once.
145
146 "top($msgnum[, $numlines])"
147 Get the header and the first $numlines of the body for the message
148 $msgnum. Returns a reference to an array which contains the lines
149 of text read from the server.
150
151 "list([$msgnum])"
152 If called with an argument the "list" returns the size of the
153 message in octets.
154
155 If called without arguments a reference to a hash is returned. The
156 keys will be the $msgnum's of all undeleted messages and the values
157 will be their size in octets.
158
159 "get($msgnum[, $fh])"
160 Get the message $msgnum from the remote mailbox. If $fh is not
161 given then get returns a reference to an array which contains the
162 lines of text read from the server. If $fh is given then the lines
163 returned from the server are printed to the filehandle $fh.
164
165 "getfh($msgnum)"
166 As per get(), but returns a tied filehandle. Reading from this
167 filehandle returns the requested message. The filehandle will
168 return EOF at the end of the message and should not be reused.
169
170 "last()"
171 Returns the highest $msgnum of all the messages accessed.
172
173 "popstat()"
174 Returns a list of two elements. These are the number of undeleted
175 elements and the size of the mbox in octets.
176
177 "ping($user)"
178 Returns a list of two elements. These are the number of new
179 messages and the total number of messages for $user.
180
181 "uidl([$msgnum])"
182 Returns a unique identifier for $msgnum if given. If $msgnum is not
183 given "uidl" returns a reference to a hash where the keys are the
184 message numbers and the values are the unique identifiers.
185
186 "delete($msgnum)"
187 Mark message $msgnum to be deleted from the remote mailbox. All
188 messages that are marked to be deleted will be removed from the
189 remote mailbox when the server connection closed.
190
191 "reset()"
192 Reset the status of the remote POP3 server. This includes resetting
193 the status of all messages to not be deleted.
194
195 "quit()"
196 Quit and close the connection to the remote POP3 server. Any
197 messages marked as deleted will be deleted from the remote mailbox.
198
199 "can_inet6()"
200 Returns whether we can use IPv6.
201
202 "can_ssl()"
203 Returns whether we can use SSL.
204
205 Notes
206 If a "Net::POP3" object goes out of scope before "quit" method is
207 called then the "reset" method will called before the connection is
208 closed. This means that any messages marked to be deleted will not be.
209
211 None.
212
214 See <https://rt.cpan.org/Dist/Display.html?Status=Active&Queue=libnet>.
215
217 Net::Netrc, Net::Cmd, IO::Socket::SSL.
218
220 Graham Barr <gbarr@pobox.com <mailto:gbarr@pobox.com>>.
221
222 Steve Hay <shay@cpan.org <mailto:shay@cpan.org>> is now maintaining
223 libnet as of version 1.22_02.
224
226 Copyright (C) 1995-2004 Graham Barr. All rights reserved.
227
228 Copyright (C) 2013-2016, 2020 Steve Hay. All rights reserved.
229
231 This module is free software; you can redistribute it and/or modify it
232 under the same terms as Perl itself, i.e. under the terms of either the
233 GNU General Public License or the Artistic License, as specified in the
234 LICENCE file.
235
237 Version 3.13
238
240 23 Dec 2020
241
243 See the Changes file.
244
245
246
247perl v5.34.0 2022-01-21 Net::POP3(3)