Refactor PopConnection, use enumeration instead of int

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@2246 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2014-03-10 21:01:48 +00:00
parent 1f11758bb2
commit 0440d25b84
1 changed files with 18 additions and 20 deletions

View File

@ -205,7 +205,7 @@ public class PopConnection extends AbstractConnection {
ExchangeSession.Message message = messages.get(messageNumber); ExchangeSession.Message message = messages.get(messageNumber);
// load big messages in a separate thread // load big messages in a separate thread
os.write("+OK ".getBytes()); os.write("+OK ".getBytes("ASCII"));
os.flush(); os.flush();
MessageLoadThread.loadMimeMessage(message, os); MessageLoadThread.loadMimeMessage(message, os);
sendClient(""); sendClient("");
@ -309,14 +309,12 @@ public class PopConnection extends AbstractConnection {
* Filter to limit output lines to max body lines after header * Filter to limit output lines to max body lines after header
*/ */
private static final class TopOutputStream extends FilterOutputStream { private static final class TopOutputStream extends FilterOutputStream {
private static final int START = 0; protected static enum State {
private static final int CR = 1; START, CR, CRLF, CRLFCR, BODY
private static final int CRLF = 2; }
private static final int CRLFCR = 3;
private static final int BODY = 4;
private int maxLines; private int maxLines;
private int state = START; private State state = State.START;
private TopOutputStream(OutputStream os, int maxLines) { private TopOutputStream(OutputStream os, int maxLines) {
super(os); super(os);
@ -325,34 +323,34 @@ public class PopConnection extends AbstractConnection {
@Override @Override
public void write(int b) throws IOException { public void write(int b) throws IOException {
if (state != BODY || maxLines > 0) { if (state != State.BODY || maxLines > 0) {
super.write(b); super.write(b);
} }
if (state == BODY) { if (state == State.BODY) {
if (b == '\n') { if (b == '\n') {
maxLines--; maxLines--;
} }
} else if (state == START) { } else if (state == State.START) {
if (b == '\r') { if (b == '\r') {
state = CR; state = State.CR;
} }
} else if (state == CR) { } else if (state == State.CR) {
if (b == '\n') { if (b == '\n') {
state = CRLF; state = State.CRLF;
} else { } else {
state = START; state = State.START;
} }
} else if (state == CRLF) { } else if (state == State.CRLF) {
if (b == '\r') { if (b == '\r') {
state = CRLFCR; state = State.CRLFCR;
} else { } else {
state = START; state = State.START;
} }
} else if (state == CRLFCR) { } else if (state == State.CRLFCR) {
if (b == '\n') { if (b == '\n') {
state = BODY; state = State.BODY;
} else { } else {
state = START; state = State.START;
} }
} }
} }