final boolean isRelative;
final List<MailboxMetaData> results;
final String user = ImapSessionUtils.getUserName(session);
final MailboxSession mailboxSession = ImapSessionUtils.getMailboxSession(session);
if (mailboxName.length() == 0) {
// An empty mailboxName signifies a request for the hierarchy
// delimiter and root name of the referenceName argument
String referenceRoot;
if (referenceName.length() > 0 && referenceName.charAt(0) == MailboxConstants.NAMESPACE_PREFIX_CHAR) {
// A qualified reference name - get the root element
isRelative = false;
int firstDelimiter = referenceName.indexOf(mailboxSession.getPathDelimiter());
if (firstDelimiter == -1) {
referenceRoot = referenceName;
} else {
referenceRoot = referenceName.substring(0, firstDelimiter);
}
} else {
// A relative reference name, return "" to indicate it is
// non-rooted
referenceRoot = "";
isRelative = true;
}
// Get the mailbox for the reference name.
MailboxPath rootPath = new MailboxPath(referenceRoot, "", "");
results = new ArrayList<MailboxMetaData>(1);
results.add(SimpleMailboxMetaData.createNoSelect(rootPath, mailboxSession.getPathDelimiter()));
} else {
// If the mailboxPattern is fully qualified, ignore the
// reference name.
String finalReferencename = referenceName;
if (mailboxName.charAt(0) == MailboxConstants.NAMESPACE_PREFIX_CHAR) {
finalReferencename = "";
}
// Is the interpreted (combined) pattern relative?
isRelative = ((finalReferencename + mailboxName).charAt(0) != MailboxConstants.NAMESPACE_PREFIX_CHAR);
MailboxPath basePath = null;
if (isRelative) {
basePath = new MailboxPath(MailboxConstants.USER_NAMESPACE, user, finalReferencename);
} else {
basePath = buildFullPath(session, finalReferencename);
}
results = getMailboxManager().search(new MailboxQuery(basePath, mailboxName, mailboxSession.getPathDelimiter()), mailboxSession);
}
for (final MailboxMetaData metaData : results) {
processResult(responder, isRelative, metaData, getMailboxType(session, mailboxTyper, metaData.getPath()));
}