mirror of
https://github.com/moparisthebest/davmail
synced 2025-02-28 09:21:49 -05:00
IMAP: implement part fetch (BODY[1])
git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@967 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
parent
ec8a999ce9
commit
767f17d841
@ -28,6 +28,7 @@ import davmail.exception.HttpNotFoundException;
|
||||
import davmail.exchange.ExchangeSession;
|
||||
import davmail.exchange.ExchangeSessionFactory;
|
||||
import davmail.ui.tray.DavGatewayTray;
|
||||
import davmail.util.StringUtil;
|
||||
import org.apache.commons.httpclient.HttpException;
|
||||
|
||||
import javax.mail.MessagingException;
|
||||
@ -528,7 +529,7 @@ public class ImapConnection extends AbstractConnection {
|
||||
DavGatewayTray.resetIcon();
|
||||
}
|
||||
|
||||
private void handleFetch(ExchangeSession.Message message, int currentIndex, String parameters) throws IOException {
|
||||
private void handleFetch(ExchangeSession.Message message, int currentIndex, String parameters) throws IOException, MessagingException {
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
buffer.append("* ").append(currentIndex).append(" FETCH (UID ").append(message.getImapUid());
|
||||
if (parameters != null) {
|
||||
@ -608,6 +609,44 @@ public class ImapConnection extends AbstractConnection {
|
||||
os.write(baos.toByteArray());
|
||||
os.flush();
|
||||
buffer.setLength(0);
|
||||
} else if (param.startsWith("BODY[") && param.endsWith("]")) {
|
||||
int partIndex = 0;
|
||||
// try to parse message part index
|
||||
String partIndexString = StringUtil.getToken(param, "[", "]");
|
||||
if (partIndexString != null) {
|
||||
try {
|
||||
partIndex = Integer.parseInt(partIndexString);
|
||||
} catch (NumberFormatException e) {
|
||||
throw new DavMailException("EXCEPTION_UNSUPPORTED_PARAMETER", param);
|
||||
}
|
||||
}
|
||||
if (partIndex == 0) {
|
||||
throw new DavMailException("EXCEPTION_INVALID_PARAMETER", param);
|
||||
}
|
||||
|
||||
MimeMessage mimeMessage = message.getMimeMessage();
|
||||
Object mimeBody = mimeMessage.getContent();
|
||||
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);
|
||||
}
|
||||
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
bodyPart.getDataHandler().writeTo(baos);
|
||||
baos.close();
|
||||
|
||||
buffer.append(" {").append(baos.size()).append('}');
|
||||
sendClient(buffer.toString());
|
||||
os.write(baos.toByteArray());
|
||||
os.flush();
|
||||
buffer.setLength(0);
|
||||
|
||||
} else {
|
||||
throw new DavMailException("EXCEPTION_UNSUPPORTED_PARAMETER", param);
|
||||
}
|
||||
@ -837,7 +876,7 @@ public class ImapConnection extends AbstractConnection {
|
||||
appendBodyStructureValue(buffer, bodyPart.getDescription());
|
||||
appendBodyStructureValue(buffer, bodyPart.getEncoding());
|
||||
appendBodyStructureValue(buffer, bodyPart.getSize());
|
||||
// line count not implemented in JavaMail, return 0
|
||||
// line count not implemented in JavaMail, return 0
|
||||
appendBodyStructureValue(buffer, 0);
|
||||
buffer.append(')');
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ EXCEPTION_INVALID_RECIPIENT=Invalid recipient: {0}
|
||||
EXCEPTION_INVALID_REQUEST=Invalid request: {0}
|
||||
EXCEPTION_INVALID_SEARCH_PARAMETERS=Invalid search parameters: {0}
|
||||
EXCEPTION_UNSUPPORTED_PARAMETER=Unsupported parameter: {0}
|
||||
EXCEPTION_INVALID_PARAMETER=Invalid parameter: {0}
|
||||
EXCEPTION_NETWORK_DOWN=All network interfaces down or host unreachable !
|
||||
EXCEPTION_UNABLE_TO_CREATE_MESSAGE=Unable to create message {0}: {1}{2}{3}
|
||||
EXCEPTION_UNABLE_TO_GET_FOLDER=Unable to get folder at {0}
|
||||
|
@ -246,4 +246,5 @@ UI_FORCE_ACTIVESYNC_UPDATE=Forcer ActiveSync :
|
||||
UI_FORCE_ACTIVESYNC_UPDATE_HELP=Forcer la mise à jour des évènements Caldav pour les appareils connectés via ActiveSync
|
||||
UI_DEFAULT_DOMAIN=Domaine par défaut :
|
||||
UI_DEFAULT_DOMAIN_HELP=Nom du domaine windows par défaut
|
||||
EXCEPTION_UNSUPPORTED_PARAMETER=Paramètre non supporté : {0}
|
||||
EXCEPTION_UNSUPPORTED_PARAMETER=Paramètre non supporté : {0}
|
||||
EXCEPTION_INVALID_PARAMETER=Paramètre invalide : {0}
|
Loading…
x
Reference in New Issue
Block a user