View Javadoc

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  package org.apache.jsieve.commands.optional;
21  
22  import org.apache.jsieve.Arguments;
23  import org.apache.jsieve.Block;
24  import org.apache.jsieve.SieveContext;
25  import org.apache.jsieve.StringListArgument;
26  import org.apache.jsieve.commands.AbstractActionCommand;
27  import org.apache.jsieve.exception.CommandException;
28  import org.apache.jsieve.exception.SieveException;
29  import org.apache.jsieve.mail.ActionReject;
30  import org.apache.jsieve.mail.MailAdapter;
31  
32  /**
33   * Class | Interface Enter description here
34   * 
35   * Creation Date: 11-Jan-04
36   * 
37   * @author sbrewin
38   * 
39   * Copyright 2003, Synergy Systems Limited
40   */
41  /**
42   * Class Reject implements the Reject Command as defined in RFC 3028, section
43   * 4.1.
44   */
45  public class Reject extends AbstractActionCommand {
46  
47      /**
48       * Constructor for Reject.
49       */
50      public Reject() {
51          super();
52      }
53  
54      /**
55       * <p>
56       * Add an ActionReject to the List of Actions to be performed.
57       * </p>
58       * <p>
59       * Also,
60       * 
61       * @see org.apache.jsieve.commands.AbstractCommand#executeBasic(MailAdapter,
62       *      Arguments, Block, SieveContext)
63       *      </p>
64       */
65      protected Object executeBasic(MailAdapter mail, Arguments arguments,
66              Block block, SieveContext context) throws SieveException {
67          final String message = ((StringListArgument) arguments
68                  .getArgumentList().get(0)).getList().get(0);
69  
70          mail.addAction(new ActionReject(message));
71          return null;
72      }
73  
74      /**
75       * @see org.apache.jsieve.commands.AbstractCommand#validateState(SieveContext)
76       */
77      protected void validateState(final SieveContext context)
78              throws CommandException {
79          super.validateState(context);
80  
81          if (context.getCommandStateManager().isHasActions())
82              throw context
83                      .getCoordinate()
84                      .commandException(
85                              "The \"reject\" command is not allowed with other Action Commands");
86      }
87  
88      /**
89       * @see org.apache.jsieve.commands.AbstractCommand#updateState(SieveContext)
90       */
91      protected void updateState(SieveContext context) {
92          super.updateState(context);
93          context.getCommandStateManager().setRejected(true);
94      }
95  
96      /**
97       * @see org.apache.jsieve.commands.AbstractCommand#validateArguments(Arguments,
98       *      SieveContext)
99       */
100     protected void validateArguments(Arguments arguments, SieveContext context)
101             throws SieveException {
102         validateSingleStringArguments(arguments, context);
103     }
104 
105 }