From edfa764765263aebeaff573a4346e851da5c3600 Mon Sep 17 00:00:00 2001 From: M66B Date: Sat, 20 Jun 2020 19:08:36 +0200 Subject: [PATCH] Annotate exceptions on check only --- .../java/eu/faircode/email/EmailService.java | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/EmailService.java b/app/src/main/java/eu/faircode/email/EmailService.java index c7c606c632..33b2e58b74 100644 --- a/app/src/main/java/eu/faircode/email/EmailService.java +++ b/app/src/main/java/eu/faircode/email/EmailService.java @@ -85,6 +85,7 @@ public class EmailService implements AutoCloseable { private Context context; private String protocol; private boolean insecure; + private int purpose; private boolean harden; private boolean useip; private String ehlo; @@ -136,6 +137,7 @@ public class EmailService implements AutoCloseable { this.context = context.getApplicationContext(); this.protocol = protocol; this.insecure = insecure; + this.purpose = purpose; this.debug = debug; properties = MessageHelper.getSessionProperties(); @@ -369,18 +371,21 @@ public class EmailService implements AutoCloseable { } else throw ex; } catch (MessagingException ex) { - if (port == 995 && !("pop3".equals(protocol) || "pop3s".equals(protocol))) - throw new MessagingException(context.getString(R.string.title_service_port), ex); - else if (ex.getMessage() != null && - ex.getMessage().contains("Got bad greeting")) - throw new MessagingException(context.getString(R.string.title_service_protocol), ex); - else if (ex.getCause() instanceof SSLException && - ex.getCause().getMessage() != null && - ex.getCause().getMessage().contains("Unable to parse TLS packet header")) - throw new MessagingException(context.getString(R.string.title_service_protocol), ex); - else if (ex.getCause() instanceof SSLHandshakeException) - throw new MessagingException(context.getString(R.string.title_service_protocol), ex); - else + if (purpose == PURPOSE_CHECK) { + if (port == 995 && !("pop3".equals(protocol) || "pop3s".equals(protocol))) + throw new MessagingException(context.getString(R.string.title_service_port), ex); + else if (ex.getMessage() != null && + ex.getMessage().contains("Got bad greeting")) + throw new MessagingException(context.getString(R.string.title_service_protocol), ex); + else if (ex.getCause() instanceof SSLException && + ex.getCause().getMessage() != null && + ex.getCause().getMessage().contains("Unable to parse TLS packet header")) + throw new MessagingException(context.getString(R.string.title_service_protocol), ex); + else if (ex.getCause() instanceof SSLHandshakeException) + throw new MessagingException(context.getString(R.string.title_service_protocol), ex); + else + throw ex; + } else throw ex; } }