KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > providers > email > Pop3Connector


1 /*
2  * $Id: Pop3Connector.java 3798 2006-11-04 04:07:14Z aperepel $
3  * --------------------------------------------------------------------------------------
4  * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
5  *
6  * The software in this package is published under the terms of the MuleSource MPL
7  * license, a copy of which has been included with this distribution in the
8  * LICENSE.txt file.
9  */

10
11 package org.mule.providers.email;
12
13 import javax.mail.Authenticator JavaDoc;
14
15 import org.mule.providers.AbstractServiceEnabledConnector;
16 import org.mule.umo.UMOComponent;
17 import org.mule.umo.endpoint.UMOEndpoint;
18 import org.mule.umo.provider.UMOMessageReceiver;
19
20 /**
21  * <code>Pop3Connector</code> is used to connect and receive mail from a POP3
22  * mailbox
23  */

24 public class Pop3Connector extends AbstractServiceEnabledConnector implements MailConnector
25 {
26     public static final String JavaDoc MAILBOX = "INBOX";
27     public static final int DEFAULT_POP3_PORT = 110;
28     public static final int DEFAULT_CHECK_FREQUENCY = 60000;
29
30     /**
31      * Holds the time in milliseconds that the endpoint should wait before checking a
32      * mailbox
33      */

34     protected long checkFrequency = DEFAULT_CHECK_FREQUENCY;
35
36     /**
37      * holds a path where messages should be backed up to
38      */

39     protected String JavaDoc backupFolder = null;
40
41     /**
42      * A custom authenticator to bew used on any mail sessions created with this
43      * connector This will only be used if user name credendtials are set on the
44      * endpoint
45      */

46     protected Authenticator JavaDoc authenticator = null;
47
48     /**
49      * Once a message has been read, should it be deleted
50      */

51     protected boolean deleteReadMessages = true;
52
53     public Pop3Connector()
54     {
55         super();
56         // by default, close client connections to pop3 after the request.
57
this.setCreateDispatcherPerRequest(true);
58     }
59
60     /**
61      * @return the milliseconds between checking the folder for messages
62      */

63     public long getCheckFrequency()
64     {
65         return checkFrequency;
66     }
67
68     /*
69      * (non-Javadoc)
70      *
71      * @see org.mule.providers.UMOConnector#getProtocol()
72      */

73     public String JavaDoc getProtocol()
74     {
75         return "pop3";
76     }
77
78     /**
79      * @param l
80      */

81     public void setCheckFrequency(long l)
82     {
83         if (l < 1)
84         {
85             l = DEFAULT_CHECK_FREQUENCY;
86         }
87         checkFrequency = l;
88     }
89
90     /**
91      * @return a relative or absolute path to a directory on the file system
92      */

93     public String JavaDoc getBackupFolder()
94     {
95         return backupFolder;
96     }
97
98     /**
99      * @param string
100      */

101     public void setBackupFolder(String JavaDoc string)
102     {
103         backupFolder = string;
104     }
105
106     /*
107      * (non-Javadoc)
108      *
109      * @see org.mule.providers.UMOConnector#registerListener(javax.jms.MessageListener,
110      * java.lang.String)
111      */

112     public UMOMessageReceiver createReceiver(UMOComponent component, UMOEndpoint endpoint) throws Exception JavaDoc
113     {
114         Object JavaDoc[] args = {new Long JavaDoc(checkFrequency), backupFolder};
115         return serviceDescriptor.createMessageReceiver(this, component, endpoint, args);
116     }
117
118     public Authenticator JavaDoc getAuthenticator()
119     {
120         return authenticator;
121     }
122
123     public void setAuthenticator(Authenticator JavaDoc authenticator)
124     {
125         this.authenticator = authenticator;
126     }
127
128     public int getDefaultPort()
129     {
130         return DEFAULT_POP3_PORT;
131     }
132
133     public boolean isDeleteReadMessages()
134     {
135         return deleteReadMessages;
136     }
137
138     public void setDeleteReadMessages(boolean deleteReadMessages)
139     {
140         this.deleteReadMessages = deleteReadMessages;
141     }
142 }
143
Popular Tags