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.smtpserver.core.filter.fastfail;
23
24 import java.util.ArrayList;
25 import java.util.Collection;
26
27 import org.apache.avalon.framework.configuration.Configurable;
28 import org.apache.avalon.framework.configuration.Configuration;
29 import org.apache.avalon.framework.configuration.ConfigurationException;
30 import org.apache.james.dsn.DSNStatus;
31 import org.apache.james.smtpserver.CommandHandler;
32 import org.apache.james.smtpserver.SMTPSession;
33
34
35 public class MaxRcptHandler extends AbstractJunkHandler implements
36 CommandHandler, Configurable {
37
38 private int maxRcpt = 0;
39
40
41
42
43 public void configure(Configuration handlerConfiguration)
44 throws ConfigurationException {
45 Configuration configuration = handlerConfiguration.getChild("maxRcpt",
46 false);
47 if (configuration != null) {
48 setMaxRcpt(configuration.getValueAsInteger(0));
49 } else {
50 throw new ConfigurationException(
51 "Please set the maxRcpt configuration value");
52 }
53
54 super.configure(handlerConfiguration);
55 }
56
57
58
59
60
61
62
63 public void setMaxRcpt(int maxRcpt) {
64 this.maxRcpt = maxRcpt;
65 }
66
67
68
69
70 public void onCommand(SMTPSession session) {
71 doProcessing(session);
72 }
73
74
75
76
77 public Collection getImplCommands() {
78 Collection implCommands = new ArrayList();
79 implCommands.add("RCPT");
80
81 return implCommands;
82 }
83
84
85
86
87 protected boolean check(SMTPSession session) {
88
89 return ((session.getRcptCount() + 1) > maxRcpt);
90 }
91
92
93
94
95 public JunkHandlerData getJunkHandlerData(SMTPSession session) {
96 JunkHandlerData data = new JunkHandlerData();
97
98 data.setRejectResponseString("452 " + DSNStatus.getStatus(DSNStatus.NETWORK, DSNStatus.DELIVERY_TOO_MANY_REC)
99 + " Requested action not taken: max recipients reached");
100 data.setJunkScoreLogString("Maximum recipients of " + maxRcpt + " reached. Add JunkScore: " +getScore());
101 data.setRejectLogString("Maximum recipients of " + maxRcpt + " reached");
102 data.setScoreName("MaxRcptCheck");
103 return data;
104 }
105 }