mirror of
https://github.com/moparisthebest/davmail
synced 2024-12-13 11:12:22 -05:00
IMAP: ignore buffer size, to avoid multiple message downloads
git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@430 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
parent
31a4a21f6f
commit
1a6294a690
@ -460,7 +460,7 @@ public class ImapConnection extends AbstractConnection {
|
|||||||
}
|
}
|
||||||
} else if ("BODY.PEEK[HEADER]".equals(param) || param.startsWith("BODY.PEEK[HEADER")) {
|
} else if ("BODY.PEEK[HEADER]".equals(param) || param.startsWith("BODY.PEEK[HEADER")) {
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
PartOutputStream partOutputStream = new PartOutputStream(baos, true, false, 0, Integer.MAX_VALUE);
|
PartOutputStream partOutputStream = new PartOutputStream(baos, true, false, 0);
|
||||||
message.write(partOutputStream);
|
message.write(partOutputStream);
|
||||||
baos.close();
|
baos.close();
|
||||||
buffer.append(" RFC822.SIZE ").append(partOutputStream.size);
|
buffer.append(" RFC822.SIZE ").append(partOutputStream.size);
|
||||||
@ -477,16 +477,12 @@ public class ImapConnection extends AbstractConnection {
|
|||||||
} else if (param.startsWith("BODY[]") || param.startsWith("BODY.PEEK[]") || "BODY.PEEK[TEXT]".equals(param)) {
|
} else if (param.startsWith("BODY[]") || param.startsWith("BODY.PEEK[]") || "BODY.PEEK[TEXT]".equals(param)) {
|
||||||
// parse buffer size
|
// parse buffer size
|
||||||
int startIndex = 0;
|
int startIndex = 0;
|
||||||
int bufferSize = Integer.MAX_VALUE;
|
|
||||||
int ltIndex = param.indexOf('<');
|
int ltIndex = param.indexOf('<');
|
||||||
if (ltIndex >= 0) {
|
if (ltIndex >= 0) {
|
||||||
int dotIndex = param.indexOf('.', ltIndex);
|
int dotIndex = param.indexOf('.', ltIndex);
|
||||||
if (dotIndex >= 0) {
|
if (dotIndex >= 0) {
|
||||||
startIndex = Integer.parseInt(param.substring(ltIndex + 1, dotIndex));
|
startIndex = Integer.parseInt(param.substring(ltIndex + 1, dotIndex));
|
||||||
int gtIndex = param.indexOf('>', ltIndex);
|
// ignore buffer size
|
||||||
if (gtIndex >= 0) {
|
|
||||||
bufferSize = Integer.parseInt(param.substring(dotIndex + 1, gtIndex));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -496,7 +492,7 @@ public class ImapConnection extends AbstractConnection {
|
|||||||
if ("BODY.PEEK[TEXT]".equals(param)) {
|
if ("BODY.PEEK[TEXT]".equals(param)) {
|
||||||
writeHeaders = false;
|
writeHeaders = false;
|
||||||
}
|
}
|
||||||
PartOutputStream bodyOutputStream = new PartOutputStream(baos, writeHeaders, true, startIndex, bufferSize);
|
PartOutputStream bodyOutputStream = new PartOutputStream(baos, writeHeaders, true, startIndex);
|
||||||
message.write(bodyOutputStream);
|
message.write(bodyOutputStream);
|
||||||
rfc822size = bodyOutputStream.size;
|
rfc822size = bodyOutputStream.size;
|
||||||
baos.close();
|
baos.close();
|
||||||
@ -875,22 +871,20 @@ public class ImapConnection extends AbstractConnection {
|
|||||||
protected final boolean writeHeaders;
|
protected final boolean writeHeaders;
|
||||||
protected final boolean writeBody;
|
protected final boolean writeBody;
|
||||||
protected final int startIndex;
|
protected final int startIndex;
|
||||||
protected final int bufferSize;
|
|
||||||
|
|
||||||
public PartOutputStream(OutputStream os, boolean writeHeaders, boolean writeBody,
|
public PartOutputStream(OutputStream os, boolean writeHeaders, boolean writeBody,
|
||||||
int startIndex, int bufferSize) {
|
int startIndex) {
|
||||||
super(os);
|
super(os);
|
||||||
this.writeHeaders = writeHeaders;
|
this.writeHeaders = writeHeaders;
|
||||||
this.writeBody = writeBody;
|
this.writeBody = writeBody;
|
||||||
this.startIndex = startIndex;
|
this.startIndex = startIndex;
|
||||||
this.bufferSize = bufferSize;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(int b) throws IOException {
|
public void write(int b) throws IOException {
|
||||||
size++;
|
size++;
|
||||||
if (((state != BODY && writeHeaders) || (state == BODY && writeBody)) &&
|
if (((state != BODY && writeHeaders) || (state == BODY && writeBody)) &&
|
||||||
(size > startIndex) && ((size - startIndex) <= bufferSize)
|
(size > startIndex)
|
||||||
) {
|
) {
|
||||||
super.write(b);
|
super.write(b);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user