From cfe5368e5600cbbded779498af68bfdf486d668e Mon Sep 17 00:00:00 2001 From: M66B Date: Mon, 9 Sep 2019 11:53:46 +0200 Subject: [PATCH] Allow formatted reply-to address, allow multiple BCC addresses --- .../eu/faircode/email/FragmentIdentity.java | 22 +++++++++++++++---- .../java/eu/faircode/email/ServiceSend.java | 4 ++-- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentIdentity.java b/app/src/main/java/eu/faircode/email/FragmentIdentity.java index e9bf84f201..8b13fbf369 100644 --- a/app/src/main/java/eu/faircode/email/FragmentIdentity.java +++ b/app/src/main/java/eu/faircode/email/FragmentIdentity.java @@ -67,6 +67,9 @@ import java.util.ArrayList; import java.util.List; import java.util.Objects; +import javax.mail.internet.AddressException; +import javax.mail.internet.InternetAddress; + import static android.app.Activity.RESULT_OK; import static com.google.android.material.textfield.TextInputLayout.END_ICON_NONE; import static com.google.android.material.textfield.TextInputLayout.END_ICON_PASSWORD_TOGGLE; @@ -605,10 +608,21 @@ public class FragmentIdentity extends FragmentBase { if (!should && synchronize && TextUtils.isEmpty(password) && !insecure) throw new IllegalArgumentException(context.getString(R.string.title_no_password)); - if (!should && !TextUtils.isEmpty(replyto) && !Patterns.EMAIL_ADDRESS.matcher(replyto).matches()) - throw new IllegalArgumentException(context.getString(R.string.title_email_invalid, replyto)); - if (!should && !TextUtils.isEmpty(bcc) && !Patterns.EMAIL_ADDRESS.matcher(bcc).matches()) - throw new IllegalArgumentException(context.getString(R.string.title_email_invalid, bcc)); + if (!should && !TextUtils.isEmpty(replyto)) { + try { + InternetAddress[] addresses = InternetAddress.parse(replyto); + if (addresses.length != 1) + throw new AddressException(); + } catch (AddressException ex) { + throw new IllegalArgumentException(context.getString(R.string.title_email_invalid, replyto)); + } + } + if (!should && !TextUtils.isEmpty(bcc)) + try { + InternetAddress.parse(bcc); + } catch (AddressException ex) { + throw new IllegalArgumentException(context.getString(R.string.title_email_invalid, bcc)); + } if (TextUtils.isEmpty(display)) display = null; diff --git a/app/src/main/java/eu/faircode/email/ServiceSend.java b/app/src/main/java/eu/faircode/email/ServiceSend.java index 9e3455a637..bb87ee8e3f 100644 --- a/app/src/main/java/eu/faircode/email/ServiceSend.java +++ b/app/src/main/java/eu/faircode/email/ServiceSend.java @@ -329,7 +329,7 @@ public class ServiceSend extends ServiceBase { // Add reply to if (ident.replyto != null) - imessage.setReplyTo(new Address[]{new InternetAddress(ident.replyto, null)}); + imessage.setReplyTo(InternetAddress.parse(ident.replyto)); // Add bcc if (ident.bcc != null) { @@ -337,7 +337,7 @@ public class ServiceSend extends ServiceBase { Address[] existing = imessage.getRecipients(Message.RecipientType.BCC); if (existing != null) bcc.addAll(Arrays.asList(existing)); - bcc.add(new InternetAddress(ident.bcc, null)); + bcc.addAll(Arrays.asList(InternetAddress.parse(ident.bcc))); imessage.setRecipients(Message.RecipientType.BCC, bcc.toArray(new Address[0])); }