Validate addresses before sending

pull/155/head
M66B 6 years ago
parent 9ee7c9f591
commit 9f3ce6bd4f

@ -188,6 +188,8 @@ public class FragmentCompose extends FragmentBase {
static final int REDUCED_IMAGE_SIZE = 1440; // pixels static final int REDUCED_IMAGE_SIZE = 1440; // pixels
static final int REDUCED_IMAGE_QUALITY = 90; // percent static final int REDUCED_IMAGE_QUALITY = 90; // percent
private static final int ADDRESS_ELLIPSIZE = 50;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@ -2169,13 +2171,37 @@ public class FragmentCompose extends FragmentBase {
InternetAddress abcc[] = null; InternetAddress abcc[] = null;
if (!TextUtils.isEmpty(to)) if (!TextUtils.isEmpty(to))
try {
ato = InternetAddress.parse(to); ato = InternetAddress.parse(to);
if (action == R.id.action_send)
for (InternetAddress address : ato)
address.validate();
} catch (AddressException ex) {
throw new AddressException(context.getString(R.string.title_address_parse_error,
Helper.ellipsize(to, ADDRESS_ELLIPSIZE), ex.getMessage()));
}
if (!TextUtils.isEmpty(cc)) if (!TextUtils.isEmpty(cc))
try {
acc = InternetAddress.parse(cc); acc = InternetAddress.parse(cc);
if (action == R.id.action_send)
for (InternetAddress address : acc)
address.validate();
} catch (AddressException ex) {
throw new AddressException(context.getString(R.string.title_address_parse_error,
Helper.ellipsize(cc, ADDRESS_ELLIPSIZE), ex.getMessage()));
}
if (!TextUtils.isEmpty(bcc)) if (!TextUtils.isEmpty(bcc))
try {
abcc = InternetAddress.parse(bcc); abcc = InternetAddress.parse(bcc);
if (action == R.id.action_send)
for (InternetAddress address : abcc)
address.validate();
} catch (AddressException ex) {
throw new AddressException(context.getString(R.string.title_address_parse_error,
Helper.ellipsize(bcc, ADDRESS_ELLIPSIZE), ex.getMessage()));
}
if (TextUtils.isEmpty(extra)) if (TextUtils.isEmpty(extra))
extra = null; extra = null;

@ -1217,4 +1217,11 @@ public class Helper {
else else
return DateUtils.getRelativeTimeSpanString(context, millis); return DateUtils.getRelativeTimeSpanString(context, millis);
} }
static String ellipsize(String text, int maxLen) {
if (text == null || text.length() < maxLen) {
return text;
}
return text.substring(0, maxLen) + "...";
}
} }

@ -276,6 +276,7 @@
<string name="title_no_name">Name missing</string> <string name="title_no_name">Name missing</string>
<string name="title_no_email">Email address missing</string> <string name="title_no_email">Email address missing</string>
<string name="title_email_invalid">Email address invalid</string> <string name="title_email_invalid">Email address invalid</string>
<string name="title_address_parse_error">Address \'%1$s\' invalid: %2$s</string>
<string name="title_no_account">Account missing</string> <string name="title_no_account">Account missing</string>
<string name="title_no_host">Host name missing</string> <string name="title_no_host">Host name missing</string>
<string name="title_no_user">User name missing</string> <string name="title_no_user">User name missing</string>

Loading…
Cancel
Save