SMTP: use content chunk to send large messages

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@2346 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2015-02-18 00:42:15 +00:00
parent bd1c6027dc
commit 6aaa145e7c
3 changed files with 35 additions and 10 deletions

View File

@ -34,6 +34,7 @@ public class CreateItemMethod extends EWSMethod {
this.savedItemFolderId = savedItemFolderId; this.savedItemFolderId = savedItemFolderId;
this.item = item; this.item = item;
addMethodOption(messageDisposition); addMethodOption(messageDisposition);
setContentChunked(true);
} }
/** /**

View File

@ -25,7 +25,10 @@ import davmail.http.DavGatewayHttpClientFacade;
import davmail.ui.tray.DavGatewayTray; import davmail.ui.tray.DavGatewayTray;
import davmail.util.StringUtil; import davmail.util.StringUtil;
import org.apache.commons.codec.binary.Base64; import org.apache.commons.codec.binary.Base64;
import org.apache.commons.httpclient.*; import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpConnection;
import org.apache.commons.httpclient.HttpState;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.PostMethod; import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.RequestEntity; import org.apache.commons.httpclient.methods.RequestEntity;
import org.apache.log4j.Level; import org.apache.log4j.Level;
@ -45,6 +48,7 @@ import java.util.zip.GZIPInputStream;
@SuppressWarnings("Since15") @SuppressWarnings("Since15")
public abstract class EWSMethod extends PostMethod { public abstract class EWSMethod extends PostMethod {
protected static final Logger LOGGER = Logger.getLogger(EWSMethod.class); protected static final Logger LOGGER = Logger.getLogger(EWSMethod.class);
protected static final int CHUNK_LENGTH = 131072;
protected FolderQueryTraversal traversal; protected FolderQueryTraversal traversal;
protected BaseShape baseShape; protected BaseShape baseShape;
@ -114,6 +118,7 @@ public abstract class EWSMethod extends PostMethod {
!Level.DEBUG.toString().equals(Settings.getProperty("log4j.logger.httpclient.wire"))) { !Level.DEBUG.toString().equals(Settings.getProperty("log4j.logger.httpclient.wire"))) {
setRequestHeader("Accept-Encoding", "gzip"); setRequestHeader("Accept-Encoding", "gzip");
} }
setRequestEntity(new RequestEntity() { setRequestEntity(new RequestEntity() {
byte[] content; byte[] content;
@ -122,10 +127,27 @@ public abstract class EWSMethod extends PostMethod {
} }
public void writeRequest(OutputStream outputStream) throws IOException { public void writeRequest(OutputStream outputStream) throws IOException {
boolean firstPass = content == null;
if (content == null) { if (content == null) {
content = generateSoapEnvelope(); content = generateSoapEnvelope();
} }
if (content.length < CHUNK_LENGTH) {
outputStream.write(content); outputStream.write(content);
} else {
int i = 0;
while (i < content.length) {
int length = CHUNK_LENGTH;
if (i + CHUNK_LENGTH > content.length) {
length = content.length - i;
}
outputStream.write(content, i, length);
if (!firstPass) {
DavGatewayTray.debug(new BundleMessage("LOG_UPLOAD_PROGRESS", String.valueOf((i + length) / 1024), (i + length) * 100 / content.length));
DavGatewayTray.switchIcon();
}
i += CHUNK_LENGTH;
}
}
} }
public long getContentLength() { public long getContentLength() {
@ -916,6 +938,7 @@ public abstract class EWSMethod extends PostMethod {
/** /**
* Convert response type to partstat value * Convert response type to partstat value
*
* @param responseType response type * @param responseType response type
* @return partstat value * @return partstat value
*/ */

View File

@ -133,6 +133,7 @@ LOG_UNSUPPORTED_REQUEST=Unsupported request: {0}
LOG_INVALID_TIMEZONE=Invalid timezone: {0} LOG_INVALID_TIMEZONE=Invalid timezone: {0}
LOG_ACCESS_FORBIDDEN=Access to {0} forbidden: {1} LOG_ACCESS_FORBIDDEN=Access to {0} forbidden: {1}
LOG_DOWNLOAD_PROGRESS=Downloaded {0} KBytes from {1} LOG_DOWNLOAD_PROGRESS=Downloaded {0} KBytes from {1}
LOG_UPLOAD_PROGRESS=Uploaded {0} KBytes ({1}%)
LOG_WEBDAV_NOT_AVAILABLE=WebDav not available, retry with EWS mode LOG_WEBDAV_NOT_AVAILABLE=WebDav not available, retry with EWS mode
UI_ABOUT=About... UI_ABOUT=About...
UI_ABOUT_DAVMAIL=About DavMail Gateway UI_ABOUT_DAVMAIL=About DavMail Gateway