: Class Pop3Agent

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| ## TsBiff 1.3
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## ts.mail
Class Pop3Agent

    java.lang.Object
      |
      +--ts.mail.AbstractMailServer
            |
            +--ts.mail.Pop3Agent

All Implemented Interfaces:
  FetchAgent, SafeTerminate

public class Pop3Agent
extends AbstractMailServer
implements FetchAgent

This Class is a FetchAgent that connects to a POP3 server to fetch mail. The class extends the AbstractMailServer, and use the super class to connect to the server.

The class does not retrieve mail messages from the POP3 server, it only STAT and TOP the server. If the server does not support the TOP command an exception is thrown.

The getMail method implements the FetchAgents interface method getMail. It returns the content of the POP3 servers mail drop as a Vector of MailModel objects, where one MailModel represents one mail message from the mailbox file.

### Limitations:

The APOP command is not supported. Mostly because most POP3 servers doesn't support it.

Version:
  $Id: Pop3Agent.java,v 1.10 1999/11/28 04:03:32 hauk Exp $
Author:
  Jan-Henrik Haukeland <hauk@tildeslash.com>
See Also:
  `DefaultMailModel`, `FetchAgent`, `MailParser`

Inner Class Summary
`protected class` | `Pop3Agent.MailParserConnector`

Field Summary
`protected static int` | `DEFAULT_PORT` Default portnumber for the POP3 protocol
`protected java.io.BufferedReader` | `in` Server input stream
`protected java.lang.String` | `myPassword` Password at pop3 server
`protected java.lang.String` | `myUserName` Username at pop3 server
`protected java.io.PrintWriter` | `out` Server output stream
`protected static java.lang.String` | `POP3_ERROR` The POP3 error status indicators
`protected static java.lang.String` | `POP3_OK` The POP3 ok status indicators
`protected java.lang.String` | `PROTOCOL` Protocol used by this class

Fields inherited from class ts.mail.AbstractMailServer
`myMailServer, myMailServerPortNumber, SO_TIMEOUT`

Constructor Summary
`Pop3Agent(java.lang.String aServer)` Initializes the object with the given values for the mail server, using the default pop3 port.
`Pop3Agent(java.lang.String aServer, int aPort)` Initializes the object with the given values for the pop3 server

Method Summary
`protected void` | `authenticate()` Login to the POP3 server
`boolean` | `canTerminate()` Implementation of the SafeTerminate interface
`protected java.lang.String` | `command(java.lang.String action)` Send a command to the POP3 server and return the result string
`java.util.Vector` | `getMail()` Implementation of the getMail method.
`java.lang.String` | `getProtocol()` Returns this FetchAgents protocol
`protected java.lang.String` | `isOk()` Read a line from the server and check the response.
`protected java.util.Vector` | `parseMail()` Connect a stream with mail messages from the POP3 server to the MailParsers input stream.
`void` | `setAuth(java.lang.String uname, java.lang.String passwd)` Set username and password for authentication at the pop3 server
`void` | `setNumLines(int num)` Set maximum number of lines to read from a mail-message
`protected int` | `stat()` Stat the server and return the number of messages in the maildrop
`void` | `stopScan()` Stop current mail scan
`protected java.lang.String` | `top(int messageid)` Top a message and return the multi-line response from the server in a String.

Methods inherited from class ts.mail.AbstractMailServer
`closeConnection, getInputStream, getMailServer, getMailServerName, getMailServerPortNumber, getOutputStream, openConnection`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### PROTOCOL

    protected final java.lang.String PROTOCOL

  Protocol used by this class

### DEFAULT_PORT

    protected static final int DEFAULT_PORT

  Default portnumber for the POP3 protocol

### POP3_ERROR

    protected static final java.lang.String POP3_ERROR

  The POP3 error status indicators

### POP3_OK

    protected static final java.lang.String POP3_OK

  The POP3 ok status indicators

### myUserName

    protected java.lang.String myUserName

  Username at pop3 server

### myPassword

    protected java.lang.String myPassword

  Password at pop3 server

### out

    protected java.io.PrintWriter out

  Server output stream

### in

    protected java.io.BufferedReader in

  Server input stream

Constructor Detail

### Pop3Agent

    public Pop3Agent(java.lang.String aServer)
              throws java.net.UnknownHostException

  Initializes the object with the given values for the mail server, using the default pop3 port.
  Parameters:
    `aServer` - The POP3 server address
  Throws:
    `java.net.UnknownHostException` - Is thrown if no IP address for the host could be found

### Pop3Agent

    public Pop3Agent(java.lang.String aServer,
                     int aPort)
              throws java.net.UnknownHostException

  Initializes the object with the given values for the pop3 server
  Parameters:
    `aServer` - The POP3 server address
    `aPort` - The POP3 server port number
  Throws:
    `java.net.UnknownHostException` - Is thrown if no IP address for the host could be found

Method Detail

### canTerminate

    public boolean canTerminate()

  Implementation of the SafeTerminate interface
  Specified by:
    `canTerminate` in interface `SafeTerminate`
  Returns:
    true if it's safe to terminate

### setAuth

    public void setAuth(java.lang.String uname,
                        java.lang.String passwd)

  Set username and password for authentication at the pop3 server
  Parameters:
    `uname` - a pop3-server username
    `passwd` - the password that goes along with the uname
  Throws:
    `java.lang.IllegalArgumentException` - if uname or passwd is null

### setNumLines

    public void setNumLines(int num)

  Set maximum number of lines to read from a mail-message
  Parameters:
    `num` - maximum number of lines to read from a mail message
  Throws:
    `java.lang.IllegalArgumentException` - if num lines is less than 0

### getMail

    public java.util.Vector getMail()
                             throws GetMailException

  Implementation of the getMail method. This method opens a connection to the Mail server and read mail messages. Each message is put into a MailModel object.
  Specified by:
    `getMail` in interface `FetchAgent`
  Returns:
    A Vector with MailModel objects
  Throws:
    `GetMailException` - Thrown if mail for some reason could not be read

### getProtocol

    public java.lang.String getProtocol()

  Returns this FetchAgents protocol
  Specified by:
    `getProtocol` in interface `FetchAgent`
  Returns:
    The protocol used

### stopScan

    public void stopScan()

  Stop current mail scan
  Specified by:
    `stopScan` in interface `FetchAgent`

### authenticate

    protected void authenticate()
                         throws GetMailException

  Login to the POP3 server
  Throws:
    `GetMailException` - Is thrown if error status from server

### stat

    protected int stat()
                throws GetMailException

  Stat the server and return the number of messages in the maildrop
  Returns:
    number of messages in the maildrop
  Throws:
    `GetMailException` - thrown if drop listing format is wrong

### top

    protected java.lang.String top(int messageid)
                            throws GetMailException

  Top a message and return the multi-line response from the server in a String.
  Parameters:
    `messageid` - the id of the message to top
  Returns:
    content of mail message that was topped
  Throws:
    `GetMailException` - thrown if error response from server

### command

    protected java.lang.String command(java.lang.String action)
                                throws GetMailException

  Send a command to the POP3 server and return the result string
  Parameters:
    `action` - a POP3 protocol recognizable command
  Returns:
    result from pop server
  Throws:
    `GetMailException` - Thrown if could not write to server

### isOk

    protected java.lang.String isOk()
                             throws GetMailException

  Read a line from the server and check the response. The POP3 protocol has no granularity on status from the server. A response indicates either ok or error. An error response from the server will result in an exception thrown by this method. If the server respond +OK, this method return the respons minus the +OK prefix. E.g. after a STAT command, the server returns +OK 3 64302, this mehtod will return 3 64302.
  Returns:
    the respons, minus the status code (i.e. everything after +OK)
  Throws:
    `GetMailException` - Is thrown if error status from server

### parseMail

    protected java.util.Vector parseMail()
                                  throws GetMailException

  Connect a stream with mail messages from the POP3 server to the MailParsers input stream. This method returns a vector with MailModels from the parser, when the parser stops.
  Returns:
    a vector of MailModels from the MailParser
  Throws:
    `GetMailException` - Thrown if error from MailParser

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| ## TsBiff 1.3
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD