mirror of
https://github.com/M66B/FairEmail.git
synced 2026-05-19 13:34:00 +02:00
Optional protocol logging
This commit is contained in:
@@ -30,7 +30,10 @@ import org.bouncycastle.asn1.x509.Extension;
|
||||
import org.bouncycastle.asn1.x509.GeneralName;
|
||||
import org.bouncycastle.asn1.x509.SubjectKeyIdentifier;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.PrintStream;
|
||||
import java.net.Inet4Address;
|
||||
import java.net.Inet6Address;
|
||||
import java.net.InetAddress;
|
||||
@@ -92,6 +95,7 @@ public class EmailService implements AutoCloseable {
|
||||
private boolean harden;
|
||||
private boolean useip;
|
||||
private String ehlo;
|
||||
private boolean log;
|
||||
private boolean debug;
|
||||
private Properties properties;
|
||||
private Session isession;
|
||||
@@ -150,6 +154,7 @@ public class EmailService implements AutoCloseable {
|
||||
properties = MessageHelper.getSessionProperties();
|
||||
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
this.log = prefs.getBoolean("protocol", false);
|
||||
this.harden = prefs.getBoolean("ssl_harden", false);
|
||||
|
||||
boolean auth_plain = prefs.getBoolean("auth_plain", true);
|
||||
@@ -515,7 +520,27 @@ public class EmailService implements AutoCloseable {
|
||||
String user, String password,
|
||||
SSLSocketFactoryService factory) throws MessagingException {
|
||||
isession = Session.getInstance(properties, null);
|
||||
isession.setDebug(debug);
|
||||
|
||||
isession.setDebug(debug || log);
|
||||
if (debug || log)
|
||||
isession.setDebugOut(new PrintStream(new OutputStream() {
|
||||
private ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
|
||||
@Override
|
||||
public void write(int b) {
|
||||
if (((char) b) == '\n') {
|
||||
String line = bos.toString();
|
||||
if (!line.endsWith("ignoring socket timeout"))
|
||||
if (debug)
|
||||
android.util.Log.i("javamail", user + " " + line);
|
||||
else
|
||||
EntityLog.log(context, user + " " + line);
|
||||
bos.reset();
|
||||
} else
|
||||
bos.write(b);
|
||||
}
|
||||
}));
|
||||
|
||||
//System.setProperty("mail.socket.debug", Boolean.toString(debug));
|
||||
isession.addProvider(new GmailSSLProvider());
|
||||
|
||||
|
||||
@@ -89,6 +89,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
|
||||
private Button btnApp;
|
||||
private Button btnMore;
|
||||
|
||||
private SwitchCompat swProtocol;
|
||||
private SwitchCompat swDebug;
|
||||
private SwitchCompat swAuthPlain;
|
||||
private SwitchCompat swAuthLogin;
|
||||
@@ -106,7 +107,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
|
||||
private final static String[] RESET_OPTIONS = new String[]{
|
||||
"shortcuts", "fts", "english", "watchdog", "updates",
|
||||
"experiments", "query_threads", "crash_reports", "cleanup_attachments",
|
||||
"debug", "auth_plain", "auth_login", "auth_sasl"
|
||||
"protocol", "debug", "auth_plain", "auth_login", "auth_sasl"
|
||||
};
|
||||
|
||||
private final static String[] RESET_QUESTIONS = new String[]{
|
||||
@@ -149,6 +150,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
|
||||
btnApp = view.findViewById(R.id.btnApp);
|
||||
btnMore = view.findViewById(R.id.btnMore);
|
||||
|
||||
swProtocol = view.findViewById(R.id.swProtocol);
|
||||
swDebug = view.findViewById(R.id.swDebug);
|
||||
swAuthPlain = view.findViewById(R.id.swAuthPlain);
|
||||
swAuthLogin = view.findViewById(R.id.swAuthLogin);
|
||||
@@ -339,6 +341,13 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
|
||||
}
|
||||
});
|
||||
|
||||
swProtocol.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
||||
prefs.edit().putBoolean("protocol", checked).apply();
|
||||
}
|
||||
});
|
||||
|
||||
swAuthPlain.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
||||
@@ -596,6 +605,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
|
||||
tvUuid.setText(prefs.getString("uuid", null));
|
||||
swCleanupAttachments.setChecked(prefs.getBoolean("cleanup_attachments", false));
|
||||
|
||||
swProtocol.setChecked(prefs.getBoolean("protocol", false));
|
||||
swDebug.setChecked(prefs.getBoolean("debug", false));
|
||||
swAuthPlain.setChecked(prefs.getBoolean("auth_plain", true));
|
||||
swAuthLogin.setChecked(prefs.getBoolean("auth_login", true));
|
||||
|
||||
@@ -130,7 +130,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
||||
private static final List<String> PREF_RELOAD = Collections.unmodifiableList(Arrays.asList(
|
||||
"ssl_harden", // force reconnect
|
||||
"badge", "unseen_ignored", // force update badge/widget
|
||||
"debug" // force reconnect
|
||||
"protocol", "debug" // force reconnect
|
||||
));
|
||||
|
||||
static final int PI_ALARM = 1;
|
||||
|
||||
Reference in New Issue
Block a user