mirror of
https://github.com/M66B/FairEmail.git
synced 2025-03-14 16:10:39 +00:00
Validate addresses before sending
This commit is contained in:
parent
9ee7c9f591
commit
9f3ce6bd4f
3 changed files with 37 additions and 3 deletions
|
@ -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) + "...";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -276,6 +276,7 @@
|
|||
<string name="title_no_name">Name missing</string>
|
||||
<string name="title_no_email">Email address missing</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_host">Host name missing</string>
|
||||
<string name="title_no_user">User name missing</string>
|
||||
|
|
Loading…
Add table
Reference in a new issue