1 17 18 package org.apache.james.imapserver.commands; 19 20 import org.apache.james.imapserver.AuthorizationException; 21 import org.apache.james.imapserver.ImapRequest; 22 import org.apache.james.imapserver.ImapSession; 23 import org.apache.james.imapserver.ImapSessionState; 24 import org.apache.james.imapserver.MailboxException; 25 26 import java.util.StringTokenizer ; 27 import java.util.List ; 28 29 class RenameCommand extends AuthenticatedSelectedStateCommand 30 { 31 public RenameCommand() 32 { 33 this.commandName = "RENAME"; 34 35 this.getArgs().add( new AstringArgument( "oldName" ) ); 36 this.getArgs().add( new AstringArgument( "newName" ) ); 37 } 38 39 public boolean doProcess( ImapRequest request, ImapSession session, List argValues ) 40 { 41 String command = this.getCommand(); 42 43 String folder = (String ) argValues.get( 0 ); 44 String newName = (String ) argValues.get( 1 ); 45 46 if ( session.getCurrentFolder() == folder ) { 47 session.noResponse( command, "You can't rename a folder while you have it selected." ); 48 return true; 49 } 50 try { 51 if ( session.getImapHost().renameMailbox( session.getCurrentUser(), folder, newName ) ) { 52 session.okResponse( command ); 53 } 54 else { 55 session.noResponse( command, "Rename failed, unknown error" ); 56 getLogger().info( "Attempt to rename mailbox " + folder 57 + " to " + newName 58 + " by user " + session.getCurrentUser() + " failed." ); 59 } 60 } 61 catch ( MailboxException mbe ) { 62 if ( mbe.getStatus().equals( MailboxException.NOT_LOCAL ) ) { 63 session.taggedResponse( NO_NOTLOCAL_MSG ); 64 } 65 else { 66 session.noResponse( command, mbe.getMessage() ); 67 } 68 return true; 69 } 70 catch ( AuthorizationException aze ) { 71 session.noResponse( command, "You do not have the rights to delete mailbox: " + folder ); 72 return true; 73 } 74 if ( session.getState() == ImapSessionState.SELECTED ) { 75 session.checkSize(); 76 session.checkExpunge(); 77 } 78 return true; 79 } 80 } 81 | Popular Tags |