Always specify charset for email addresses

pull/183/head
M66B 4 years ago
parent 900348b9d8
commit af45824fd8

@ -1654,7 +1654,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
InternetAddress via = null; InternetAddress via = null;
if (message.identityEmail != null) if (message.identityEmail != null)
try { try {
via = new InternetAddress(message.identityEmail, message.identityName); via = new InternetAddress(message.identityEmail, message.identityName, StandardCharsets.UTF_8.name());
} catch (UnsupportedEncodingException ignored) { } catch (UnsupportedEncodingException ignored) {
} }

@ -39,6 +39,7 @@ import org.json.JSONObject;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.text.DateFormat; import java.text.DateFormat;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
@ -420,7 +421,7 @@ public class EntityRule {
if (answer == null) if (answer == null)
throw new IllegalArgumentException("Rule answer not found name=" + name); throw new IllegalArgumentException("Rule answer not found name=" + name);
Address[] from = new InternetAddress[]{new InternetAddress(identity.email, identity.name)}; Address[] from = new InternetAddress[]{new InternetAddress(identity.email, identity.name, StandardCharsets.UTF_8.name())};
// Prevent loop // Prevent loop
List<EntityMessage> messages = db.message().getMessagesByThread( List<EntityMessage> messages = db.message().getMessagesByThread(

@ -150,6 +150,7 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.nio.charset.StandardCharsets;
import java.security.GeneralSecurityException; import java.security.GeneralSecurityException;
import java.security.PrivateKey; import java.security.PrivateKey;
import java.security.cert.CertificateException; import java.security.cert.CertificateException;
@ -1829,7 +1830,7 @@ public class FragmentCompose extends FragmentBase {
if (address != null) if (address != null)
list.addAll(Arrays.asList(address)); list.addAll(Arrays.asList(address));
list.add(new InternetAddress(email, name)); list.add(new InternetAddress(email, name, StandardCharsets.UTF_8.name()));
if (requestCode == REQUEST_CONTACT_TO) if (requestCode == REQUEST_CONTACT_TO)
draft.to = list.toArray(new Address[0]); draft.to = list.toArray(new Address[0]);
@ -2679,7 +2680,7 @@ public class FragmentCompose extends FragmentBase {
if (contact != null && contact.moveToNext()) { if (contact != null && contact.moveToNext()) {
String name = contact.getString(0); String name = contact.getString(0);
String email = contact.getString(1); String email = contact.getString(1);
selected.add(new InternetAddress(email, name)); selected.add(new InternetAddress(email, name, StandardCharsets.UTF_8.name()));
} }
} }
} }
@ -3584,7 +3585,7 @@ public class FragmentCompose extends FragmentBase {
data.draft.account = drafts.account; data.draft.account = drafts.account;
data.draft.folder = drafts.id; data.draft.folder = drafts.id;
data.draft.identity = selected.id; data.draft.identity = selected.id;
data.draft.from = new InternetAddress[]{new InternetAddress(selected.email, selected.name)}; data.draft.from = new InternetAddress[]{new InternetAddress(selected.email, selected.name, StandardCharsets.UTF_8.name())};
data.draft.sender = MessageHelper.getSortKey(data.draft.from); data.draft.sender = MessageHelper.getSortKey(data.draft.from);
Uri lookupUri = ContactInfo.getLookupUri(data.draft.from); Uri lookupUri = ContactInfo.getLookupUri(data.draft.from);
@ -3631,7 +3632,7 @@ public class FragmentCompose extends FragmentBase {
String email = organizer.getEmail(); String email = organizer.getEmail();
String name = organizer.getCommonName(); String name = organizer.getCommonName();
if (!TextUtils.isEmpty(email)) { if (!TextUtils.isEmpty(email)) {
InternetAddress o = new InternetAddress(email, name); InternetAddress o = new InternetAddress(email, name, StandardCharsets.UTF_8.name());
Log.i("Setting organizer=" + o); Log.i("Setting organizer=" + o);
data.draft.to = new Address[]{o}; data.draft.to = new Address[]{o};
} }
@ -4049,7 +4050,7 @@ public class FragmentCompose extends FragmentBase {
List<EntityAttachment> attachments = db.attachment().getAttachments(draft.id); List<EntityAttachment> attachments = db.attachment().getAttachments(draft.id);
// Get data // Get data
InternetAddress[] afrom = (identity == null ? null : new InternetAddress[]{new InternetAddress(identity.email, identity.name)}); InternetAddress[] afrom = (identity == null ? null : new InternetAddress[]{new InternetAddress(identity.email, identity.name, StandardCharsets.UTF_8.name())});
InternetAddress[] ato = (TextUtils.isEmpty(to) ? null : InternetAddress.parseHeader(to, false)); InternetAddress[] ato = (TextUtils.isEmpty(to) ? null : InternetAddress.parseHeader(to, false));
InternetAddress[] acc = (TextUtils.isEmpty(cc) ? null : InternetAddress.parseHeader(cc, false)); InternetAddress[] acc = (TextUtils.isEmpty(cc) ? null : InternetAddress.parseHeader(cc, false));
InternetAddress[] abcc = (TextUtils.isEmpty(bcc) ? null : InternetAddress.parseHeader(bcc, false)); InternetAddress[] abcc = (TextUtils.isEmpty(bcc) ? null : InternetAddress.parseHeader(bcc, false));

@ -81,6 +81,7 @@ import java.io.OutputStream;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.lang.reflect.Array; import java.lang.reflect.Array;
import java.net.SocketException; import java.net.SocketException;
import java.nio.charset.StandardCharsets;
import java.security.cert.CertPathValidatorException; import java.security.cert.CertPathValidatorException;
import java.text.DateFormat; import java.text.DateFormat;
import java.util.ArrayList; import java.util.ArrayList;
@ -1422,7 +1423,7 @@ public class Log {
} }
static InternetAddress myAddress() throws UnsupportedEncodingException { static InternetAddress myAddress() throws UnsupportedEncodingException {
return new InternetAddress("marcel+fairemail@faircode.eu", "FairCode"); return new InternetAddress("marcel+fairemail@faircode.eu", "FairCode", StandardCharsets.UTF_8.name());
} }
static boolean isSupportedDevice() { static boolean isSupportedDevice() {

@ -198,7 +198,7 @@ public class MessageHelper {
name = null; name = null;
Log.i("extra=" + email); Log.i("extra=" + email);
} }
imessage.setFrom(new InternetAddress(email, name)); imessage.setFrom(new InternetAddress(email, name, StandardCharsets.UTF_8.name()));
} }
if (message.to != null && message.to.length > 0) if (message.to != null && message.to.length > 0)

@ -38,6 +38,7 @@ import org.json.JSONException;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Collections; import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
@ -312,7 +313,7 @@ public class ServiceUI extends IntentService {
reply.inreplyto = ref.msgid; reply.inreplyto = ref.msgid;
reply.thread = ref.thread; reply.thread = ref.thread;
reply.to = ref.from; reply.to = ref.from;
reply.from = new Address[]{new InternetAddress(identity.email, identity.name)}; reply.from = new Address[]{new InternetAddress(identity.email, identity.name, StandardCharsets.UTF_8.name())};
reply.subject = getString(R.string.title_subject_reply, subject); reply.subject = getString(R.string.title_subject_reply, subject);
reply.received = new Date().getTime(); reply.received = new Date().getTime();
reply.seen = true; reply.seen = true;

Loading…
Cancel
Save