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 java.util.ArrayList;
019 import java.util.List;
020
021 import com.hs.mail.imap.mailbox.Mailbox;
022 import com.hs.mail.imap.mailbox.MailboxManager;
023 import com.hs.mail.imap.mailbox.MailboxQuery;
024
025 /**
026 *
027 * @author Won Chul Doh
028 * @since Feb 1, 2010
029 *
030 */
031 public class ListProcessor extends AbstractListProcessor {
032
033 @Override
034 protected List<Mailbox> listMailbox(long userID, long ownerID,
035 String mailboxName, MailboxQuery query) {
036 MailboxManager manager = getMailboxManager();
037 List<Mailbox> children = manager.getChildren(userID, ownerID,
038 mailboxName, false);
039 List<Mailbox> results = new ArrayList<Mailbox>();
040 for (Mailbox child : children) {
041 if (query.match(child.getName())) {
042 child.setHasChildren(manager.hasChildren(child));
043 results.add(child);
044 }
045 }
046 return results;
047 }
048
049 @Override
050 protected Mailbox getMailbox(long ownerID, String mailboxName) {
051 MailboxManager manager = getMailboxManager();
052 Mailbox result = manager.getMailbox(ownerID, mailboxName);
053 if (result != null) {
054 result.setHasChildren(manager.hasChildren(result));
055 }
056 return result;
057 }
058
059 }