referenceRoot = "";
removeUserPrefix = true;
}
// Get the mailbox for the reference name.
MailFolder referenceFolder = getMailbox(referenceRoot, session, false);
// If it doesn't exist, act as though "" was passed for reference name.
if (referenceFolder == null) {
referenceFolder = getMailbox("", session, true);
removeUserPrefix = true;
}
mailboxes = new ArrayList(1);
mailboxes.add(referenceFolder);
} else {
String searchPattern;
// If the mailboxPattern is fully qualified, ignore the
// reference name.
if (mailboxPattern.charAt(0) == NAMESPACE_PREFIX_CHAR) {
searchPattern = mailboxPattern;
} else {
searchPattern = combineSearchTerms(referenceName, mailboxPattern);
}
// If the search pattern is relative, need to remove user prefix from results.
removeUserPrefix = (searchPattern.charAt(0) != NAMESPACE_PREFIX_CHAR);
mailboxes = doList(session, searchPattern);
}
String personalNamespace = USER_NAMESPACE + HIERARCHY_DELIMITER_CHAR +
session.getUser().getQualifiedMailboxName();
int prefixLength = personalNamespace.length();
Iterator iterator = mailboxes.iterator();
while (iterator.hasNext()) {
MailFolder folder = (MailFolder) iterator.next();
StringBuffer message = new StringBuffer("(");
if (!folder.isSelectable()) {
message.append("\\Noselect");
}
message.append(") \"");
message.append(HIERARCHY_DELIMITER_CHAR);
message.append("\" ");
String mailboxName = folder.getFullName();
if (removeUserPrefix) {
if (mailboxName.length() <= prefixLength) {
mailboxName = "";
} else {
mailboxName = mailboxName.substring(prefixLength + 1);