1
0
Fork 0
mirror of https://github.com/M66B/FairEmail.git synced 2025-01-01 12:44:42 +00:00

Internet address improvements

This commit is contained in:
M66B 2020-04-21 18:51:09 +02:00
parent 6c3114f013
commit e0c839e9a9
3 changed files with 15 additions and 45 deletions

View file

@ -32,9 +32,6 @@ import androidx.fragment.app.FragmentTransaction;
import java.util.ArrayList; import java.util.ArrayList;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
public class ActivityCompose extends ActivityBase implements FragmentManager.OnBackStackChangedListener { public class ActivityCompose extends ActivityBase implements FragmentManager.OnBackStackChangedListener {
static final int PI_REPLY = 1; static final int PI_REPLY = 1;
@ -72,21 +69,11 @@ public class ActivityCompose extends ActivityBase implements FragmentManager.OnB
String to = mailto.getTo(); String to = mailto.getTo();
if (to != null) if (to != null)
try { args.putString("to", to);
InternetAddress.parse(to);
args.putString("to", to);
} catch (AddressException ex) {
Log.w(ex);
}
String cc = mailto.getCc(); String cc = mailto.getCc();
if (cc != null) if (cc != null)
try { args.putString("cc", cc);
InternetAddress.parse(cc);
args.putString("cc", cc);
} catch (AddressException ex) {
Log.w(ex);
}
String subject = mailto.getSubject(); String subject = mailto.getSubject();
if (subject != null) if (subject != null)
@ -100,45 +87,25 @@ public class ActivityCompose extends ActivityBase implements FragmentManager.OnB
if (intent.hasExtra(Intent.EXTRA_SHORTCUT_ID)) { if (intent.hasExtra(Intent.EXTRA_SHORTCUT_ID)) {
String to = intent.getStringExtra(Intent.EXTRA_SHORTCUT_ID); String to = intent.getStringExtra(Intent.EXTRA_SHORTCUT_ID);
if (to != null) if (to != null)
try { args.putString("to", to);
InternetAddress.parse(to);
args.putString("to", to);
} catch (AddressException ex) {
Log.w(ex);
}
} }
if (intent.hasExtra(Intent.EXTRA_EMAIL)) { if (intent.hasExtra(Intent.EXTRA_EMAIL)) {
String[] to = intent.getStringArrayExtra(Intent.EXTRA_EMAIL); String[] to = intent.getStringArrayExtra(Intent.EXTRA_EMAIL);
if (to != null) if (to != null)
try { args.putString("to", TextUtils.join(", ", to));
InternetAddress.parse(TextUtils.join(", ", to));
args.putString("to", TextUtils.join(", ", to));
} catch (AddressException ex) {
Log.w(ex);
}
} }
if (intent.hasExtra(Intent.EXTRA_CC)) { if (intent.hasExtra(Intent.EXTRA_CC)) {
String[] cc = intent.getStringArrayExtra(Intent.EXTRA_CC); String[] cc = intent.getStringArrayExtra(Intent.EXTRA_CC);
if (cc != null) if (cc != null)
try { args.putString("cc", TextUtils.join(", ", cc));
InternetAddress.parse(TextUtils.join(", ", cc));
args.putString("cc", TextUtils.join(", ", cc));
} catch (AddressException ex) {
Log.w(ex);
}
} }
if (intent.hasExtra(Intent.EXTRA_BCC)) { if (intent.hasExtra(Intent.EXTRA_BCC)) {
String[] bcc = intent.getStringArrayExtra(Intent.EXTRA_BCC); String[] bcc = intent.getStringArrayExtra(Intent.EXTRA_BCC);
if (bcc != null) if (bcc != null)
try { args.putString("bcc", TextUtils.join(", ", bcc));
InternetAddress.parse(TextUtils.join(", ", bcc));
args.putString("bcc", TextUtils.join(", ", bcc));
} catch (AddressException ex) {
Log.w(ex);
}
} }
if (intent.hasExtra(Intent.EXTRA_SUBJECT)) { if (intent.hasExtra(Intent.EXTRA_SUBJECT)) {

View file

@ -2632,7 +2632,7 @@ public class FragmentCompose extends FragmentBase {
InternetAddress[] to = null; InternetAddress[] to = null;
try { try {
to = InternetAddress.parse(etTo.getText().toString()); to = InternetAddress.parseHeader(etTo.getText().toString(), false);
} catch (AddressException ignored) { } catch (AddressException ignored) {
} }
@ -3098,21 +3098,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.parse(to)); data.draft.to = (TextUtils.isEmpty(to) ? null : InternetAddress.parseHeader(to, false));
} 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.parse(cc)); data.draft.cc = (TextUtils.isEmpty(cc) ? null : InternetAddress.parseHeader(cc, false));
} 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.parse(bcc)); data.draft.bcc = (TextUtils.isEmpty(bcc) ? null : InternetAddress.parseHeader(bcc, false));
} catch (AddressException ex) { } catch (AddressException ex) {
Log.w(ex); Log.w(ex);
} }

View file

@ -687,6 +687,7 @@ public class FragmentIdentity extends FragmentBase {
InternetAddress[] addresses = InternetAddress.parse(replyto); InternetAddress[] addresses = InternetAddress.parse(replyto);
if (addresses.length != 1) if (addresses.length != 1)
throw new AddressException(); throw new AddressException();
addresses[0].validate();
} catch (AddressException ex) { } catch (AddressException ex) {
throw new IllegalArgumentException(context.getString(R.string.title_email_invalid, replyto)); throw new IllegalArgumentException(context.getString(R.string.title_email_invalid, replyto));
} }
@ -694,14 +695,16 @@ public class FragmentIdentity extends FragmentBase {
if (!TextUtils.isEmpty(cc) && !should) if (!TextUtils.isEmpty(cc) && !should)
try { try {
InternetAddress.parse(cc); for (InternetAddress address : InternetAddress.parse(cc))
address.validate();
} catch (AddressException ex) { } catch (AddressException ex) {
throw new IllegalArgumentException(context.getString(R.string.title_email_invalid, cc)); throw new IllegalArgumentException(context.getString(R.string.title_email_invalid, cc));
} }
if (!TextUtils.isEmpty(bcc) && !should) if (!TextUtils.isEmpty(bcc) && !should)
try { try {
InternetAddress.parse(bcc); for (InternetAddress address : InternetAddress.parse(bcc))
address.validate();
} catch (AddressException ex) { } catch (AddressException ex) {
throw new IllegalArgumentException(context.getString(R.string.title_email_invalid, bcc)); throw new IllegalArgumentException(context.getString(R.string.title_email_invalid, bcc));
} }