From 03d05e9331f074216a05c3ec63d73540563a336b Mon Sep 17 00:00:00 2001 From: Jesse Vincent Date: Sun, 27 Mar 2011 23:07:37 +0800 Subject: [PATCH] If an SMTP server tells us how big the biggest message they accept is, don't even try to deliver it to them --- .../fsck/k9/mail/transport/SmtpTransport.java | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/com/fsck/k9/mail/transport/SmtpTransport.java b/src/com/fsck/k9/mail/transport/SmtpTransport.java index 6a3cac5c6..3dfb9fbfc 100644 --- a/src/com/fsck/k9/mail/transport/SmtpTransport.java +++ b/src/com/fsck/k9/mail/transport/SmtpTransport.java @@ -13,6 +13,7 @@ import com.fsck.k9.mail.filter.PeekableInputStream; import com.fsck.k9.mail.filter.SmtpDataStuffing; import com.fsck.k9.mail.internet.MimeUtility; import com.fsck.k9.mail.store.TrustManagerFactory; +import com.fsck.k9.mail.store.LocalStore.LocalMessage; import javax.net.ssl.SSLContext; import javax.net.ssl.SSLException; @@ -241,11 +242,11 @@ public class SmtpTransport extends Transport { } if (result.matches(".*SIZE \\d*$")) { try { - mLargestAcceptableMessage = Integer.parseInt( result.substring(result.lastIndexOf(' ') + 1)); + mLargestAcceptableMessage = Integer.parseInt(result.substring(result.lastIndexOf(' ') + 1)); } catch (Exception e) { - if (K9.DEBUG && K9.DEBUG_PROTOCOL_SMTP) { - Log.d(K9.LOG_TAG, "Tried to parse "+result+" and get an int out of the last word: "+e); - } + if (K9.DEBUG && K9.DEBUG_PROTOCOL_SMTP) { + Log.d(K9.LOG_TAG, "Tried to parse " + result + " and get an int out of the last word: " + e); + } } } } @@ -306,13 +307,23 @@ public class SmtpTransport extends Transport { private void sendMessageTo(ArrayList addresses, Message message) throws MessagingException { + boolean possibleSend = false; + close(); open(); message.setEncoding(m8bitEncodingAllowed ? "8bit" : null); + // If the message has attachments and our server has told us about a limit on + // the size of messages, count the message's size before sending it + if (mLargestAcceptableMessage > 0 && ((LocalMessage)message).hasAttachments()) { + if (message.calculateSize() > mLargestAcceptableMessage) { + MessagingException me = new MessagingException("Message too large for server"); + me.setPermanentFailure(possibleSend); + throw me; + } + } Address[] from = message.getFrom(); - boolean possibleSend = false; try { //TODO: Add BODY=8BITMIME parameter if appropriate? executeSimpleCommand("MAIL FROM: " + "<" + from[0].getAddress() + ">");