1
0
mirror of https://github.com/moparisthebest/davmail synced 2024-12-12 10:42:21 -05:00

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() {
@ -202,7 +224,7 @@ public abstract class EWSMethod extends PostMethod {
itemId.write(writer); itemId.write(writer);
} }
if (itemIds != null) { if (itemIds != null) {
for (ItemId localItemId:itemIds) { for (ItemId localItemId : itemIds) {
localItemId.write(writer); localItemId.write(writer);
} }
} }
@ -412,7 +434,7 @@ public abstract class EWSMethod extends PostMethod {
protected void writeIndexedPageView(Writer writer) throws IOException { protected void writeIndexedPageView(Writer writer) throws IOException {
if (maxCount > 0) { if (maxCount > 0) {
writer.write("<m:IndexedPage"+itemType+"View MaxEntriesReturned=\""); writer.write("<m:IndexedPage" + itemType + "View MaxEntriesReturned=\"");
writer.write(String.valueOf(maxCount)); writer.write(String.valueOf(maxCount));
writer.write("\" Offset=\""); writer.write("\" Offset=\"");
writer.write(String.valueOf(offset)); writer.write(String.valueOf(offset));
@ -720,13 +742,13 @@ public abstract class EWSMethod extends PostMethod {
&& !"ErrorItemNotFound".equals(errorDetail) && !"ErrorItemNotFound".equals(errorDetail)
) { ) {
try { try {
throw new EWSException(errorDetail + ' ' +((errorDescription!=null)?errorDescription:"")+ "\n request: " + new String(generateSoapEnvelope(), "UTF-8")); throw new EWSException(errorDetail + ' ' + ((errorDescription != null) ? errorDescription : "") + "\n request: " + new String(generateSoapEnvelope(), "UTF-8"));
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
throw new EWSException(e.getMessage()); throw new EWSException(e.getMessage());
} }
} }
} }
if (getStatusCode() == HttpStatus.SC_BAD_REQUEST || getStatusCode() == HttpStatus.SC_INSUFFICIENT_STORAGE ) { if (getStatusCode() == HttpStatus.SC_BAD_REQUEST || getStatusCode() == HttpStatus.SC_INSUFFICIENT_STORAGE) {
throw new EWSException(getStatusText()); throw new EWSException(getStatusText());
} }
} }
@ -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
*/ */
@ -1141,7 +1164,7 @@ public abstract class EWSMethod extends PostMethod {
try { try {
LOGGER.error("Current text: " + reader.getText()); LOGGER.error("Current text: " + reader.getText());
} catch (IllegalStateException ise) { } catch (IllegalStateException ise) {
LOGGER.error(e+" "+e.getMessage()); LOGGER.error(e + " " + e.getMessage());
} }
} }
} }

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