Added option to lookup MX records on sending

pull/158/head
M66B 5 years ago
parent 2359276202
commit 52c16a52ed

@ -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";

@ -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);

@ -82,6 +82,29 @@
app:layout_constraintStart_toEndOf="@id/spAutoResize"
app:layout_constraintTop_toTopOf="@id/spAutoResize" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swLookupMx"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_advanced_lookup_mx"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/spAutoResize"
app:switchPadding="12dp" />
<TextView
android:id="@+id/tvLookupMxHint"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="48dp"
android:text="@string/title_advanced_lookup_mx_hint"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textStyle="italic"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swLookupMx" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swAutoSend"
android:layout_width="0dp"
@ -91,7 +114,7 @@
android:text="@string/title_advanced_autosend"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/spAutoResize"
app:layout_constraintTop_toBottomOf="@id/tvLookupMxHint"
app:switchPadding="12dp" />
<TextView

@ -193,6 +193,7 @@
<string name="title_advanced_plain_only">Send plain text only by default</string>
<string name="title_advanced_autoresize">Automatically resize attached and embedded images</string>
<string name="title_advanced_resize_pixels">&lt; %1$d pixels</string>
<string name="title_advanced_lookup_mx">Check recipient email addresses before sending</string>
<string name="title_advanced_autosend">Confirm sending messages</string>
<string name="title_advanced_send_delayed">Delay sending messages</string>
@ -270,6 +271,8 @@
<string name="title_advanced_sync_kept_hint">This will transfer extra data and use extra battery power, especially if there are a lot of messages kept on the device</string>
<string name="title_advanced_sync_folders_hint">Disabling this will reduce data and battery usage somewhat, but will disable updating the list of folders too</string>
<string name="title_advanced_lookup_mx_hint">This will check if DNS MX records exist</string>
<string name="title_advanced_metered_hint">Metered connections are generally mobile connections or paid Wi-Fi hotspots</string>
<string name="title_advanced_metered_warning">Disabling this option will disable receiving and sending messages on mobile internet connections</string>
<string name="title_advanced_rlah_hint">Assuming no roaming within the EU</string>
@ -504,6 +507,7 @@
<string name="title_save">Save</string>
<string name="title_send">Send</string>
<string name="title_send_at">Send at &#8230;</string>
<string name="title_no_server">No server found at \'%1$s\'</string>
<string name="title_style_bold">Bold</string>
<string name="title_style_italic">Italic</string>

Loading…
Cancel
Save