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
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 * This handler can be used to just ignore duplicated recipients.
37 */
38 public class SupressDuplicateRcptHandler extends AbstractLogEnabled implements CommandHandler {
39
40 /**
41 * @see org.apache.james.smtpserver.CommandHandler#getImplCommands()
42 */
43 public Collection getImplCommands() {
44 Collection c = new ArrayList();
45 c.add("RCPT");
46
47 return c;
48 }
49
50 /**
51 * @see org.apache.james.smtpserver.CommandHandler#onCommand(SMTPSession)
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 // Check if the recipient is allready in the rcpt list
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 }