From df59723f08009db612c8fb85dade194e94bf5628 Mon Sep 17 00:00:00 2001 From: M66B Date: Sun, 12 Jan 2020 19:10:10 +0100 Subject: [PATCH] Fixed not recognizing cert errors --- .../main/java/eu/faircode/email/MailService.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/MailService.java b/app/src/main/java/eu/faircode/email/MailService.java index 37ace3ef87..f68b211379 100644 --- a/app/src/main/java/eu/faircode/email/MailService.java +++ b/app/src/main/java/eu/faircode/email/MailService.java @@ -59,7 +59,6 @@ import javax.mail.Session; import javax.mail.Store; import javax.mail.event.StoreListener; import javax.net.ssl.SSLContext; -import javax.net.ssl.SSLHandshakeException; import javax.net.ssl.SSLSocketFactory; import javax.net.ssl.TrustManager; import javax.net.ssl.TrustManagerFactory; @@ -379,12 +378,15 @@ public class MailService implements AutoCloseable { } else throw new NoSuchProviderException(protocol); } catch (MessagingException ex) { - if (factory != null && - ex.getCause() instanceof SSLHandshakeException && - ex.getCause().getCause() instanceof CertificateException) - throw new UntrustedException(factory.getFingerPrint(), ex); - else - throw ex; + if (factory != null) { + Throwable ce = ex; + while (ce != null) { + if (ce instanceof CertificateException) + throw new UntrustedException(factory.getFingerPrint(), ex); + ce = ce.getCause(); + } + } + throw ex; } }