001    /*
002     * Copyright 2010 the original author or authors.
003     * 
004     *  Licensed under the Apache License, Version 2.0 (the "License");
005     *  you may not use this file except in compliance with the License.
006     *  You may obtain a copy of the License at
007     *
008     *      http://www.apache.org/licenses/LICENSE-2.0
009     *
010     *  Unless required by applicable law or agreed to in writing, software
011     *  distributed under the License is distributed on an "AS IS" BASIS,
012     *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     *  See the License for the specific language governing permissions and
014     *  limitations under the License.
015     */
016    package com.hs.mail.imap.processor;
017    
018    import org.jboss.netty.channel.Channel;
019    
020    import com.hs.mail.imap.ImapSession;
021    import com.hs.mail.imap.mailbox.Mailbox;
022    import com.hs.mail.imap.mailbox.MailboxManager;
023    import com.hs.mail.imap.message.request.ImapRequest;
024    import com.hs.mail.imap.message.request.Status;
025    import com.hs.mail.imap.message.request.StatusRequest;
026    import com.hs.mail.imap.message.responder.Responder;
027    import com.hs.mail.imap.message.responder.StatusResponder;
028    import com.hs.mail.imap.message.response.HumanReadableText;
029    import com.hs.mail.imap.message.response.StatusResponse;
030    import com.hs.mail.imap.message.response.StatusResponseBuilder;
031    
032    /**
033     * 
034     * @author Won Chul Doh
035     * @since Feb 1, 2010
036     *
037     */
038    public class StatusProcessor extends AbstractImapProcessor {
039    
040            @Override
041            protected void doProcess(ImapSession session, ImapRequest message,
042                            Responder responder) {
043                    doProcess(session, (StatusRequest) message, (StatusResponder) responder);
044            }
045    
046            private void doProcess(ImapSession session, StatusRequest request,
047                            StatusResponder responder) {
048                    String mailboxName = request.getMailbox();
049                    Status attr = request.getStatusAtts();
050                    MailboxManager manager = getMailboxManager();
051                    Mailbox mailbox = manager.getMailbox(session.getUserID(), mailboxName);
052                    if (mailbox == null) {
053                            responder.taggedNo(request, HumanReadableText.MAILBOX_NOT_FOUND);
054                    } else {
055                            StatusResponse response = new StatusResponseBuilder().build(attr,
056                                            mailbox);
057                            responder.respond(response);
058                            responder.okCompleted(request);
059                    }
060            }
061            
062            @Override
063            protected Responder createResponder(Channel channel, ImapRequest request) {
064                    return new StatusResponder(channel, request);
065            }
066    
067    }