IMAP: implement subparts partial fetch
git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@989 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
parent
f0a7f1ae76
commit
4789993fb9
|
@ -596,26 +596,27 @@ public class ImapConnection extends AbstractConnection {
|
||||||
// write headers only
|
// write headers only
|
||||||
mimeMessage.writeTo(new PartOutputStream(baos, true, false, startIndex, maxSize));
|
mimeMessage.writeTo(new PartOutputStream(baos, true, false, startIndex, maxSize));
|
||||||
} else {
|
} else {
|
||||||
int partIndex;
|
MimePart bodyPart = mimeMessage;
|
||||||
// try to parse part index
|
String[] partIndexStrings = partIndexString.split("\\.");
|
||||||
try {
|
for (String subPartIndexString:partIndexStrings) {
|
||||||
partIndex = Integer.parseInt(partIndexString);
|
int subPartIndex;
|
||||||
} catch (NumberFormatException e) {
|
// try to parse part index
|
||||||
throw new DavMailException("EXCEPTION_UNSUPPORTED_PARAMETER", param);
|
try {
|
||||||
|
subPartIndex = Integer.parseInt(subPartIndexString);
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
throw new DavMailException("EXCEPTION_INVALID_PARAMETER", param);
|
||||||
|
}
|
||||||
|
|
||||||
|
Object mimeBody = bodyPart.getContent();
|
||||||
|
if (mimeBody instanceof MimeMultipart) {
|
||||||
|
MimeMultipart multiPart = (MimeMultipart) mimeBody;
|
||||||
|
bodyPart = (MimePart) multiPart.getBodyPart(subPartIndex - 1);
|
||||||
|
} else if (subPartIndex != 1) {
|
||||||
|
throw new DavMailException("EXCEPTION_INVALID_PARAMETER", param);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Object mimeBody = mimeMessage.getContent();
|
// write selected part, without headers
|
||||||
MimePart bodyPart;
|
|
||||||
if (mimeBody instanceof MimeMultipart) {
|
|
||||||
MimeMultipart multiPart = (MimeMultipart) mimeBody;
|
|
||||||
bodyPart = (MimePart) multiPart.getBodyPart(partIndex - 1);
|
|
||||||
} else if (partIndex == 1) {
|
|
||||||
// no multipart, single body
|
|
||||||
bodyPart = mimeMessage;
|
|
||||||
} else {
|
|
||||||
throw new DavMailException("EXCEPTION_INVALID_PARAMETER", param);
|
|
||||||
}
|
|
||||||
// write selected part
|
|
||||||
bodyPart.getDataHandler().writeTo(new PartialOutputStream(baos, startIndex, maxSize));
|
bodyPart.getDataHandler().writeTo(new PartialOutputStream(baos, startIndex, maxSize));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue