in geronimo-mail_2.1_impl/geronimo-mail_2.1_provider/src/main/java/org/apache/geronimo/mail/store/imap/connection/IMAPResponseTokenizer.java [1354:1421]
public Flags readFlagList() throws MessagingException {
Flags flags = new Flags();
// this should be a list here
checkLeftParen();
// run through the flag list
while (notListEnd()) {
// the flags are a bit of a pain. The flag names include "\" in the name, which
// is not a character allowed in an atom. This requires a bit of customized parsing
// to handle this.
Token token = next();
// flags can be specified as just atom tokens, so allow this as a user flag.
if (token.isType(token.ATOM)) {
// append the atom as a raw name
flags.add(token.getValue());
}
// all of the system flags start with a '\' followed by
// an atom. They also can be extension flags. IMAP has a special
// case of "\*" that we need to check for.
else if (token.isType('\\')) {
token = next();
// the next token is the real bit we need to process.
if (token.isType('*')) {
// this indicates USER flags are allowed.
flags.add(Flags.Flag.USER);
}
// if this is an atom name, handle as a system flag
else if (token.isType(Token.ATOM)) {
String name = token.getValue();
if (name.equalsIgnoreCase("Seen")) {
flags.add(Flags.Flag.SEEN);
}
else if (name.equalsIgnoreCase("RECENT")) {
flags.add(Flags.Flag.RECENT);
}
else if (name.equalsIgnoreCase("DELETED")) {
flags.add(Flags.Flag.DELETED);
}
else if (name.equalsIgnoreCase("ANSWERED")) {
flags.add(Flags.Flag.ANSWERED);
}
else if (name.equalsIgnoreCase("DRAFT")) {
flags.add(Flags.Flag.DRAFT);
}
else if (name.equalsIgnoreCase("FLAGGED")) {
flags.add(Flags.Flag.FLAGGED);
}
else {
// this is a server defined flag....just add the name with the
// flag thingy prepended.
flags.add("\\" + name);
}
}
else {
throw new MessagingException("Invalid Flag: " + token.getValue());
}
}
else {
throw new MessagingException("Invalid Flag: " + token.getValue());
}
}
// step over this for good practice.
checkRightParen();
return flags;
}