1 /*****************************************************************
2 * Licensed to the Apache Software Foundation (ASF) under one *
3 * or more contributor license agreements. See the NOTICE file *
4 * distributed with this work for additional information *
5 * regarding copyright ownership. The ASF licenses this file *
6 * to you under the Apache License, Version 2.0 (the *
7 * "License"); you may not use this file except in compliance *
8 * with the License. You may obtain a copy of the License at *
9 * *
10 * http://www.apache.org/licenses/LICENSE-2.0 *
11 * *
12 * Unless required by applicable law or agreed to in writing, *
13 * software distributed under the License is distributed on an *
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
15 * KIND, either express or implied. See the License for the *
16 * specific language governing permissions and limitations *
17 * under the License. *
18 ****************************************************************/
19
20
21 package org.apache.james.postage.smtpserver;
22
23 import org.apache.avalon.framework.configuration.DefaultConfiguration;
24 import org.apache.avalon.framework.configuration.Configuration;
25
26 public class SimpleSMTPServerConfiguration extends DefaultConfiguration {
27 private int m_smtpListenerPort;
28 private String m_authorizedAddresses = "127.0.0.0/8";
29 private String m_authorizingMode = "false";
30
31 public static Configuration getValuedConfiguration(String name, String value) {
32 DefaultConfiguration defaultConfiguration = new DefaultConfiguration(name);
33 defaultConfiguration.setValue(value);
34 return defaultConfiguration;
35 }
36
37 public SimpleSMTPServerConfiguration(int smtpListenerPort) {
38 super("smptserver");
39
40 m_smtpListenerPort = smtpListenerPort;
41 }
42
43 public String getAuthorizedAddresses() {
44 return m_authorizedAddresses;
45 }
46
47 public void setAuthorizedAddresses(String authorizedAddresses) {
48 m_authorizedAddresses = authorizedAddresses;
49 }
50
51 public void setAuthorizingNotRequired() {
52 m_authorizingMode = "false";
53 }
54
55 public void setAuthorizingRequired() {
56 m_authorizingMode = "true";
57
58 }
59
60 public void setAuthorizingAnnounce() {
61 m_authorizingMode = "announce";
62
63 }
64
65 public void init() {
66
67 setAttribute("enabled", true);
68
69 addChild(getValuedConfiguration("port", "" + m_smtpListenerPort));
70
71 DefaultConfiguration handlerConfig = new DefaultConfiguration("handler");
72 handlerConfig.addChild(getValuedConfiguration("helloName", "myMailServer"));
73 handlerConfig.addChild(getValuedConfiguration("connectiontimeout", "360000"));
74 handlerConfig.addChild(getValuedConfiguration("authorizedAddresses", m_authorizedAddresses));
75 handlerConfig.addChild(getValuedConfiguration("maxmessagesize", "" + 0));
76 handlerConfig.addChild(getValuedConfiguration("authRequired", m_authorizingMode));
77
78 addChild(handlerConfig);
79 }
80
81 }