From 4e2ae11238566b480fd685c34a65ee0879c62a82 Mon Sep 17 00:00:00 2001 From: cketti Date: Wed, 27 May 2020 02:54:23 +0200 Subject: [PATCH] Don't select charset depending on the recipient address It's 2020. We now always use UTF-8 for outgoing emails. --- .../fsck/k9/mail/internet/CharsetSupport.java | 12 ------ .../k9/mail/transport/smtp/SmtpTransport.java | 40 ++++++------------- 2 files changed, 13 insertions(+), 39 deletions(-) diff --git a/mail/common/src/main/java/com/fsck/k9/mail/internet/CharsetSupport.java b/mail/common/src/main/java/com/fsck/k9/mail/internet/CharsetSupport.java index 361957d67..fcc635fee 100644 --- a/mail/common/src/main/java/com/fsck/k9/mail/internet/CharsetSupport.java +++ b/mail/common/src/main/java/com/fsck/k9/mail/internet/CharsetSupport.java @@ -35,18 +35,6 @@ public class CharsetSupport { part.getMimeType() + ";\r\n charset=" + getExternalCharset(charset)); } - - public static String getCharsetFromAddress(String address) { - String variant = JisSupport.getJisVariantFromAddress(address); - if (variant != null) { - String charset = "x-" + variant + "-shift_jis-2007"; - if (Charset.isSupported(charset)) - return charset; - } - - return "UTF-8"; - } - static String getExternalCharset(String charset) { if (JisSupport.isShiftJis(charset)) { return SHIFT_JIS; diff --git a/mail/protocols/smtp/src/main/java/com/fsck/k9/mail/transport/smtp/SmtpTransport.java b/mail/protocols/smtp/src/main/java/com/fsck/k9/mail/transport/smtp/SmtpTransport.java index b154dc497..aeaff52f6 100644 --- a/mail/protocols/smtp/src/main/java/com/fsck/k9/mail/transport/smtp/SmtpTransport.java +++ b/mail/protocols/smtp/src/main/java/com/fsck/k9/mail/transport/smtp/SmtpTransport.java @@ -16,11 +16,13 @@ import java.security.GeneralSecurityException; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; +import java.util.LinkedHashSet; import java.util.LinkedList; import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Queue; +import java.util.Set; import android.text.TextUtils; @@ -41,7 +43,6 @@ import com.fsck.k9.mail.filter.EOLConvertingOutputStream; import com.fsck.k9.mail.filter.LineWrapOutputStream; import com.fsck.k9.mail.filter.PeekableInputStream; import com.fsck.k9.mail.filter.SmtpDataStuffing; -import com.fsck.k9.mail.internet.CharsetSupport; import com.fsck.k9.mail.oauth.OAuth2TokenProvider; import com.fsck.k9.mail.oauth.XOAuth2ChallengeParser; import com.fsck.k9.mail.ssl.TrustedSocketFactory; @@ -372,37 +373,22 @@ public class SmtpTransport extends Transport { @Override public void sendMessage(Message message) throws MessagingException { - List
addresses = new ArrayList<>(); - { - addresses.addAll(Arrays.asList(message.getRecipients(RecipientType.TO))); - addresses.addAll(Arrays.asList(message.getRecipients(RecipientType.CC))); - addresses.addAll(Arrays.asList(message.getRecipients(RecipientType.BCC))); + Set addresses = new LinkedHashSet<>(); + for (Address address : message.getRecipients(RecipientType.TO)) { + addresses.add(address.getAddress()); + } + for (Address address : message.getRecipients(RecipientType.CC)) { + addresses.add(address.getAddress()); + } + for (Address address : message.getRecipients(RecipientType.BCC)) { + addresses.add(address.getAddress()); } message.removeHeader("Bcc"); - Map> charsetAddressesMap = new HashMap<>(); - for (Address address : addresses) { - String addressString = address.getAddress(); - String charset = CharsetSupport.getCharsetFromAddress(addressString); - List addressesOfCharset = charsetAddressesMap.get(charset); - if (addressesOfCharset == null) { - addressesOfCharset = new ArrayList<>(); - charsetAddressesMap.put(charset, addressesOfCharset); - } - addressesOfCharset.add(addressString); + if (addresses.isEmpty()) { + return; } - for (Map.Entry> charsetAddressesMapEntry : - charsetAddressesMap.entrySet()) { - String charset = charsetAddressesMapEntry.getKey(); - List addressesOfCharset = charsetAddressesMapEntry.getValue(); - message.setCharset(charset); - sendMessageTo(addressesOfCharset, message); - } - } - - private void sendMessageTo(List addresses, Message message) - throws MessagingException { close(); open();