1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.apache.james.pop3server;
23
24 import org.apache.avalon.framework.configuration.Configuration;
25 import org.apache.avalon.framework.configuration.ConfigurationException;
26 import org.apache.avalon.framework.container.ContainerUtil;
27 import org.apache.avalon.framework.service.ServiceException;
28 import org.apache.avalon.framework.service.ServiceManager;
29 import org.apache.james.api.user.UsersRepository;
30 import org.apache.james.services.MailServer;
31 import org.apache.james.socket.AbstractJamesService;
32 import org.apache.james.socket.ProtocolHandler;
33
34
35
36
37
38
39
40
41 public class POP3Server extends AbstractJamesService implements POP3ServerMBean {
42
43
44
45
46
47 POP3HandlerChain handlerChain = new POP3HandlerChain();
48
49
50
51
52 private MailServer mailServer;
53
54
55
56
57 private UsersRepository users;
58
59
60
61
62
63
64 private int lengthReset = 20 * 1024;
65
66
67
68
69 private POP3HandlerConfigurationData theConfigData
70 = new POP3HandlerConfigurationDataImpl();
71
72 private ServiceManager serviceManager;
73
74 public void setMailServer(MailServer mailServer) {
75 this.mailServer = mailServer;
76 }
77
78 public void setUsers(UsersRepository users) {
79 this.users = users;
80 }
81
82
83
84
85 public void service( final ServiceManager componentManager )
86 throws ServiceException {
87 super.service(componentManager);
88 serviceManager = componentManager;
89 MailServer mailServer = (MailServer)componentManager.lookup( MailServer.ROLE );
90 setMailServer(mailServer);
91 UsersRepository users = (UsersRepository)componentManager.lookup( UsersRepository.ROLE );
92 setUsers(users);
93 }
94
95
96
97
98 public void configure(final Configuration configuration) throws ConfigurationException {
99 super.configure(configuration);
100 if (isEnabled()) {
101 Configuration handlerConfiguration = configuration.getChild("handler");
102 lengthReset = handlerConfiguration.getChild("lengthReset").getValueAsInteger(lengthReset);
103 if (getLogger().isInfoEnabled()) {
104 getLogger().info("The idle timeout will be reset every " + lengthReset + " bytes.");
105 }
106
107 ContainerUtil.enableLogging(handlerChain,getLogger());
108
109 try {
110 ContainerUtil.service(handlerChain,serviceManager);
111 } catch (ServiceException e) {
112 if (getLogger().isErrorEnabled()) {
113 getLogger().error("Failed to service handlerChain",e);
114 }
115 throw new ConfigurationException("Failed to service handlerChain");
116 }
117
118
119 ContainerUtil.configure(handlerChain,handlerConfiguration.getChild("handlerchain"));
120
121 }
122 }
123
124
125
126
127 protected int getDefaultPort() {
128 return 110;
129 }
130
131
132
133
134 public String getServiceType() {
135 return "POP3 Service";
136 }
137
138
139
140
141
142 public ProtocolHandler newProtocolHandlerInstance() {
143 POP3Handler protocolHandler = new POP3Handler();
144
145 protocolHandler.setHandlerChain(handlerChain);
146 return protocolHandler;
147 }
148
149
150
151
152 private class POP3HandlerConfigurationDataImpl
153 implements POP3HandlerConfigurationData {
154
155
156
157
158 public String getHelloName() {
159 if (POP3Server.this.helloName == null) {
160 return POP3Server.this.mailServer.getHelloName();
161 } else {
162 return POP3Server.this.helloName;
163 }
164 }
165
166
167
168
169 public int getResetLength() {
170 return POP3Server.this.lengthReset;
171 }
172
173
174
175
176 public MailServer getMailServer() {
177 return POP3Server.this.mailServer;
178 }
179
180
181
182
183 public UsersRepository getUsersRepository() {
184 return POP3Server.this.users;
185 }
186 }
187
188
189
190
191 protected Object getConfigurationData() {
192 return theConfigData;
193 }
194 }