Switch to byte array stream for mbox

pull/197/head
M66B 4 years ago
parent 69bfb953c2
commit d8a8536e4c

@ -62,6 +62,7 @@ import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import java.io.BufferedOutputStream; import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.FilterOutputStream; import java.io.FilterOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
@ -907,10 +908,9 @@ public class FragmentFolders extends FragmentBase {
Message imessage = MessageHelper.from(context, message, null, isession, false); Message imessage = MessageHelper.from(context, message, null, isession, false);
imessage.writeTo(new FilterOutputStream(out) { imessage.writeTo(new FilterOutputStream(out) {
private int pos = 0;
private boolean cr = false; private boolean cr = false;
private boolean lf = false; private boolean lf = false;
private byte[] buffer = new byte[998]; private ByteArrayOutputStream buffer = new ByteArrayOutputStream(998);
@Override @Override
public void write(int b) throws IOException { public void write(int b) throws IOException {
@ -929,40 +929,40 @@ public class FragmentFolders extends FragmentBase {
} else { } else {
if (cr || lf) if (cr || lf)
line(); line();
if (pos == buffer.length) buffer.write(b);
throw new IOException("Line too long");
buffer[pos++] = (byte) b;
} }
} }
@Override @Override
public void flush() throws IOException { public void flush() throws IOException {
if (pos > 0 || cr || lf) if (buffer.size() > 0 || cr || lf)
line(); line();
out.write(10); out.write(10);
super.flush(); super.flush();
} }
private void line() throws IOException { private void line() throws IOException {
byte[] b = buffer.toByteArray();
int i = 0; int i = 0;
for (; i < pos; i++) for (; i < b.length; i++)
if (buffer[i] != '>') if (b[i] != '>')
break; break;
if (i + 4 < pos && if (i + 4 < b.length &&
buffer[i + 0] == 'F' && b[i + 0] == 'F' &&
buffer[i + 1] == 'r' && b[i + 1] == 'r' &&
buffer[i + 2] == 'o' && b[i + 2] == 'o' &&
buffer[i + 3] == 'm' && b[i + 3] == 'm' &&
buffer[i + 4] == ' ') b[i + 4] == ' ')
out.write('>'); out.write('>');
for (i = 0; i < pos; i++) for (i = 0; i < b.length; i++)
out.write(buffer[i]); out.write(b[i]);
out.write(10); out.write(10);
pos = 0; buffer.reset();
cr = false; cr = false;
lf = false; lf = false;
} }

Loading…
Cancel
Save