1 17 18 package org.apache.james.imapserver.commands; 19 20 import org.apache.james.imapserver.AccessControlException; 21 import org.apache.james.imapserver.ACLMailbox; 22 import org.apache.james.imapserver.ImapRequest; 23 import org.apache.james.imapserver.ImapSession; 24 import org.apache.james.imapserver.ImapSessionState; 25 26 import java.util.StringTokenizer ; 27 import java.util.List ; 28 29 class SelectCommand extends AuthenticatedSelectedStateCommand 30 { 31 public SelectCommand() 32 { 33 this.commandName = "SELECT"; 34 35 this.getArgs().add( new AstringArgument( "mailbox" ) ); 36 } 37 38 protected boolean doProcess( ImapRequest request, ImapSession session, List argValues ) 39 { 40 String command = this.getCommand(); 41 42 if ( session.getState() == ImapSessionState.SELECTED ) { 45 session.getCurrentMailbox().removeMailboxEventListener( session ); 46 session.getImapHost().releaseMailbox( session.getCurrentUser(), session.getCurrentMailbox() ); 47 session.setState( ImapSessionState.AUTHENTICATED ); 48 session.setCurrentMailbox( null ); 49 session.setCurrentIsReadOnly( false ); 50 } 51 52 String folder = (String ) argValues.get( 0 ); 53 ACLMailbox mailbox = getMailbox( session, folder, command ); 54 if ( mailbox == null ) { 55 return true; 56 } 57 else { 58 session.setCurrentMailbox( mailbox ); 59 } 60 61 try { if ( !session.getCurrentMailbox().hasReadRights( session.getCurrentUser() ) ) { 63 session.noResponse( command, "Read access not granted." ); 64 return true; 65 } 66 if ( command.equalsIgnoreCase( "SELECT" ) ) { 67 if ( !session.getCurrentMailbox().isSelectable( session.getCurrentUser() ) ) { 68 session.noResponse( "Mailbox exists but is not selectable" ); 69 return true; 70 } 71 } 72 73 session.getCurrentMailbox().addMailboxEventListener( session ); 75 session.setCurrentFolder( folder ); 76 session.setState( ImapSessionState.SELECTED ); 77 getLogger().debug( "Current folder for user " + session.getCurrentUser() + " from " 78 + session.getRemoteHost() + "(" + session.getRemoteIP() + ") is " 79 + session.getCurrentFolder() ); 80 81 session.getOut().println( UNTAGGED + SP + "FLAGS (" 83 + session.getCurrentMailbox().getSupportedFlags() + ")" ); 84 if ( !session.getCurrentMailbox().allFlags( session.getCurrentUser() ) ) { 85 session.untaggedResponse( " [PERMANENTFLAGS (" 86 + session.getCurrentMailbox().getPermanentFlags( session.getCurrentUser() ) 87 + ") ]" ); 88 } 89 session.checkSize(); 90 session.getOut().println( UNTAGGED + SP + OK + " [UIDVALIDITY " 91 + session.getCurrentMailbox().getUIDValidity() + "]" ); 92 int oldestUnseen = session.getCurrentMailbox().getOldestUnseen( session.getCurrentUser() ); 93 if ( oldestUnseen > 0 ) { 94 session.getOut().println( UNTAGGED + SP + OK + " [UNSEEN " 95 + oldestUnseen + "] " + oldestUnseen + " is the first unseen" ); 96 } 97 else { 98 session.getOut().println( UNTAGGED + SP + OK + " No unseen messages" ); 99 } 100 session.setSequence( session.getCurrentMailbox().listUIDs( session.getCurrentUser() )); 101 102 if ( command.equalsIgnoreCase( "EXAMINE" ) ) { 103 session.setCurrentIsReadOnly( true ); 104 105 session.okResponse("[READ-ONLY] " + command ); 106 return true; 107 108 } 109 else if ( session.getCurrentMailbox().isReadOnly( session.getCurrentUser() ) ) { 110 session.setCurrentIsReadOnly( true ); 111 session.okResponse( "[READ-ONLY] " + command ); 112 return true; 113 } 114 session.okResponse( "[READ-WRITE] " + command ); 115 return true; 116 } 117 catch ( AccessControlException ace ) { 118 session.noResponse( command, "No such mailbox." ); 119 session.logACE( ace ); 120 return true; 121 } 122 } 123 } 124 | Popular Tags |