mirror of
https://github.com/M66B/FairEmail.git
synced 2024-12-29 11:15:51 +00:00
Internet address improvements
This commit is contained in:
parent
6c3114f013
commit
e0c839e9a9
3 changed files with 15 additions and 45 deletions
|
@ -32,9 +32,6 @@ import androidx.fragment.app.FragmentTransaction;
|
|||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.mail.internet.AddressException;
|
||||
import javax.mail.internet.InternetAddress;
|
||||
|
||||
public class ActivityCompose extends ActivityBase implements FragmentManager.OnBackStackChangedListener {
|
||||
static final int PI_REPLY = 1;
|
||||
|
||||
|
@ -72,21 +69,11 @@ public class ActivityCompose extends ActivityBase implements FragmentManager.OnB
|
|||
|
||||
String to = mailto.getTo();
|
||||
if (to != null)
|
||||
try {
|
||||
InternetAddress.parse(to);
|
||||
args.putString("to", to);
|
||||
} catch (AddressException ex) {
|
||||
Log.w(ex);
|
||||
}
|
||||
args.putString("to", to);
|
||||
|
||||
String cc = mailto.getCc();
|
||||
if (cc != null)
|
||||
try {
|
||||
InternetAddress.parse(cc);
|
||||
args.putString("cc", cc);
|
||||
} catch (AddressException ex) {
|
||||
Log.w(ex);
|
||||
}
|
||||
args.putString("cc", cc);
|
||||
|
||||
String subject = mailto.getSubject();
|
||||
if (subject != null)
|
||||
|
@ -100,45 +87,25 @@ public class ActivityCompose extends ActivityBase implements FragmentManager.OnB
|
|||
if (intent.hasExtra(Intent.EXTRA_SHORTCUT_ID)) {
|
||||
String to = intent.getStringExtra(Intent.EXTRA_SHORTCUT_ID);
|
||||
if (to != null)
|
||||
try {
|
||||
InternetAddress.parse(to);
|
||||
args.putString("to", to);
|
||||
} catch (AddressException ex) {
|
||||
Log.w(ex);
|
||||
}
|
||||
args.putString("to", to);
|
||||
}
|
||||
|
||||
if (intent.hasExtra(Intent.EXTRA_EMAIL)) {
|
||||
String[] to = intent.getStringArrayExtra(Intent.EXTRA_EMAIL);
|
||||
if (to != null)
|
||||
try {
|
||||
InternetAddress.parse(TextUtils.join(", ", to));
|
||||
args.putString("to", TextUtils.join(", ", to));
|
||||
} catch (AddressException ex) {
|
||||
Log.w(ex);
|
||||
}
|
||||
args.putString("to", TextUtils.join(", ", to));
|
||||
}
|
||||
|
||||
if (intent.hasExtra(Intent.EXTRA_CC)) {
|
||||
String[] cc = intent.getStringArrayExtra(Intent.EXTRA_CC);
|
||||
if (cc != null)
|
||||
try {
|
||||
InternetAddress.parse(TextUtils.join(", ", cc));
|
||||
args.putString("cc", TextUtils.join(", ", cc));
|
||||
} catch (AddressException ex) {
|
||||
Log.w(ex);
|
||||
}
|
||||
args.putString("cc", TextUtils.join(", ", cc));
|
||||
}
|
||||
|
||||
if (intent.hasExtra(Intent.EXTRA_BCC)) {
|
||||
String[] bcc = intent.getStringArrayExtra(Intent.EXTRA_BCC);
|
||||
if (bcc != null)
|
||||
try {
|
||||
InternetAddress.parse(TextUtils.join(", ", bcc));
|
||||
args.putString("bcc", TextUtils.join(", ", bcc));
|
||||
} catch (AddressException ex) {
|
||||
Log.w(ex);
|
||||
}
|
||||
args.putString("bcc", TextUtils.join(", ", bcc));
|
||||
}
|
||||
|
||||
if (intent.hasExtra(Intent.EXTRA_SUBJECT)) {
|
||||
|
|
|
@ -2632,7 +2632,7 @@ public class FragmentCompose extends FragmentBase {
|
|||
|
||||
InternetAddress[] to = null;
|
||||
try {
|
||||
to = InternetAddress.parse(etTo.getText().toString());
|
||||
to = InternetAddress.parseHeader(etTo.getText().toString(), false);
|
||||
} catch (AddressException ignored) {
|
||||
}
|
||||
|
||||
|
@ -3098,21 +3098,21 @@ public class FragmentCompose extends FragmentBase {
|
|||
|
||||
try {
|
||||
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) {
|
||||
Log.w(ex);
|
||||
}
|
||||
|
||||
try {
|
||||
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) {
|
||||
Log.w(ex);
|
||||
}
|
||||
|
||||
try {
|
||||
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) {
|
||||
Log.w(ex);
|
||||
}
|
||||
|
|
|
@ -687,6 +687,7 @@ public class FragmentIdentity extends FragmentBase {
|
|||
InternetAddress[] addresses = InternetAddress.parse(replyto);
|
||||
if (addresses.length != 1)
|
||||
throw new AddressException();
|
||||
addresses[0].validate();
|
||||
} catch (AddressException ex) {
|
||||
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)
|
||||
try {
|
||||
InternetAddress.parse(cc);
|
||||
for (InternetAddress address : InternetAddress.parse(cc))
|
||||
address.validate();
|
||||
} catch (AddressException ex) {
|
||||
throw new IllegalArgumentException(context.getString(R.string.title_email_invalid, cc));
|
||||
}
|
||||
|
||||
if (!TextUtils.isEmpty(bcc) && !should)
|
||||
try {
|
||||
InternetAddress.parse(bcc);
|
||||
for (InternetAddress address : InternetAddress.parse(bcc))
|
||||
address.validate();
|
||||
} catch (AddressException ex) {
|
||||
throw new IllegalArgumentException(context.getString(R.string.title_email_invalid, bcc));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue