Skip to content

Commit

Permalink
Work in progress
Browse files Browse the repository at this point in the history
#474
Signed-off-by: jmehrens [email protected]
  • Loading branch information
jmehrens committed Feb 23, 2024
1 parent 09fe51c commit 720ad1d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
}

0 comments on commit 720ad1d

Please sign in to comment.