Remove spaces from email addresses

pull/199/head
M66B 4 years ago
parent c90559f241
commit 0170d1b942

@ -610,7 +610,7 @@ public class EntityRule {
} else { } else {
reply.wasforwardedfrom = message.msgid; reply.wasforwardedfrom = message.msgid;
reply.thread = reply.msgid; // new thread reply.thread = reply.msgid; // new thread
reply.to = InternetAddress.parseHeader(to, false); reply.to = MessageHelper.parseAddresses(context, to);
} }
reply.from = from; reply.from = from;

@ -1974,7 +1974,7 @@ public class FragmentCompose extends FragmentBase {
InternetAddress[] to = null; InternetAddress[] to = null;
try { try {
to = InternetAddress.parseHeader(etTo.getText().toString(), false); to = MessageHelper.parseAddresses(getContext(), etTo.getText().toString());
} catch (AddressException ignored) { } catch (AddressException ignored) {
} }
@ -3994,21 +3994,21 @@ public class FragmentCompose extends FragmentBase {
try { try {
String to = args.getString("to"); String to = args.getString("to");
data.draft.to = (TextUtils.isEmpty(to) ? null : InternetAddress.parseHeader(to, false)); data.draft.to = MessageHelper.parseAddresses(context, to);
} catch (AddressException ex) { } catch (AddressException ex) {
Log.w(ex); Log.w(ex);
} }
try { try {
String cc = args.getString("cc"); String cc = args.getString("cc");
data.draft.cc = (TextUtils.isEmpty(cc) ? null : InternetAddress.parseHeader(cc, false)); data.draft.cc = MessageHelper.parseAddresses(context, cc);
} catch (AddressException ex) { } catch (AddressException ex) {
Log.w(ex); Log.w(ex);
} }
try { try {
String bcc = args.getString("bcc"); String bcc = args.getString("bcc");
data.draft.bcc = (TextUtils.isEmpty(bcc) ? null : InternetAddress.parseHeader(bcc, false)); data.draft.bcc = MessageHelper.parseAddresses(context, bcc);
} catch (AddressException ex) { } catch (AddressException ex) {
Log.w(ex); Log.w(ex);
} }
@ -4953,9 +4953,9 @@ public class FragmentCompose extends FragmentBase {
// Get data // Get data
InternetAddress[] afrom = (identity == null ? null : new InternetAddress[]{new InternetAddress(identity.email, identity.name, StandardCharsets.UTF_8.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 = MessageHelper.parseAddresses(context, to);
InternetAddress[] acc = (TextUtils.isEmpty(cc) ? null : InternetAddress.parseHeader(cc, false)); InternetAddress[] acc = MessageHelper.parseAddresses(context, cc);
InternetAddress[] abcc = (TextUtils.isEmpty(bcc) ? null : InternetAddress.parseHeader(bcc, false)); InternetAddress[] abcc = MessageHelper.parseAddresses(context, bcc);
// Safe guard // Safe guard
if (action == R.id.action_send) { if (action == R.id.action_send) {

@ -2884,6 +2884,23 @@ public class MessageHelper {
return email; return email;
} }
static InternetAddress[] parseAddresses(Context context, String text) throws AddressException {
if (TextUtils.isEmpty(text))
return null;
InternetAddress[] addresses = InternetAddress.parseHeader(text, false);
if (addresses.length == 0)
return null;
for (InternetAddress address : addresses) {
String email = address.getAddress();
if (email != null)
address.setAddress(email.replace(" ", ""));
}
return addresses;
}
static boolean isRemoved(Throwable ex) { static boolean isRemoved(Throwable ex) {
while (ex != null) { while (ex != null) {
if (ex instanceof MessageRemovedException || if (ex instanceof MessageRemovedException ||

Loading…
Cancel
Save