1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package org.apache.james.smtpserver.core.filter.fastfail;
24
25 import java.util.ArrayList;
26 import java.util.Collection;
27
28 import org.apache.avalon.framework.logger.AbstractLogEnabled;
29 import org.apache.james.dsn.DSNStatus;
30 import org.apache.james.smtpserver.CommandHandler;
31 import org.apache.james.smtpserver.SMTPSession;
32 import org.apache.mailet.MailAddress;
33
34
35
36
37
38 public class SupressDuplicateRcptHandler extends AbstractLogEnabled implements CommandHandler {
39
40
41
42
43 public Collection getImplCommands() {
44 Collection c = new ArrayList();
45 c.add("RCPT");
46
47 return c;
48 }
49
50
51
52
53 public void onCommand(SMTPSession session) {
54 MailAddress rcpt = (MailAddress) session.getState().get(SMTPSession.CURRENT_RECIPIENT);
55 Collection rcptList = (Collection) session.getState().get(SMTPSession.RCPT_LIST);
56
57
58 if(rcptList != null && rcptList.contains(rcpt)) {
59 StringBuffer responseBuffer = new StringBuffer();
60
61 responseBuffer.append("250 " + DSNStatus.getStatus(DSNStatus.SUCCESS, DSNStatus.ADDRESS_VALID) + " Recipient <")
62 .append(rcpt.toString()).append("> OK");
63 session.writeResponse(responseBuffer.toString());
64 session.setStopHandlerProcessing(true);
65
66 getLogger().debug("Duplicate recipient not add to recipient list: " + rcpt.toString());
67 }
68 }
69 }