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;
21
22 import org.apache.jsieve.Arguments;
23 import org.apache.jsieve.Block;
24 import org.apache.jsieve.SieveContext;
25 import org.apache.jsieve.exception.SieveException;
26 import org.apache.jsieve.mail.MailAdapter;
27
28 /**
29 * Class Else implements the Else Command as defined in RFC 3028, section 3.1.
30 */
31 public class Else extends AbstractConditionalCommand {
32
33 /**
34 * Constructor for Else.
35 */
36 public Else() {
37 super();
38 }
39
40 /**
41 * <p>
42 * Conditionally eexecute a Block if an Else Condition is runnable.
43 * </p>
44 * <p>
45 * Also,
46 *
47 * @see org.apache.jsieve.commands.AbstractCommand#executeBasic(MailAdapter,
48 * Arguments, Block, SieveContext)
49 * </p>
50 */
51 protected Object executeBasic(MailAdapter mail, Arguments arguments,
52 Block block, SieveContext context) throws SieveException {
53 // Check Syntax
54 if (!context.getConditionManager().isElseAllowed())
55 throw context.getCoordinate().commandException(
56 "Unexpected Command: \"else\".");
57
58 // Check Runnable
59 if (!context.getConditionManager().isElseRunnable())
60 return Boolean.FALSE;
61
62 // Execute the Block
63 execute(mail, block, context);
64
65 // Update the ConditionManager
66 // 'Else' is always true
67 context.getConditionManager().setElseTestResult(true);
68
69 // Return the result
70 return Boolean.TRUE;
71 }
72
73 }