mirror of
https://github.com/M66B/FairEmail.git
synced 2025-12-31 18:11:03 +01:00
Validate addresses before sending
This commit is contained in:
@@ -188,6 +188,8 @@ public class FragmentCompose extends FragmentBase {
|
||||
static final int REDUCED_IMAGE_SIZE = 1440; // pixels
|
||||
static final int REDUCED_IMAGE_QUALITY = 90; // percent
|
||||
|
||||
private static final int ADDRESS_ELLIPSIZE = 50;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@@ -2169,13 +2171,37 @@ public class FragmentCompose extends FragmentBase {
|
||||
InternetAddress abcc[] = null;
|
||||
|
||||
if (!TextUtils.isEmpty(to))
|
||||
ato = InternetAddress.parse(to);
|
||||
try {
|
||||
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))
|
||||
acc = InternetAddress.parse(cc);
|
||||
try {
|
||||
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))
|
||||
abcc = InternetAddress.parse(bcc);
|
||||
try {
|
||||
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))
|
||||
extra = null;
|
||||
|
||||
@@ -1217,4 +1217,11 @@ public class Helper {
|
||||
else
|
||||
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) + "...";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user