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 java.util.ListIterator; 23 24 import org.apache.jsieve.Arguments; 25 import org.apache.jsieve.Block; 26 import org.apache.jsieve.SieveContext; 27 import org.apache.jsieve.StringListArgument; 28 import org.apache.jsieve.commands.AbstractActionCommand; 29 import org.apache.jsieve.exception.SieveException; 30 import org.apache.jsieve.mail.Action; 31 import org.apache.jsieve.mail.ActionFileInto; 32 import org.apache.jsieve.mail.MailAdapter; 33 34 /** 35 * Class FileInto implements the FileInto Command as defined in RFC 3028, 36 * section 4.2. 37 */ 38 public class FileInto extends AbstractActionCommand { 39 40 /** 41 * Constructor for Require. 42 */ 43 public FileInto() { 44 super(); 45 } 46 47 /** 48 * <p> 49 * Add an ActionFileInto to the List of Actions to be performed passing the 50 * sole StringList argument as the destination. RFC 3028 mandates that there 51 * should be only one FileInto per destination. If this is a duplicate, this 52 * Command is silently ignored. 53 * </p> 54 * <p> 55 * Also, 56 * 57 * @see org.apache.jsieve.commands.AbstractCommand#executeBasic(MailAdapter, 58 * Arguments, Block, SieveContext) 59 * </p> 60 */ 61 protected Object executeBasic(MailAdapter mail, Arguments arguments, 62 Block block, SieveContext context) throws SieveException { 63 String destination = (String) ((StringListArgument) arguments 64 .getArgumentList().get(0)).getList().get(0); 65 66 // Only one fileinto per destination allowed, others should be 67 // discarded 68 ListIterator actionsIter = mail.getActionsIterator(); 69 boolean isDuplicate = false; 70 while (actionsIter.hasNext()) { 71 Action action = (Action) actionsIter.next(); 72 isDuplicate = (action instanceof ActionFileInto) 73 && (((ActionFileInto) action).getDestination() 74 .equals(destination)); 75 } 76 77 if (!isDuplicate) 78 mail.addAction(new ActionFileInto(destination)); 79 80 return null; 81 } 82 83 /** 84 * @see org.apache.jsieve.commands.AbstractCommand#validateArguments(Arguments, 85 * SieveContext) 86 */ 87 protected void validateArguments(Arguments arguments, SieveContext context) 88 throws SieveException { 89 validateSingleStringArguments(arguments, context); 90 } 91 92 }