Merge pull request #4788 from k9mail/remove_jis_send_support

Don't select charset depending on recipient address when sending messages
This commit is contained in:
cketti 2020-05-29 21:55:35 +02:00 committed by GitHub
commit e0b6ca2061
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 39 deletions

View file

@ -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;

View file

@ -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<Address> 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<String> 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<String, List<String>> charsetAddressesMap = new HashMap<>();
for (Address address : addresses) {
String addressString = address.getAddress();
String charset = CharsetSupport.getCharsetFromAddress(addressString);
List<String> addressesOfCharset = charsetAddressesMap.get(charset);
if (addressesOfCharset == null) {
addressesOfCharset = new ArrayList<>();
charsetAddressesMap.put(charset, addressesOfCharset);
}
addressesOfCharset.add(addressString);
if (addresses.isEmpty()) {
return;
}
for (Map.Entry<String, List<String>> charsetAddressesMapEntry :
charsetAddressesMap.entrySet()) {
String charset = charsetAddressesMapEntry.getKey();
List<String> addressesOfCharset = charsetAddressesMapEntry.getValue();
message.setCharset(charset);
sendMessageTo(addressesOfCharset, message);
}
}
private void sendMessageTo(List<String> addresses, Message message)
throws MessagingException {
close();
open();