Added sign-off to quick setup

This commit is contained in:
M66B 2022-02-01 09:47:34 +01:00
parent 03dd806c8d
commit a7e508482f
1 changed files with 27 additions and 1 deletions

View File

@ -1049,8 +1049,10 @@ public class EmailProvider implements Parcelable {
EntityLog.log(context, "Handshake " + address + ": " + Log.formatThrowable(ex));
} finally {
try {
if (sslSocket != null)
if (sslSocket != null) {
signOff(sslSocket, context);
sslSocket.close();
}
} catch (Throwable ex) {
Log.e(ex);
}
@ -1157,6 +1159,30 @@ public class EmailProvider implements Parcelable {
throw new SocketException("No STARTTLS");
}
private void signOff(Socket socket, Context context) {
try {
String command = (port == 465 || port == 587 ? "QUIT" : "A002 LOGOUT");
EntityLog.log(context, EntityLog.Type.Protocol,
socket.getRemoteSocketAddress() + " >" + command);
socket.getOutputStream().write((command + "\n").getBytes());
LineInputStream lis =
new LineInputStream(
new BufferedInputStream(
socket.getInputStream()));
String response;
do {
response = lis.readLine();
if (response != null)
EntityLog.log(context, EntityLog.Type.Protocol,
socket.getRemoteSocketAddress() + " <" + response);
} while (response != null);
} catch (IOException ex) {
Log.w(ex);
}
}
@Override
public boolean equals(Object obj) {
if (obj instanceof Server) {