本文整理汇总了Java中com.icegreen.greenmail.imap.ProtocolException类的典型用法代码示例。如果您正苦于以下问题:Java ProtocolException类的具体用法?Java ProtocolException怎么用?Java ProtocolException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ProtocolException类属于com.icegreen.greenmail.imap包,在下文中一共展示了ProtocolException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setFlag
import com.icegreen.greenmail.imap.ProtocolException; //导入依赖的package包/类
public void setFlag(String flagString, Flags flags) throws ProtocolException {
if (flagString.equalsIgnoreCase(MessageFlags.ANSWERED)) {
flags.add(Flags.Flag.ANSWERED);
} else if (flagString.equalsIgnoreCase(MessageFlags.DELETED)) {
flags.add(Flags.Flag.DELETED);
} else if (flagString.equalsIgnoreCase(MessageFlags.DRAFT)) {
flags.add(Flags.Flag.DRAFT);
} else if (flagString.equalsIgnoreCase(MessageFlags.FLAGGED)) {
flags.add(Flags.Flag.FLAGGED);
} else if (flagString.equalsIgnoreCase(MessageFlags.SEEN)) {
flags.add(Flags.Flag.SEEN);
} else if (flagString.equalsIgnoreCase(MessageFlags.RECENT)) {
flags.add(Flags.Flag.RECENT);
} else {
// User flag
flags.add(flagString);
}
}
示例2: statusDataItems
import com.icegreen.greenmail.imap.ProtocolException; //导入依赖的package包/类
StatusDataItems statusDataItems(ImapRequestLineReader request)
throws ProtocolException {
StatusDataItems items = new StatusDataItems();
request.nextWordChar();
consumeChar(request, '(');
CharacterValidator validator = new NoopCharValidator();
String nextWord = consumeWord(request, validator);
while (!nextWord.endsWith(")")) {
addItem(nextWord, items);
nextWord = consumeWord(request, validator);
}
// Got the closing ")", may be attached to a word.
if (nextWord.length() > 1) {
addItem(nextWord.substring(0, nextWord.length() - 1), items);
}
return items;
}
示例3: addItem
import com.icegreen.greenmail.imap.ProtocolException; //导入依赖的package包/类
private void addItem(String nextWord, StatusDataItems items)
throws ProtocolException {
if (nextWord.equals(MESSAGES)) {
items.messages = true;
} else if (nextWord.equals(RECENT)) {
items.recent = true;
} else if (nextWord.equals(UIDNEXT)) {
items.uidNext = true;
} else if (nextWord.equals(UIDVALIDITY)) {
items.uidValidity = true;
} else if (nextWord.equals(UNSEEN)) {
items.unseen = true;
} else {
throw new ProtocolException("Unknown status item: '" + nextWord + "'");
}
}
示例4: doProcess
import com.icegreen.greenmail.imap.ProtocolException; //导入依赖的package包/类
/**
* @see CommandTemplate#doProcess
*/
protected void doProcess(ImapRequestLineReader request,
ImapResponse response,
ImapSession session)
throws ProtocolException {
String userid = parser.astring(request);
String password = parser.astring(request);
parser.endLine(request);
if (session.getUserManager().test(userid, password)) {
GreenMailUser user = session.getUserManager().getUser(userid);
session.setAuthenticated(user);
response.commandComplete(this);
} else {
response.commandFailed(this, "Invalid login/password");
}
}
示例5: nstring
import com.icegreen.greenmail.imap.ProtocolException; //导入依赖的package包/类
/**
* Reads an argument of type "nstring" from the request.
*/
public String nstring(ImapRequestLineReader request) throws ProtocolException {
char next = request.nextWordChar();
switch (next) {
case '"':
return consumeQuoted(request);
case '{':
return consumeLiteral(request);
default:
String value = atom(request);
if ("NIL".equals(value)) {
return null;
} else {
throw new ProtocolException("Invalid nstring value: valid values are '\"...\"', '{12} CRLF *CHAR8', and 'NIL'.");
}
}
}
示例6: date
import com.icegreen.greenmail.imap.ProtocolException; //导入依赖的package包/类
/**
* Reads a "date" argument from the request.
* TODO handle timezones properly
*/
public Date date(ImapRequestLineReader request) throws ProtocolException {
char next = request.nextWordChar();
String dateString;
if (next == '"') {
dateString = consumeQuoted(request);
} else {
dateString = atom(request);
}
DateFormat dateFormat = new SimpleDateFormat("dd-MMM-yyyy");
try {
return dateFormat.parse(dateString);
} catch (ParseException e) {
throw new ProtocolException("Invalid date format.");
}
}
示例7: consumeWord
import com.icegreen.greenmail.imap.ProtocolException; //导入依赖的package包/类
/**
* Reads the next "word from the request, comprising all characters up to the next SPACE.
* Characters are tested by the supplied CharacterValidator, and an exception is thrown
* if invalid characters are encountered.
*/
protected String consumeWord(ImapRequestLineReader request,
CharacterValidator validator)
throws ProtocolException {
StringBuffer atom = new StringBuffer();
char next = request.nextWordChar();
while (!isWhitespace(next)) {
if (validator.isValid(next)) {
atom.append(next);
request.consume();
} else {
throw new ProtocolException("Invalid character: '" + next + "'");
}
next = request.nextChar();
}
return atom.toString();
}
示例8: consumeQuoted
import com.icegreen.greenmail.imap.ProtocolException; //导入依赖的package包/类
/**
* Reads a quoted string value from the request.
*/
protected String consumeQuoted(ImapRequestLineReader request)
throws ProtocolException {
// The 1st character must be '"'
consumeChar(request, '"');
StringBuffer quoted = new StringBuffer();
char next = request.nextChar();
while (next != '"') {
if (next == '\\') {
request.consume();
next = request.nextChar();
if (!isQuotedSpecial(next)) {
throw new ProtocolException("Invalid escaped character in quote: '" +
next + "'");
}
}
quoted.append(next);
request.consume();
next = request.nextChar();
}
consumeChar(request, '"');
return quoted.toString();
}
示例9: doProcess
import com.icegreen.greenmail.imap.ProtocolException; //导入依赖的package包/类
/**
* @see CommandTemplate#doProcess
*/
protected void doProcess(ImapRequestLineReader request,
ImapResponse response,
ImapSession session)
throws ProtocolException, FolderException {
parser.endLine(request);
if (!session.getSelected().isReadonly()) {
MailFolder folder = session.getSelected();
folder.expunge();
}
session.deselect();
// Don't send unsolicited responses on close.
session.unsolicitedResponses(response);
response.commandComplete(this);
}
示例10: setFlag
import com.icegreen.greenmail.imap.ProtocolException; //导入依赖的package包/类
public void setFlag(String flagString, Flags flags) throws ProtocolException {
if (flagString.equalsIgnoreCase(MessageFlags.ANSWERED)) {
flags.add(Flags.Flag.ANSWERED);
} else if (flagString.equalsIgnoreCase(MessageFlags.DELETED)) {
flags.add(Flags.Flag.DELETED);
} else if (flagString.equalsIgnoreCase(MessageFlags.DRAFT)) {
flags.add(Flags.Flag.DRAFT);
} else if (flagString.equalsIgnoreCase(MessageFlags.FLAGGED)) {
flags.add(Flags.Flag.FLAGGED);
} else if (flagString.equalsIgnoreCase(MessageFlags.SEEN)) {
flags.add(Flags.Flag.SEEN);
} else {
throw new ProtocolException("Invalid flag string.");
}
}
示例11: addItem
import com.icegreen.greenmail.imap.ProtocolException; //导入依赖的package包/类
private void addItem(String nextWord, StatusDataItems items)
throws ProtocolException {
if (nextWord.equals(MESSAGES)) {
items.messages = true;
} else if (nextWord.equals(RECENT)) {
items.recent = true;
} else if (nextWord.equals(UIDNEXT)) {
items.uidNext = true;
} else if (nextWord.equals(UIDVALIDITY)) {
items.uidValidity = true;
} else if (nextWord.equals(UNSEEN)) {
items.unseen = true;
} else {
throw new ProtocolException("Unknown status item: '" + nextWord + '\'');
}
}
示例12: doProcess
import com.icegreen.greenmail.imap.ProtocolException; //导入依赖的package包/类
/**
* @see CommandTemplate#doProcess
*/
@Override
protected void doProcess(ImapRequestLineReader request,
ImapResponse response,
ImapSession session)
throws ProtocolException, FolderException {
parser.endLine(request);
if( session.getHost().getStore().isQuotaSupported()) {
response.untaggedResponse(CAPABILITY_RESPONSE + SP + "QUOTA");
}
else {
response.untaggedResponse(CAPABILITY_RESPONSE);
}
session.unsolicitedResponses(response);
response.commandComplete(this);
}
示例13: doProcess
import com.icegreen.greenmail.imap.ProtocolException; //导入依赖的package包/类
@Override
protected void doProcess(final ImapRequestLineReader request, final ImapResponse response,
final ImapSession session) throws ProtocolException, FolderException, AuthorizationException {
if(!session.getHost().getStore().isQuotaSupported()) {
response.commandFailed(this,"Quota is not supported. Activate quota capability first");
}
String root = parser.mailbox(request);
// NAME root (name usage limit)
Quota[] quota = session.getHost().getStore().getQuota(
root, session.getUser().getQualifiedMailboxName());
for(Quota q: quota) {
StringBuilder buf = new StringBuilder();
appendQuota(q, buf);
response.untaggedResponse(buf.toString());
}
response.commandComplete(this);
}
示例14: doProcess
import com.icegreen.greenmail.imap.ProtocolException; //导入依赖的package包/类
/**
* @see CommandTemplate#doProcess
*/
@Override
protected void doProcess(ImapRequestLineReader request,
ImapResponse response,
ImapSession session)
throws ProtocolException {
String userid = parser.astring(request);
String password = parser.astring(request);
parser.endLine(request);
if (session.getUserManager().test(userid, password)) {
GreenMailUser user = session.getUserManager().getUser(userid);
session.setAuthenticated(user);
response.commandComplete(this);
} else {
response.commandFailed(this, "Invalid login/password for user id "+userid);
}
}
示例15: dateTime
import com.icegreen.greenmail.imap.ProtocolException; //导入依赖的package包/类
/**
* Reads a "date-time" argument from the request.
*/
public Date dateTime(ImapRequestLineReader request) throws ProtocolException {
char next = request.nextWordChar();
String dateString;
// From https://tools.ietf.org/html/rfc3501 :
// date-time = DQUOTE date-day-fixed "-" date-month "-" date-year
// SP time SP zone DQUOTE
// zone = ("+" / "-") 4DIGIT
if (next == '"') {
dateString = consumeQuoted(request);
} else {
throw new ProtocolException("DateTime values must be quoted.");
}
try {
// You can use Z or zzzz
return new SimpleDateFormat("dd-MMM-yyyy hh:mm:ss Z", Locale.US).parse(dateString);
} catch (ParseException e) {
throw new ProtocolException("Invalid date format <" + dateString + ">, should comply to dd-MMM-yyyy hh:mm:ss Z");
}
}