james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject [jira] Closed: (JAMES-114) Enable FetchPop to access non-standard ports
Date Sun, 06 Jun 2004 18:57:55 GMT
Message:

   The following issue has been closed.

---------------------------------------------------------------------
View the issue:
  http://issues.apache.org/jira/browse/JAMES-114

Here is an overview of the issue:
---------------------------------------------------------------------
        Key: JAMES-114
    Summary: Enable FetchPop to access non-standard ports
       Type: Bug

     Status: Closed
 Resolution: WON'T FIX

    Project: James
 Components: 
             James Core
   Versions:
             2.1

   Assignee: 
   Reporter: John Witchel

    Created: Wed, 9 Jul 2003 8:29 PM
    Updated: Sun, 6 Jun 2004 11:57 AM
Environment: Operating System: Other
Platform: Other

Description:
This is a small but valuable feature.  Here's the trivial patch I wrote.  To 
run FetchPop against a non-standard port simply add a port child to the 
fetchpop configuration.  If not port is provided, the method runs as normal.

-- John 

public class FetchPOP extends AbstractLogEnabled implements Configurable, 
Target {
    /**
     * The MailServer service
     */
    private MailServer server;
    /**
     * The unique, identifying name for this task
     */
    private String fetchTaskName;
    /**
     * The POP3 server host name for this fetch task
     */
    private String popHost;
    /**
     * The POP3 user name for this fetch task
     */
    private String popUser;
    /**
     * The POP3 user password for this fetch task
     */
    private String popPass;
    /**
     * The POP3 port (optional)
     *
     */
     private int popPort;
    /**
     * @see 
org.apache.avalon.cornerstone.services.scheduler.Target#targetTriggered(String)
     */
    public void targetTriggered(String arg0) {
        if (getLogger().isDebugEnabled()) {
            getLogger().debug(fetchTaskName + " fetcher starting fetch");
        }
        
        POP3Client pop = new POP3Client();
        try {
            if(popPort == -1) { // No port specified
                pop.connect(popHost);
            } else {
            pop.connect(popHost, popPort);
            }
            
            pop.login(popUser, popPass);
            if (getLogger().isDebugEnabled()) {
                getLogger().debug("Login:" + pop.getReplyString());
            }
            pop.setState(POP3Client.TRANSACTION_STATE);
            POP3MessageInfo[] messages = pop.listMessages();
            getLogger().debug("List:" + pop.getReplyString());
            Vector received = new Vector();
            for (int i = 0; i < messages.length; i++) {
                InputStream in = new ReaderInputStream(pop.retrieveMessage
(messages[i].number));
                getLogger().debug("Retrieve:" + pop.getReplyString());
                MimeMessage message = null;
                try {
                    message = new MimeMessage(null, in);
                    in.close();
                    message.addHeader("X-fetched-from", fetchTaskName);
                    message.saveChanges();
                    try {
                        server.sendMail(message);
                        getLogger().debug("Sent message " + message.toString());
                        received.add(messages[i]);
                    } catch (MessagingException innerE) {
                        getLogger().error("can't insert message " + 
message.toString() + "created from "+messages[i].identifier);
                    }
                } catch (MessagingException outerE) {
                    getLogger().error("can't create message out of fetched 
message "+messages[i].identifier);
                }
            }
            Enumeration enum = received.elements();
            while (enum.hasMoreElements()) {
                POP3MessageInfo element = (POP3MessageInfo) enum.nextElement();
                pop.deleteMessage(element.number);
                if (getLogger().isDebugEnabled()) {
                    getLogger().debug("Delete:" + pop.getReplyString());
                }
            }
            pop.logout();
            if (getLogger().isDebugEnabled()) {
                getLogger().debug("logout:" + pop.getReplyString());
            }
            pop.disconnect();
        } catch (SocketException e) {
            getLogger().error(e.getMessage());
        } catch (IOException e) {
            getLogger().error(e.getMessage());
        }
    }
    /**
     * @see org.apache.avalon.framework.component.Composable#compose
(ComponentManager)
     */
    public void compose(final ComponentManager componentManager) throws 
ComponentException {
        try {
            server = (MailServer) componentManager.lookup(MailServer.ROLE);
        } catch (ClassCastException cce) {
            StringBuffer errorBuffer =
                new StringBuffer(128).append("Component ").append
(MailServer.ROLE).append(
                    "does not implement the required interface.");
            throw new ComponentException(errorBuffer.toString());
        }
    }
    /**
     * @see org.apache.avalon.framework.configuration.Configurable#configure
(Configuration)
     */
    public void configure(Configuration conf) throws ConfigurationException {
        this.popHost = conf.getChild("host").getValue();
        this.popUser = conf.getChild("user").getValue();
        this.popPass = conf.getChild("password").getValue();
        this.fetchTaskName = conf.getAttribute("name");
        this.popPort = conf.getChild("port").getValueAsInteger(-1);
        if (getLogger().isDebugEnabled()) {
            getLogger().info("Configured FetchPOP fetch task " + fetchTaskName);
        }
    }
}


---------------------------------------------------------------------
JIRA INFORMATION:
This message is automatically generated by JIRA.

If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa

If you want more information on JIRA, or have a bug to report see:
   http://www.atlassian.com/software/jira


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message