Optional protocol logging

pull/187/head
M66B 4 years ago
parent 1ad69b82a7
commit a9150f84b8

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

@ -327,6 +327,30 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/btnApp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swProtocol"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_advanced_protocol"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/btnMore"
app:switchPadding="12dp" />
<eu.faircode.email.FixedTextView
android:id="@+id/tvProtocolHint"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="48dp"
android:text="@string/title_advanced_protocol_hint"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="?attr/colorWarning"
android:textStyle="italic"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swProtocol" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swDebug"
android:layout_width="0dp"
@ -335,7 +359,7 @@
android:text="@string/title_advanced_debug"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/btnMore"
app:layout_constraintTop_toBottomOf="@id/tvProtocolHint"
app:switchPadding="12dp" />
<eu.faircode.email.FixedTextView

@ -504,6 +504,7 @@
<string name="title_advanced_experiments">Try experimental features</string>
<string name="title_advanced_query_threads">Limit parallel database access</string>
<string name="title_advanced_crash_reports">Send error reports</string>
<string name="title_advanced_protocol">Protocol logging</string>
<string name="title_advanced_debug">Debug mode</string>
<string name="title_advanced_cleanup_attachments">Delete attachments of old messages</string>
<string name="title_advanced_cleanup">Cleanup</string>
@ -585,6 +586,7 @@
<string name="title_advanced_fts_hint">Enabling this improves search performance, but also increases battery and storage space usage</string>
<string name="title_advanced_english_hint">This will restart the app</string>
<string name="title_advanced_experiments_hint">List of current experimental features</string>
<string name="title_advanced_protocol_hint">This will significantly increase battery and storage space usage!</string>
<string name="title_advanced_debug_hint">Enable extra logging and show debug information at various places</string>
<string name="title_advanced_cleanup_attachments_hint">When manually cleaning, this will remove attachments from messages that are no longer synchronized</string>
<string name="title_advanced_cleanup_hint">This will delete all temporary files</string>

Loading…
Cancel
Save