From f88537284f296d0e40d5b7965dc63126c9ea8e30 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Fri, 1 Sep 2017 15:36:45 +0200 Subject: [PATCH] simplify MAIL FROM formatting logic --- .../k9/mail/transport/smtp/SmtpTransport.java | 33 +++++++++---------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/k9mail-library/src/main/java/com/fsck/k9/mail/transport/smtp/SmtpTransport.java b/k9mail-library/src/main/java/com/fsck/k9/mail/transport/smtp/SmtpTransport.java index 9e81faea4..9ce9c4a43 100644 --- a/k9mail-library/src/main/java/com/fsck/k9/mail/transport/smtp/SmtpTransport.java +++ b/k9mail-library/src/main/java/com/fsck/k9/mail/transport/smtp/SmtpTransport.java @@ -419,13 +419,10 @@ public class SmtpTransport extends Transport { } private void sendMessageTo(List addresses, Message message) - throws MessagingException { + throws MessagingException { close(); open(); - if (!is8bitEncodingAllowed) { - Timber.d("Server does not support 8bit transfer encoding"); - } // 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 (largestAcceptableMessage > 0 && message.hasAttachments()) { @@ -435,16 +432,13 @@ public class SmtpTransport extends Transport { } boolean entireMessageSent = false; - Address[] from = message.getFrom(); + try { - String fromAddress = from[0].getAddress(); + String mailFrom = constructSmtpMailFromCommand(message.getFrom(), is8bitEncodingAllowed); + if (isPipeliningSupported) { Queue pipelinedCommands = new LinkedList<>(); - if (is8bitEncodingAllowed) { - pipelinedCommands.add(String.format("MAIL FROM:<%s> BODY=8BITMIME", fromAddress)); - } else { - pipelinedCommands.add(String.format("MAIL FROM:<%s>", fromAddress)); - } + pipelinedCommands.add(mailFrom); for (String address : addresses) { pipelinedCommands.add(String.format("RCPT TO:<%s>", address)); @@ -453,13 +447,8 @@ public class SmtpTransport extends Transport { pipelinedCommands.add("DATA"); executePipelinedCommands(pipelinedCommands); readPipelinedResponse(pipelinedCommands); - } else { - if (is8bitEncodingAllowed) { - executeCommand("MAIL FROM:<%s> BODY=8BITMIME", fromAddress); - } else { - executeCommand("MAIL FROM:<%s>", fromAddress); - } + executeCommand(mailFrom); for (String address : addresses) { executeCommand("RCPT TO:<%s>", address); @@ -489,6 +478,16 @@ public class SmtpTransport extends Transport { } + private static String constructSmtpMailFromCommand(Address[] from, boolean is8bitEncodingAllowed) { + String fromAddress = from[0].getAddress(); + if (is8bitEncodingAllowed) { + return String.format("MAIL FROM:<%s> BODY=8BITMIME", fromAddress); + } else { + Timber.d("Server does not support 8bit transfer encoding"); + return String.format("MAIL FROM:<%s>", fromAddress); + } + } + @Override public void close() { try {