View Javadoc

1   /*
2    * Copyright (c) 2004-2006 Creative Sphere Limited.
3    * All rights reserved. This program and the accompanying materials
4    * are made available under the terms of the Eclipse Public License v1.0
5    * which accompanies this distribution, and is available at
6    * http://www.eclipse.org/legal/epl-v10.html
7    *
8    * Contributors:
9    *
10   *   Creative Sphere - initial API and implementation
11   *
12   */
13  package org.abstracthorizon.mercury.imap.cmd;
14  
15  import java.io.IOException;
16  
17  import javax.mail.MessagingException;
18  
19  import org.abstracthorizon.mercury.common.command.CommandException;
20  
21  import org.abstracthorizon.mercury.imap.IMAPSession;
22  import org.abstracthorizon.mercury.imap.response.NOResponse;
23  import org.abstracthorizon.mercury.imap.response.Response;
24  import org.abstracthorizon.mercury.imap.util.ParserException;
25  import org.abstracthorizon.mercury.imap.util.IMAPScanner;
26  
27  /**
28   * UID prefix of IMAP command. It is treated as a command - but it is actually
29   * a wrapper to commands that follow UID
30   *
31   * @author Daniel Sendula
32   */
33  public class UID extends IMAPCommand {
34  
35      /**
36       * Constructor
37       * @param mnemonic menmonic
38       */
39      public UID(String mnemonic) {
40          super(mnemonic);
41      }
42  
43      /**
44       * Executes the command
45       * @param session
46       * @throws ParserException
47       * @throws MessagingException
48       * @throws CommandException
49       * @throws IOException
50       */
51      protected void execute(IMAPSession session) throws ParserException, MessagingException, CommandException, IOException {
52          IMAPScanner scanner = session.getScanner();
53          if (scanner.keyword("COPY")) {
54              session.getParent().invokeCommand(session, "COPY", true);
55          } else if (scanner.keyword("FETCH")) {
56              session.getParent().invokeCommand(session, "FETCH", true);
57          } else if (scanner.keyword("SEARCH")) {
58              session.getParent().invokeCommand(session, "SEARCH", true);
59          } else if (scanner.keyword("STORE")) {
60              session.getParent().invokeCommand(session, "STORE", true);
61          } else {
62              new NOResponse(session, Response.UNTAGGED_RESPONSE, "Error in UID command").submit();
63          }
64      }
65  }