Allow formatted reply-to address, allow multiple BCC addresses

This commit is contained in:
M66B 2019-09-09 11:53:46 +02:00
parent ad0e77ecc6
commit cfe5368e56
2 changed files with 20 additions and 6 deletions

View File

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

View File

@ -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]));
}