diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java
index 1e83407cac..80f479a9f5 100644
--- a/app/src/main/java/eu/faircode/email/FragmentCompose.java
+++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java
@@ -114,6 +114,10 @@ import org.jsoup.nodes.Element;
import org.openintents.openpgp.OpenPgpError;
import org.openintents.openpgp.util.OpenPgpApi;
import org.openintents.openpgp.util.OpenPgpServiceConnection;
+import org.xbill.DNS.Lookup;
+import org.xbill.DNS.SimpleResolver;
+import org.xbill.DNS.TextParseException;
+import org.xbill.DNS.Type;
import java.io.BufferedOutputStream;
import java.io.BufferedWriter;
@@ -125,6 +129,7 @@ import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.net.UnknownHostException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
@@ -2463,8 +2468,10 @@ public class FragmentCompose extends FragmentBase {
try {
ato = InternetAddress.parse(to);
if (action == R.id.action_send)
- for (InternetAddress address : ato)
+ for (InternetAddress address : ato) {
address.validate();
+ lookup(address, context);
+ }
} catch (AddressException ex) {
throw new AddressException(context.getString(R.string.title_address_parse_error,
Helper.ellipsize(to, ADDRESS_ELLIPSIZE), ex.getMessage()));
@@ -2474,8 +2481,10 @@ public class FragmentCompose extends FragmentBase {
try {
acc = InternetAddress.parse(cc);
if (action == R.id.action_send)
- for (InternetAddress address : acc)
+ for (InternetAddress address : acc) {
address.validate();
+ lookup(address, context);
+ }
} catch (AddressException ex) {
throw new AddressException(context.getString(R.string.title_address_parse_error,
Helper.ellipsize(cc, ADDRESS_ELLIPSIZE), ex.getMessage()));
@@ -2485,8 +2494,10 @@ public class FragmentCompose extends FragmentBase {
try {
abcc = InternetAddress.parse(bcc);
if (action == R.id.action_send)
- for (InternetAddress address : abcc)
+ for (InternetAddress address : abcc) {
address.validate();
+ lookup(address, context);
+ }
} catch (AddressException ex) {
throw new AddressException(context.getString(R.string.title_address_parse_error,
Helper.ellipsize(bcc, ADDRESS_ELLIPSIZE), ex.getMessage()));
@@ -2743,7 +2754,29 @@ public class FragmentCompose extends FragmentBase {
Helper.unexpectedError(getFragmentManager(), ex);
}
- String getActionName(int id) {
+ private void lookup(InternetAddress address, Context context) throws TextParseException, UnknownHostException {
+ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
+ boolean lookup_mx = prefs.getBoolean("lookup_mx", false);
+ if (!lookup_mx)
+ return;
+
+ String email = address.getAddress();
+ if (email == null || !email.contains("@"))
+ return;
+
+ String domain = email.split("@")[1];
+ Lookup lookup = new Lookup(domain, Type.MX);
+ SimpleResolver resolver = new SimpleResolver(Helper.DEFAULT_DNS);
+ lookup.setResolver(resolver);
+ Log.i("Lookup dns=" + domain + " @" + resolver.getAddress());
+
+ lookup.run();
+ if (lookup.getResult() == Lookup.HOST_NOT_FOUND ||
+ lookup.getResult() == Lookup.TYPE_NOT_FOUND)
+ throw new IllegalArgumentException(context.getString(R.string.title_no_server, domain));
+ }
+
+ private String getActionName(int id) {
switch (id) {
case R.id.action_delete:
return "delete";
diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsSend.java b/app/src/main/java/eu/faircode/email/FragmentOptionsSend.java
index 054d27abcd..f0aca15d83 100644
--- a/app/src/main/java/eu/faircode/email/FragmentOptionsSend.java
+++ b/app/src/main/java/eu/faircode/email/FragmentOptionsSend.java
@@ -45,11 +45,12 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc
private SwitchCompat swAutoResize;
private Spinner spAutoResize;
private TextView tvAutoResize;
+ private SwitchCompat swLookupMx;
private SwitchCompat swAutoSend;
private Spinner spSendDelayed;
private final static String[] RESET_OPTIONS = new String[]{
- "keyboard", "prefix_once", "plain_only", "autoresize", "resize", "autosend", "send_delayed"
+ "keyboard", "prefix_once", "plain_only", "autoresize", "resize", "lookup_mx", "autosend", "send_delayed"
};
@Override
@@ -68,6 +69,7 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc
swAutoResize = view.findViewById(R.id.swAutoResize);
spAutoResize = view.findViewById(R.id.spAutoResize);
tvAutoResize = view.findViewById(R.id.tvAutoResize);
+ swLookupMx = view.findViewById(R.id.swLookupMx);
swAutoSend = view.findViewById(R.id.swAutoSend);
spSendDelayed = view.findViewById(R.id.spSendDelayed);
@@ -120,6 +122,13 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc
}
});
+ swLookupMx.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
+ @Override
+ public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
+ prefs.edit().putBoolean("lookup_mx", checked).apply();
+ }
+ });
+
swAutoSend.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
@@ -201,6 +210,7 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc
}
spAutoResize.setEnabled(swAutoResize.isChecked());
+ swLookupMx.setChecked(prefs.getBoolean("lookup_mx", false));
swAutoSend.setChecked(!prefs.getBoolean("autosend", false));
int send_delayed = prefs.getInt("send_delayed", 0);
diff --git a/app/src/main/res/layout/fragment_options_send.xml b/app/src/main/res/layout/fragment_options_send.xml
index cf1f631fea..3ea055b721 100644
--- a/app/src/main/res/layout/fragment_options_send.xml
+++ b/app/src/main/res/layout/fragment_options_send.xml
@@ -82,6 +82,29 @@
app:layout_constraintStart_toEndOf="@id/spAutoResize"
app:layout_constraintTop_toTopOf="@id/spAutoResize" />
+
+
+
+
Send plain text only by default
Automatically resize attached and embedded images
< %1$d pixels
+ Check recipient email addresses before sending
Confirm sending messages
Delay sending messages
@@ -270,6 +271,8 @@
This will transfer extra data and use extra battery power, especially if there are a lot of messages kept on the device
Disabling this will reduce data and battery usage somewhat, but will disable updating the list of folders too
+ This will check if DNS MX records exist
+
Metered connections are generally mobile connections or paid Wi-Fi hotspots
Disabling this option will disable receiving and sending messages on mobile internet connections
Assuming no roaming within the EU
@@ -504,6 +507,7 @@
Save
Send
Send at …
+ No server found at \'%1$s\'
Bold
Italic