1
0
mirror of https://github.com/moparisthebest/davmail synced 2025-01-07 03:38:05 -05:00

IMAP: improve MimeMessage handling, drop after fetch to avoid keeping full message in memory

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@805 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2009-10-30 11:14:47 +00:00
parent 2499aba4c4
commit e4ff8946d9
2 changed files with 14 additions and 23 deletions

View File

@ -1473,6 +1473,13 @@ public class ExchangeSession {
return mimeMessage; return mimeMessage;
} }
/**
* Drop mime message to avoid keeping message content in memory.
*/
public void dropMimeMessage() {
mimeMessage = null;
}
/** /**
* Delete message. * Delete message.
* *

View File

@ -30,16 +30,15 @@ import davmail.exchange.ExchangeSessionFactory;
import davmail.ui.tray.DavGatewayTray; import davmail.ui.tray.DavGatewayTray;
import org.apache.commons.httpclient.HttpException; import org.apache.commons.httpclient.HttpException;
import javax.mail.internet.*;
import javax.mail.MessagingException; import javax.mail.MessagingException;
import javax.mail.Address; import javax.mail.internet.*;
import java.io.*; import java.io.*;
import java.net.Socket; import java.net.Socket;
import java.net.SocketTimeoutException;
import java.net.SocketException; import java.net.SocketException;
import java.util.*; import java.net.SocketTimeoutException;
import java.text.SimpleDateFormat;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
/** /**
* Dav Gateway smtp connection implementation. * Dav Gateway smtp connection implementation.
@ -497,7 +496,6 @@ public class ImapConnection extends AbstractConnection {
StringBuilder buffer = new StringBuilder(); StringBuilder buffer = new StringBuilder();
buffer.append("* ").append(currentIndex).append(" FETCH (UID ").append(message.getImapUid()); buffer.append("* ").append(currentIndex).append(" FETCH (UID ").append(message.getImapUid());
if (parameters != null) { if (parameters != null) {
boolean bodystructure = false;
StringTokenizer paramTokens = new StringTokenizer(parameters); StringTokenizer paramTokens = new StringTokenizer(parameters);
while (paramTokens.hasMoreTokens()) { while (paramTokens.hasMoreTokens()) {
String param = paramTokens.nextToken(); String param = paramTokens.nextToken();
@ -506,13 +504,7 @@ public class ImapConnection extends AbstractConnection {
} else if ("ENVELOPE".equals(param)) { } else if ("ENVELOPE".equals(param)) {
appendEnvelope(buffer, message); appendEnvelope(buffer, message);
} else if ("BODYSTRUCTURE".equals(param)) { } else if ("BODYSTRUCTURE".equals(param)) {
if (parameters.indexOf("BODY.") >= 0) {
// Apple Mail: send structure with body, need exact RFC822.SIZE
bodystructure = true;
} else {
// thunderbird : send BODYSTRUCTURE
appendBodyStructure(buffer, message); appendBodyStructure(buffer, message);
}
} else if ("INTERNALDATE".equals(param) && message.date != null && message.date.length() > 0) { } else if ("INTERNALDATE".equals(param) && message.date != null && message.date.length() > 0) {
try { try {
SimpleDateFormat dateParser = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); SimpleDateFormat dateParser = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
@ -529,11 +521,6 @@ public class ImapConnection extends AbstractConnection {
message.write(partOutputStream); message.write(partOutputStream);
baos.close(); baos.close();
if (bodystructure) {
bodystructure = false;
// Apple Mail: need to build full bodystructure
appendBodyStructure(buffer, message);
}
buffer.append(" RFC822.SIZE ").append(partOutputStream.size); buffer.append(" RFC822.SIZE ").append(partOutputStream.size);
if ("BODY.PEEK[HEADER]".equals(param)) { if ("BODY.PEEK[HEADER]".equals(param)) {
buffer.append(" BODY[HEADER] {"); buffer.append(" BODY[HEADER] {");
@ -568,11 +555,6 @@ public class ImapConnection extends AbstractConnection {
rfc822size = bodyOutputStream.size; rfc822size = bodyOutputStream.size;
baos.close(); baos.close();
if (bodystructure) {
bodystructure = false;
// Apple Mail: need to build full bodystructure
appendBodyStructure(buffer, message);
}
buffer.append(" RFC822.SIZE ").append(rfc822size).append(' '); buffer.append(" RFC822.SIZE ").append(rfc822size).append(' ');
if ("BODY.PEEK[TEXT]".equals(param)) { if ("BODY.PEEK[TEXT]".equals(param)) {
buffer.append("BODY[TEXT]"); buffer.append("BODY[TEXT]");
@ -593,6 +575,8 @@ public class ImapConnection extends AbstractConnection {
} }
buffer.append(')'); buffer.append(')');
sendClient(buffer.toString()); sendClient(buffer.toString());
// do not keep message content in memory
message.dropMimeMessage();
} }
protected void handleStore(String commandId, AbstractRangeIterator rangeIterator, String action, String flags) throws IOException { protected void handleStore(String commandId, AbstractRangeIterator rangeIterator, String action, String flags) throws IOException {