JavaScript is disabled on your browser.
gnu.inet.imap

Class IMAPConnection

  • All Implemented Interfaces:
    IMAPConstants


    public class IMAPConnection
    extends java.lang.Object
    implements IMAPConstants 
    The protocol class implementing IMAP4rev1.

    To use this connection, you must implement an IMAPCallback either directly or by subclassing the IMAPAdapter class. This callback will be notified of the various IMAP events that occur during the processing of the command, since a single command may result in multiple events possibly unrelated to the intent of the caller (alerts, new message updates, etc).

    • Field Detail

      • IMAP_TRACE

        public static final java.util.logging.Level IMAP_TRACE
        The network trace level.
      • DEFAULT_PORT

        public static final int DEFAULT_PORT
        The default IMAP port.
        See Also:
        Constant Field Values
      • DEFAULT_SSL_PORT

        public static final int DEFAULT_SSL_PORT
        The default IMAP-SSL port.
        See Also:
        Constant Field Values
    • Constructor Detail

      • IMAPConnection

        public IMAPConnection(java.lang.String host)
        Creates a new connection to the default IMAP port.
        Parameters:
        host - the name of the host to connect to
      • IMAPConnection

        public IMAPConnection(java.lang.String host,
         int port)
        Creates a new connection.
        Parameters:
        host - the name of the host to connect to
        port - the port to connect to, or -1 for the default
      • IMAPConnection

        public IMAPConnection(java.lang.String host,
         int port,
         int connectionTimeout,
         int timeout)
        Creates a new connection.
        Parameters:
        host - the name of the host to connect to
        port - the port to connect to, or -1 for the default
        connectionTimeout - the socket connection timeout
        timeout - the socket timeout
      • IMAPConnection

        public IMAPConnection(java.lang.String host,
         int port,
         javax.net.ssl.TrustManager tm)
        Creates a new secure connection using the specified trust manager.
        Parameters:
        host - the name of the host to connect to
        port - the port to connect to, or -1 for the default
        tm - a trust manager used to check SSL certificates, or null to use the default
      • IMAPConnection

        public IMAPConnection(java.lang.String host,
         int port,
         int connectionTimeout,
         int timeout,
         boolean secure,
         javax.net.ssl.TrustManager tm)
        Creates a new connection.
        Parameters:
        host - the name of the host to connect to
        port - the port to connect to, or -1 for the default
        connectionTimeout - the socket connection timeout
        timeout - the socket timeout
        secure - if an IMAP-SSL connection should be made
        tm - a trust manager used to check SSL certificates, or null to use the default
    • Method Detail

      • setLiteralFactory

        public void setLiteralFactory(LiteralFactory factory,
         int threshold)
        Sets a literal factory for the connection. This must be called before connect()
        Parameters:
        factory - the factory
        threshold - the threshold over which literals are considered large
        See Also:
        LiteralFactory}
      • getLogger

        public java.util.logging.Logger getLogger()
        Returns the logger used by this connection for debug output.
      • newTag

        protected java.lang.String newTag()
        Returns a new tag for a command.
      • capability

        public boolean capability(IMAPCallback callback)
         throws java.io.IOException
        Returns a list of the capabilities of the IMAP server.
        Throws:
        java.io.IOException
      • noop

        public void noop(IMAPCallback callback)
         throws java.io.IOException
        Ping the server. The callback will be notified of any changes in state.
        Throws:
        java.io.IOException
      • getSSLSocketFactory

        protected javax.net.ssl.SSLSocketFactory getSSLSocketFactory(javax.net.ssl.TrustManager tm)
         throws java.security.GeneralSecurityException
        Returns a configured SSLSocketFactory to use in creating new SSL sockets.
        Parameters:
        tm - an optional trust manager to use
        Throws:
        java.security.GeneralSecurityException
      • starttls

        public boolean starttls(IMAPCallback callback)
         throws java.io.IOException
        Attempts to start TLS on the specified connection. See RFC 2595 for details.
        Returns:
        true if successful, false otherwise
        Throws:
        java.io.IOException
      • starttls

        public boolean starttls(IMAPCallback callback,
         javax.net.ssl.TrustManager tm)
         throws java.io.IOException
        Attempts to start TLS on the specified connection. See RFC 2595 for details.
        Parameters:
        tm - the custom trust manager to use
        Returns:
        true if successful, false otherwise
        Throws:
        java.io.IOException
      • login

        public boolean login(java.lang.String username,
         java.lang.String password,
         IMAPCallback callback)
         throws java.io.IOException
        Login to the connection using the username and password method.
        Parameters:
        username - the authentication principal
        password - the authentication credentials
        Returns:
        true if authentication was successful, false otherwise
        Throws:
        java.io.IOException
      • authenticate

        public boolean authenticate(java.lang.String mechanism,
         java.lang.String username,
         java.lang.String password,
         IMAPCallback callback)
         throws java.io.IOException
        Authenticates the connection using the specified SASL mechanism, username, and password.
        Parameters:
        mechanism - a SASL authentication mechanism, e.g. LOGIN, PLAIN, CRAM-MD5, GSSAPI
        username - the authentication principal
        password - the authentication credentials
        Returns:
        true if authentication was successful, false otherwise
        Throws:
        java.io.IOException
      • logout

        public void logout(IMAPCallback callback)
         throws java.io.IOException
        Logout this connection. Underlying network resources will be freed.
        Throws:
        java.io.IOException
      • select

        public boolean select(java.lang.String mailbox,
         IMAPCallback callback)
         throws java.io.IOException
        Selects the specified mailbox. The mailbox is identified as read-write if writes are permitted.
        Parameters:
        mailbox - the mailbox name
        callback - the callback to be notified of the state of the selected mailbox
        Throws:
        java.io.IOException
      • examine

        public boolean examine(java.lang.String mailbox,
         IMAPCallback callback)
         throws java.io.IOException
        Selects the specified mailbox. The mailbox is identified as read-only.
        Parameters:
        mailbox - the mailbox name
        callback - the callback to be notified of the state of the selected mailbox
        Throws:
        java.io.IOException
      • create

        public boolean create(java.lang.String mailbox,
         IMAPCallback callback)
         throws java.io.IOException
        Creates a mailbox with the specified name.
        Parameters:
        mailbox - the mailbox name
        Returns:
        true if the mailbox was successfully created, false otherwise
        Throws:
        java.io.IOException
      • delete

        public boolean delete(java.lang.String mailbox,
         IMAPCallback callback)
         throws java.io.IOException
        Deletes the mailbox with the specified name.
        Parameters:
        mailbox - the mailbox name
        Returns:
        true if the mailbox was successfully deleted, false otherwise
        Throws:
        java.io.IOException
      • rename

        public boolean rename(java.lang.String source,
         java.lang.String target,
         IMAPCallback callback)
         throws java.io.IOException
        Renames the source mailbox to the specified name.
        Parameters:
        source - the source mailbox name
        target - the target mailbox name
        Returns:
        true if the mailbox was successfully renamed, false otherwise
        Throws:
        java.io.IOException
      • subscribe

        public boolean subscribe(java.lang.String mailbox,
         IMAPCallback callback)
         throws java.io.IOException
        Adds the specified mailbox to the set of subscribed mailboxes as returned by the LSUB command.
        Parameters:
        mailbox - the mailbox name
        Returns:
        true if the mailbox was successfully subscribed, false otherwise
        Throws:
        java.io.IOException
      • unsubscribe

        public boolean unsubscribe(java.lang.String mailbox,
         IMAPCallback callback)
         throws java.io.IOException
        Removes the specified mailbox from the set of subscribed mailboxes as returned by the LSUB command.
        Parameters:
        mailbox - the mailbox name
        Returns:
        true if the mailbox was successfully unsubscribed, false otherwise
        Throws:
        java.io.IOException
      • list

        public boolean list(java.lang.String reference,
         java.lang.String mailbox,
         IMAPCallback callback)
         throws java.io.IOException
        Returns a subset of names from the complete set of names available to the client.
        Parameters:
        reference - the context relative to which mailbox names are defined
        mailbox - a mailbox name, possibly including IMAP wildcards
        Throws:
        java.io.IOException
      • lsub

        public boolean lsub(java.lang.String reference,
         java.lang.String mailbox,
         IMAPCallback callback)
         throws java.io.IOException
        Returns a subset of subscribed names.
        Parameters:
        reference - the context relative to which mailbox names are defined
        mailbox - a mailbox name, possibly including IMAP wildcards
        Throws:
        java.io.IOException
        See Also:
        list(java.lang.String, java.lang.String, gnu.inet.imap.IMAPCallback)
      • status

        public boolean status(java.lang.String mailbox,
         java.util.List<java.lang.String> statusNames,
         IMAPCallback callback)
         throws java.io.IOException
        Requests the status of the specified mailbox.
        Throws:
        java.io.IOException
      • append

        public boolean append(java.lang.String mailbox,
         java.util.List<java.lang.String> flags,
         java.util.Date date,
         byte[] content,
         IMAPCallback callback)
         throws java.io.IOException
        Append a message to the specified mailbox.
        Parameters:
        mailbox - the mailbox name
        flags - optional list of flags to specify for the message
        date - optional date of the message
        content - the RFC822 message (including headers)
        Returns:
        true if successful, false if error in flags/text
        Throws:
        java.io.IOException
      • check

        public boolean check(IMAPCallback callback)
         throws java.io.IOException
        Request a checkpoint of the currently selected mailbox.
        Throws:
        java.io.IOException
      • close

        public boolean close(IMAPCallback callback)
         throws java.io.IOException
        Permanently remove all messages that have the \Deleted flags set, and close the mailbox.
        Returns:
        true if successful, false if no mailbox was selected
        Throws:
        java.io.IOException
      • expunge

        public boolean expunge(IMAPCallback callback)
         throws java.io.IOException
        Permanently removes all messages that have the \Delete flag set.
        Throws:
        java.io.IOException
      • uidExpunge

        public boolean uidExpunge(UIDSet uids,
         IMAPCallback callback)
         throws java.io.IOException
        Permanently removes all messages in the specified UID-set that have the \Delete flag set.
        Parameters:
        uids - the non-null set of UIDs
        Throws:
        java.io.IOException
      • search

        public boolean search(java.lang.String charset,
         java.util.List<java.lang.String> criteria,
         IMAPCallback callback)
         throws java.io.IOException
        Searches the currently selected mailbox for messages matching the specified criteria.
        Parameters:
        charset - optional charset
        criteria - the list of criteria
        Throws:
        java.io.IOException
      • fetch

        public boolean fetch(MessageSet messages,
         java.util.List<java.lang.String> fetchCommands,
         IMAPCallback callback)
         throws java.io.IOException
        Retrieves data associated with the specified message in the mailbox.
        Parameters:
        message - the message number, or -1 for all messages
        fetchCommands - the fetch commands, e.g. FLAGS
        Throws:
        java.io.IOException
      • uidFetch

        public boolean uidFetch(UIDSet uids,
         java.util.List<java.lang.String> fetchCommands,
         IMAPCallback callback)
         throws java.io.IOException
        Retrieves data associated with the specified message in the mailbox.
        Parameters:
        uids - the message UIDs, or null for all messages
        fetchCommands - the fetch commands, e.g. FLAGS
        Throws:
        java.io.IOException
      • store

        public boolean store(MessageSet messages,
         java.lang.String flagCommand,
         java.util.List<java.lang.String> flags,
         IMAPCallback callback)
         throws java.io.IOException
        Alters data associated with the specified messages in the mailbox.
        Parameters:
        messages - the message set, or null for all messages
        flagCommand - FLAGS, +FLAGS, -FLAGS(or .SILENT versions)
        flags - message flags to set
        Throws:
        java.io.IOException
      • uidStore

        public boolean uidStore(UIDSet uids,
         java.lang.String flagCommand,
         java.util.List<java.lang.String> flags,
         IMAPCallback callback)
         throws java.io.IOException
        Alters data associated with the specified messages in the mailbox.
        Parameters:
        uids - the message UIDs, or null for all messages
        flagCommand - FLAGS, +FLAGS, -FLAGS(or .SILENT versions)
        flags - message flags to set
        Throws:
        java.io.IOException
      • copy

        public boolean copy(MessageSet messages,
         java.lang.String mailbox,
         IMAPCallback callback)
         throws java.io.IOException
        Copies the specified messages to the end of the destination mailbox.
        Parameters:
        messages - the message-set
        mailbox - the destination mailbox
        Throws:
        java.io.IOException
      • namespace

        public boolean namespace(IMAPCallback callback)
         throws java.io.IOException
        Returns the namespaces available on the server.
        Throws:
        java.io.IOException
        See Also:
        2342
      • setacl

        public boolean setacl(java.lang.String mailbox,
         java.lang.String principal,
         int rights,
         IMAPCallback callback)
         throws java.io.IOException
        Changes the access rights on the specified mailbox such that the authentication principal is granted the specified permissions.
        Parameters:
        mailbox - the mailbox name
        principal - the authentication identifier
        rights - the rights to assign
        Throws:
        java.io.IOException
        See Also:
        4314
      • deleteacl

        public boolean deleteacl(java.lang.String mailbox,
         java.lang.String principal,
         IMAPCallback callback)
         throws java.io.IOException
        Removes any access rights for the given authentication principal on the specified mailbox.
        Parameters:
        mailbox - the mailbox name
        principal - the authentication identifier
        Throws:
        java.io.IOException
        See Also:
        4314
      • getacl

        public boolean getacl(java.lang.String mailbox,
         IMAPCallback callback)
         throws java.io.IOException
        Returns the access control list for the specified mailbox.
        Parameters:
        mailbox - the mailbox name
        Throws:
        java.io.IOException
        See Also:
        4314
      • listrights

        public boolean listrights(java.lang.String mailbox,
         java.lang.String principal,
         IMAPCallback callback)
         throws java.io.IOException
        Returns the rights for the given principal for the specified mailbox. The returned rights are a logical OR of RIGHTS_* bits.
        Parameters:
        mailbox - the mailbox name
        principal - the authentication identity
        Throws:
        java.io.IOException
        See Also:
        4314
      • myrights

        public boolean myrights(java.lang.String mailbox,
         IMAPCallback callback)
         throws java.io.IOException
        Returns the rights for the current principal for the specified mailbox. The returned rights are a logical OR of RIGHTS_* bits.
        Parameters:
        mailbox - the mailbox name
        Throws:
        java.io.IOException
        See Also:
        4314
      • setquota

        public boolean setquota(java.lang.String quotaRoot,
         java.util.Map<java.lang.String,java.lang.Integer> resources,
         IMAPCallback callback)
         throws java.io.IOException
        Sets the quota for the specified quota root.
        Parameters:
        quotaRoot - the quota root
        resources - the list of resources and associated limits to set
        Throws:
        java.io.IOException
      • getquota

        public boolean getquota(java.lang.String quotaRoot,
         IMAPCallback callback)
         throws java.io.IOException
        Returns the specified quota root's resource usage and limits.
        Parameters:
        quotaRoot - the quota root
        Throws:
        java.io.IOException
      • getquotaroot

        public boolean getquotaroot(java.lang.String mailbox,
         IMAPCallback callback)
         throws java.io.IOException
        Returns the quotas for the given mailbox.
        Parameters:
        mailbox - the mailbox name
        Throws:
        java.io.IOException
      • uidExpunge

        public boolean uidExpunge(long start,
         long end,
         IMAPCallback callback)
         throws java.io.IOException
        Expunges the specified range of messages. See RFC 2359 for details.
        Parameters:
        start - the UID of the first message to expunge
        end - the UID of the last message to expunge
        Throws:
        java.io.IOException

AltStyle によって変換されたページ (->オリジナル) /