001    /****************************************************************
002     * Licensed to the Apache Software Foundation (ASF) under one   *
003     * or more contributor license agreements.  See the NOTICE file *
004     * distributed with this work for additional information        *
005     * regarding copyright ownership.  The ASF licenses this file   *
006     * to you under the Apache License, Version 2.0 (the            *
007     * "License"); you may not use this file except in compliance   *
008     * with the License.  You may obtain a copy of the License at   *
009     *                                                              *
010     *   http://www.apache.org/licenses/LICENSE-2.0                 *
011     *                                                              *
012     * Unless required by applicable law or agreed to in writing,   *
013     * software distributed under the License is distributed on an  *
014     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
015     * KIND, either express or implied.  See the License for the    *
016     * specific language governing permissions and limitations      *
017     * under the License.                                           *
018     ****************************************************************/
019    
020    
021    
022    package org.apache.james.protocols.smtp.core;
023    
024    import java.util.ArrayList;
025    import java.util.Collection;
026    
027    import org.apache.james.protocols.smtp.SMTPResponse;
028    import org.apache.james.protocols.smtp.SMTPRetCode;
029    import org.apache.james.protocols.smtp.SMTPSession;
030    import org.apache.james.protocols.smtp.dsn.DSNStatus;
031    import org.apache.james.protocols.smtp.hook.HookResult;
032    import org.apache.james.protocols.smtp.hook.UnknownHook;
033    
034    /**
035      * Default command handler for handling unknown commands
036      */
037    public class UnknownCmdHandler extends AbstractHookableCmdHandler<UnknownHook>{
038    
039        /**
040         * The name of the command handled by the command handler
041         */
042        public static final String UNKNOWN_COMMAND = "UNKNOWN";
043    
044        /**
045         * @see org.apache.james.protocols.api.handler.CommandHandler#getImplCommands()
046         */
047        public Collection<String> getImplCommands() {
048            Collection<String> implCommands = new ArrayList<String>();
049            implCommands.add(UNKNOWN_COMMAND);
050    
051            return implCommands;
052        }
053    
054        @Override
055        protected SMTPResponse doCoreCmd(SMTPSession session, String command, String parameters) {
056            StringBuilder result = new StringBuilder();
057            result.append(DSNStatus.getStatus(DSNStatus.PERMANENT, DSNStatus.DELIVERY_INVALID_CMD)).append(" Command ").append(command).append(" unrecognized.");
058            return new SMTPResponse(SMTPRetCode.SYNTAX_ERROR_COMMAND_UNRECOGNIZED, result);
059        }
060    
061        @Override
062        protected SMTPResponse doFilterChecks(SMTPSession session, String command, String parameters) {
063            session.getState().put("CURR_COMMAND", command);
064            return null;
065        }
066    
067        @Override
068        protected HookResult callHook(UnknownHook rawHook, SMTPSession session, String parameters) {
069            return rawHook.doUnknown(session, (String) session.getState().get("CURR_COMMAND"));
070        }
071    
072        @Override
073        protected Class<UnknownHook> getHookInterface() {
074            return UnknownHook.class;
075        }
076    }