use of com.zimbra.cs.mailclient.CommandFailedException in project zm-mailbox by Zimbra.
the class SmtpConnection method readHelloReplies.
/**
* Reads replies to {@code EHLO} or {@code HELO}.
* <p>
* Returns the reply code. Handles multiple {@code 250} responses.
*
* @param command the command name
* @param firstReply the first reply line returned from sending {@code EHLO} or {@code HELO}
*/
private int readHelloReplies(String command, Reply firstReply) throws IOException {
Reply reply = firstReply;
int line = 1;
serverExtensions.clear();
serverAuthMechanisms.clear();
while (true) {
if (reply.text == null) {
throw new CommandFailedException(command, "Invalid server response at line " + line + ": " + reply);
}
if (reply.code != 250) {
return reply.code;
}
if (line > 1) {
// Parse server extensions.
Matcher matcher = PAT_EXTENSION.matcher(reply.text);
if (matcher.matches()) {
String extName = matcher.group(1).toUpperCase();
serverExtensions.add(extName);
if (extName.equals(AUTH)) {
// Parse auth mechanisms.
Splitter splitter = Splitter.on(CharMatcher.WHITESPACE).trimResults().omitEmptyStrings();
for (String mechanism : splitter.split(matcher.group(2))) {
serverAuthMechanisms.add(mechanism.toUpperCase());
}
}
}
}
if (reply.last) {
// Last 250 response.
mailIn.trace();
return 250;
} else {
// Multiple response lines.
reply = Reply.parse(mailIn.readLine());
}
line++;
}
}
use of com.zimbra.cs.mailclient.CommandFailedException in project zm-mailbox by Zimbra.
the class ImapRequest method failed.
public CommandFailedException failed(String error, Throwable cause) {
CommandFailedException cfe = new CommandFailedException(cmd.getName(), error);
try {
cfe.setRequest(toString());
} catch (Exception e) {
}
cfe.initCause(cause);
return cfe;
}
use of com.zimbra.cs.mailclient.CommandFailedException in project zm-mailbox by Zimbra.
the class TestImap method appendInvalidFlag.
private void appendInvalidFlag(String flag) throws IOException {
Literal msg = message(10);
Flags flags = Flags.fromSpec("afs");
flags.set(flag);
Date date = new Date(System.currentTimeMillis());
try {
AppendResult res = connection.append("INBOX", flags, date, msg);
fail("server allowed client to set system flag " + flag);
} catch (CommandFailedException e) {
//expected
} finally {
msg.dispose();
}
//do a no-op so we don't hit max consecutive error limit
connection.noop();
}
use of com.zimbra.cs.mailclient.CommandFailedException in project zm-mailbox by Zimbra.
the class TestImapThrottle method uidfetch.
@Test
public void uidfetch() throws IOException {
Flags flags = Flags.fromSpec("afs");
for (int i = 0; i < 3; i++) {
Date date = new Date(System.currentTimeMillis());
Literal msg = message(1000 + i * 1000);
try {
connection.append("INBOX", flags, date, msg);
} finally {
msg.dispose();
}
}
for (int i = 0; i < LOOP_LIMIT; i++) {
connection.uidFetch("1:*", new String[] { "FLAGS", "UID" });
}
try {
connection.uidFetch("1:*", new String[] { "FLAGS", "UID" });
Assert.fail("should have been rejected");
} catch (CommandFailedException e) {
Assert.assertTrue(connection.isClosed());
}
}
use of com.zimbra.cs.mailclient.CommandFailedException in project zm-mailbox by Zimbra.
the class TestImapThrottle method store.
@Test
public void store() throws IOException {
Flags flags = Flags.fromSpec("afs");
for (int i = 0; i < 3; i++) {
Date date = new Date(System.currentTimeMillis());
Literal msg = message(1000 + i * 1000);
try {
connection.append("INBOX", flags, date, msg);
} finally {
msg.dispose();
}
}
for (int i = 0; i < LOOP_LIMIT; i++) {
connection.store("1:3", "FLAGS", new String[] { "FOO", "BAR" });
}
try {
connection.store("1:3", "FLAGS", new String[] { "FOO", "BAR" });
Assert.fail("should have been rejected");
} catch (CommandFailedException e) {
Assert.assertTrue(connection.isClosed());
}
}
Aggregations