com.sun.mail.pop3.package.html Maven / Gradle / Ivy
A POP3 protocol provider for the JavaMail API
that provides access to a POP3 message store.
Refer to
RFC 1939
for more information.
The POP3 provider provides a Store object that contains a single Folder
named "INBOX". Due to the limitations of the POP3 protocol, many of
the JavaMail API capabilities like event notification, folder management,
flag management, etc. are not allowed. The corresponding methods throw
the MethodNotSupportedException exception; see below for details.
Note that JavaMail does not include a local store into
which messages can be downloaded and stored. See our
Third Party Products
web page for availability of "mbox" and "MH" local store providers.
The POP3 provider is accessed through the JavaMail APIs by using the protocol
name "pop3" or a URL of the form "pop3://user:password@host:port/INBOX".
POP3 supports only a single folder named "INBOX".
POP3 supports no permanent flags (see
{@link javax.mail.Folder#getPermanentFlags Folder.getPermanentFlags()}).
In particular, the Flags.Flag.RECENT
flag will never be set
for POP3
messages. It's up to the application to determine which messages in a
POP3 mailbox are "new". There are several strategies to accomplish
this, depending on the needs of the application and the environment:
-
A simple approach would be to keep track of the newest
message seen by the application.
-
An alternative would be to keep track of the UIDs (see below)
of all messages that have been seen.
-
Another approach is to download all messages into a local
mailbox, so that all messages in the POP3 mailbox are, by
definition, new.
All approaches will require some permanent storage associated with the client.
POP3 does not support the Folder.expunge()
method. To delete and
expunge messages, set the Flags.Flag.DELETED
flag on the messages
and close the folder using the Folder.close(true)
method. You
cannot expunge without closing the folder.
POP3 does not provide a "received date", so the getReceivedDate
method will return null.
It may be possible to examine other message headers (e.g., the
"Received" headers) to estimate the received date, but these techniques
are error-prone at best.
The POP3 provider supports the POP3 UIDL command, see
{@link com.sun.mail.pop3.POP3Folder#getUID POP3Folder.getUID()}.
You can use it as follows:
if (folder instanceof com.sun.mail.pop3.POP3Folder) {
com.sun.mail.pop3.POP3Folder pf =
(com.sun.mail.pop3.POP3Folder)folder;
String uid = pf.getUID(msg);
if (uid != null)
... // use it
}
You can also pre-fetch all the UIDs for all messages like this:
FetchProfile fp = new FetchProfile();
fp.add(UIDFolder.FetchProfileItem.UID);
folder.fetch(folder.getMessages(), fp);
Then use the technique above to get the UID for each message. This is
similar to the technique used with the UIDFolder interface supported by
IMAP, but note that POP3 UIDs are strings, not integers like IMAP
UIDs. See the POP3 spec for details.
The POP3 protocol provider supports the following properties,
which may be set in the JavaMail Session
object.
The properties are always set as strings; the Type column describes
how the string is interpreted. For example, use
props.put("mail.pop3.port", "888");
to set the mail.pop3.port
property, which is of type int.
Note that if you're using the "pop3s" protocol to access POP3 over SSL,
all the properties would be named "mail.pop3s.*".
Name
Type
Description
mail.pop3.user
String
Default user name for POP3.
mail.pop3.host
String
The POP3 server to connect to.
mail.pop3.port
int
The POP3 server port to connect to, if the connect() method doesn't
explicitly specify one. Defaults to 110.
mail.pop3.connectiontimeout
int
Socket connection timeout value in milliseconds.
Default is infinite timeout.
mail.pop3.timeout
int
Socket I/O timeout value in milliseconds. Default is infinite timeout.
mail.pop3.rsetbeforequit
boolean
Send a POP3 RSET command when closing the folder, before sending the
QUIT command. Useful with POP3 servers that implicitly mark all
messages that are read as "deleted"; this will prevent such messages
from being deleted and expunged unless the client requests so. Default
is false.
mail.pop3.message.class
String
Class name of a subclass of com.sun.mail.pop3.POP3Message
.
The subclass can be used to handle (for example) non-standard
Content-Type headers. The subclass must have a public constructor
of the form MyPOP3Message(Folder f, int msgno)
throws MessagingException
.
mail.pop3.localaddress
String
Local address (host name) to bind to when creating the POP3 socket.
Defaults to the address picked by the Socket class.
Should not normally need to be set, but useful with multi-homed hosts
where it's important to pick a particular local address to bind to.
mail.pop3.localport
int
Local port number to bind to when creating the POP3 socket.
Defaults to the port number picked by the Socket class.
mail.pop3.apop.enable
boolean
If set to true, use APOP instead of USER/PASS to login to the
POP3 server, if the POP3 server supports APOP. APOP sends a
digest of the password rather than the clear text password.
Defaults to false.
mail.pop3.socketFactory
SocketFactory
If set to a class that implements the
javax.net.SocketFactory
interface, this class
will be used to create POP3 sockets. Note that this is an
instance of a class, not a name, and must be set using the
put
method, not the setProperty
method.
mail.pop3.socketFactory.class
String
If set, specifies the name of a class that implements the
javax.net.SocketFactory
interface. This class
will be used to create POP3 sockets.
mail.pop3.socketFactory.fallback
boolean
If set to true, failure to create a socket using the specified
socket factory class will cause the socket to be created using
the java.net.Socket
class.
Defaults to true.
mail.pop3.socketFactory.port
int
Specifies the port to connect to when using the specified socket
factory.
If not set, the default port will be used.
mail.pop3.ssl.enable
boolean
If set to true, use SSL to connect and use the SSL port by default.
Defaults to false for the "pop3" protocol and true for the "pop3s" protocol.
mail.pop3.ssl.checkserveridentity
boolean
If set to true, check the server identity as specified by
RFC 2595.
These additional checks based on the content of the server's certificate
are intended to prevent man-in-the-middle attacks.
Defaults to false.
mail.pop3.ssl.trust
String
If set, and a socket factory hasn't been specified, enables use of a
{@link com.sun.mail.util.MailSSLSocketFactory MailSSLSocketFactory}.
If set to "*", all hosts are trusted.
If set to a whitespace separated list of hosts, those hosts are trusted.
Otherwise, trust depends on the certificate the server presents.
mail.pop3.ssl.socketFactory
SSLSocketFactory
If set to a class that extends the
javax.net.ssl.SSLSocketFactory
class, this class
will be used to create POP3 SSL sockets. Note that this is an
instance of a class, not a name, and must be set using the
put
method, not the setProperty
method.
mail.pop3.ssl.socketFactory.class
String
If set, specifies the name of a class that extends the
javax.net.ssl.SSLSocketFactory
class. This class
will be used to create POP3 SSL sockets.
mail.pop3.ssl.socketFactory.port
int
Specifies the port to connect to when using the specified socket
factory.
If not set, the default port will be used.
mail.pop3.ssl.protocols
string
Specifies the SSL protocols that will be enabled for SSL connections.
The property value is a whitespace separated list of tokens acceptable
to the javax.net.ssl.SSLSocket.setEnabledProtocols
method.
mail.pop3.ssl.ciphersuites
string
Specifies the SSL cipher suites that will be enabled for SSL connections.
The property value is a whitespace separated list of tokens acceptable
to the javax.net.ssl.SSLSocket.setEnabledCipherSuites
method.
mail.pop3.starttls.enable
boolean
If true, enables the use of the STLS
command (if
supported by the server) to switch the connection to a TLS-protected
connection before issuing any login commands. Note that an appropriate
trust store must configured so that the client will trust the server's
certificate.
Defaults to false.
mail.pop3.starttls.required
boolean
If true, requires the use of the STLS
command.
If the server doesn't support the STLS command, or the command
fails, the connect method will fail.
Defaults to false.
mail.pop3.disabletop
boolean
If set to true, the POP3 TOP command will not be used to fetch
message headers. This is useful for POP3 servers that don't
properly implement the TOP command, or that provide incorrect
information in the TOP command results.
Defaults to false.
mail.pop3.forgettopheaders
boolean
If set to true, the headers that might have been retrieved using
the POP3 TOP command will be forgotten and replaced by headers
retrieved as part of the POP3 RETR command. Some servers, such
as some versions of Microsft Exchange and IBM Lotus Notes,
will return slightly different
headers each time the TOP or RETR command is used. To allow the
POP3 provider to properly parse the message content returned from
the RETR command, the headers also returned by the RETR command
must be used. Setting this property to true will cause these
headers to be used, even if they differ from the headers returned
previously as a result of using the TOP command.
Defaults to false.
In general, applications should not need to use the classes in this
package directly. Instead, they should use the APIs defined by
javax.mail
package (and subpackages). Applications should
never construct instances of POP3Store
or
POP3Folder
directly. Instead, they should use the
Session
method getStore
to acquire an
appropriate Store
object, and from that acquire
Folder
objects.
WARNING: The APIs unique to this package should be
considered EXPERIMENTAL. They may be changed in the
future in ways that are incompatible with applications using the
current APIs.