diff --git a/providers/angus-mail/src/test/java/org/eclipse/angus/mail/imap/IMAPSearchTest.java b/providers/angus-mail/src/test/java/org/eclipse/angus/mail/imap/IMAPSearchTest.java index c870f98a..96676260 100644 --- a/providers/angus-mail/src/test/java/org/eclipse/angus/mail/imap/IMAPSearchTest.java +++ b/providers/angus-mail/src/test/java/org/eclipse/angus/mail/imap/IMAPSearchTest.java @@ -109,6 +109,7 @@ public void testUtf8Search() { server = new TestServer(new IMAPUtf8Handler() { @Override public void search(String line) throws IOException { + System.out.println(line); if (line.contains("CHARSET")) bad("CHARSET not supported"); else diff --git a/providers/angus-mail/src/test/java/org/eclipse/angus/mail/test/ProtocolHandler.java b/providers/angus-mail/src/test/java/org/eclipse/angus/mail/test/ProtocolHandler.java index 4007d931..b7f4d2fd 100644 --- a/providers/angus-mail/src/test/java/org/eclipse/angus/mail/test/ProtocolHandler.java +++ b/providers/angus-mail/src/test/java/org/eclipse/angus/mail/test/ProtocolHandler.java @@ -99,27 +99,45 @@ protected String readLine() throws IOException { int room = buf.length; int offset = 0; int c; + int ls = -1; + int len = -1; while ((c = in.read()) != -1) { + if (c == '{') { + ls = offset + 1; + } + + if (c == '}' && ls > -1) { + len = Integer.parseInt(new String(buf, ls, offset - ls)); + } + if (c == '\n') { - break; - } else if (c == '\r') { - int c2 = in.read(); - if ((c2 != '\n') && (c2 != -1)) { - if (!(in instanceof PushbackInputStream)) - this.in = new PushbackInputStream(in); - ((PushbackInputStream) in).unread(c2); + if (len < 0) { + break; } - break; - } else { - if (--room < 0) { - byte[] nbuf = new byte[offset + 128]; - room = nbuf.length - offset - 1; - System.arraycopy(buf, 0, nbuf, 0, offset); - buf = nbuf; + len = -1; + } + + if (c == '\r') { + if (len > -1) { + int c2 = in.read(); + if ((c2 != '\n') && (c2 != -1)) { + if (!(in instanceof PushbackInputStream)) + this.in = new PushbackInputStream(in); + ((PushbackInputStream) in).unread(c2); + } + break; } - buf[offset++] = (byte) c; + len = -1; + } + + if (--room < 0) { + byte[] nbuf = new byte[offset + 128]; + room = nbuf.length - offset - 1; + System.arraycopy(buf, 0, nbuf, 0, offset); + buf = nbuf; } + buf[offset++] = (byte) c; } if ((c == -1) && (offset == 0)) return null; diff --git a/providers/imap/src/main/java/org/eclipse/angus/mail/imap/protocol/SearchSequence.java b/providers/imap/src/main/java/org/eclipse/angus/mail/imap/protocol/SearchSequence.java index 914908ac..a14cbeda 100644 --- a/providers/imap/src/main/java/org/eclipse/angus/mail/imap/protocol/SearchSequence.java +++ b/providers/imap/src/main/java/org/eclipse/angus/mail/imap/protocol/SearchSequence.java @@ -580,12 +580,16 @@ private static final class Utf8Literal implements Literal { @Override public int size() { - return bytes.length; + return bytes.length + 4; } @Override public void writeTo(OutputStream os) throws IOException { + os.write('\n'); + os.write('\r'); os.write(this.bytes); + os.write('\n'); + os.write('\r'); } } }