diff --git a/app/src/main/java/com/sun/mail/iap/Protocol.java b/app/src/main/java/com/sun/mail/iap/Protocol.java index f85e95e807..afb077b218 100644 --- a/app/src/main/java/com/sun/mail/iap/Protocol.java +++ b/app/src/main/java/com/sun/mail/iap/Protocol.java @@ -116,7 +116,7 @@ public class Protocol { processGreeting(readResponse()); timestamp = System.currentTimeMillis(); - + connected = true; // must be last statement in constructor } finally { /* @@ -636,7 +636,7 @@ public class Protocol { } socket = null; if (traceInput != null && traceOutput != null) - eu.faircode.email.TrafficStatsHelper.report(host, "IMAP", + eu.faircode.email.TrafficStatsHelper.report(host, prefix, traceOutput.getSent(), traceInput.getReceived()); } } diff --git a/app/src/main/java/com/sun/mail/pop3/Protocol.java b/app/src/main/java/com/sun/mail/pop3/Protocol.java index 74ebf647a7..d7735114da 100644 --- a/app/src/main/java/com/sun/mail/pop3/Protocol.java +++ b/app/src/main/java/com/sun/mail/pop3/Protocol.java @@ -807,7 +807,7 @@ class Protocol { if (socket != null) socket.close(); if (traceInput != null && traceOutput != null) - eu.faircode.email.TrafficStatsHelper.report(host, "POP3", + eu.faircode.email.TrafficStatsHelper.report(host, prefix, traceOutput.getSent(), traceInput.getReceived()); } catch (IOException ex) { // ignore it diff --git a/app/src/main/java/com/sun/mail/smtp/SMTPTransport.java b/app/src/main/java/com/sun/mail/smtp/SMTPTransport.java index 666cb0a4df..13ceef2646 100644 --- a/app/src/main/java/com/sun/mail/smtp/SMTPTransport.java +++ b/app/src/main/java/com/sun/mail/smtp/SMTPTransport.java @@ -1473,7 +1473,7 @@ public class SMTPTransport extends Transport { serverInput = null; lineInputStream = null; if (traceInput != null && traceOutput != null) - eu.faircode.email.TrafficStatsHelper.report(host, "SMTP", + eu.faircode.email.TrafficStatsHelper.report(host, name, traceOutput.getSent(), traceInput.getReceived()); if (super.isConnected()) // only notify if already connected super.close(); diff --git a/app/src/main/java/com/sun/mail/util/SocketFetcher.java b/app/src/main/java/com/sun/mail/util/SocketFetcher.java index d51d92d690..6c495a4663 100644 --- a/app/src/main/java/com/sun/mail/util/SocketFetcher.java +++ b/app/src/main/java/com/sun/mail/util/SocketFetcher.java @@ -347,6 +347,7 @@ public class SocketFetcher { socket.connect(new InetSocketAddress(iaddr, port), cto); else socket.connect(new InetSocketAddress(iaddr, port)); + eu.faircode.email.TrafficStatsHelper.connect(host, port, prefix); eu.faircode.email.Log.i("Socket connected" + " local=" + socket.getLocalSocketAddress() + " remote=" + socket.getRemoteSocketAddress()); diff --git a/app/src/main/java/eu/faircode/email/TrafficStatsHelper.java b/app/src/main/java/eu/faircode/email/TrafficStatsHelper.java index 6fbee5be07..dcfb935536 100644 --- a/app/src/main/java/eu/faircode/email/TrafficStatsHelper.java +++ b/app/src/main/java/eu/faircode/email/TrafficStatsHelper.java @@ -28,8 +28,16 @@ public class TrafficStatsHelper { ctx = context; } - public static void report(String host, String protocol, long sent, long received) { - String msg = protocol + " " + host + " tx=" + sent + " rx=" + received; + public static void connect(String host, int port, String prefix) { + String msg = "Connected " + prefix + " " + host + ":" + port; + if (ctx == null) + Log.i(msg); + else + EntityLog.log(ctx, EntityLog.Type.Statistics, msg); + } + + public static void report(String host, String prefix, long sent, long received) { + String msg = "Disconnected " + prefix + " " + host + " tx=" + sent + " rx=" + received; if (ctx == null) Log.i(msg); else