From 1f6a4a9bd8a2b805ca593da4013b5fdba4bce80f Mon Sep 17 00:00:00 2001 From: M66B Date: Sat, 9 Mar 2019 16:54:43 +0000 Subject: [PATCH] Send minimal client ID --- .../main/java/eu/faircode/email/Helper.java | 19 ++++++++++++++++--- .../eu/faircode/email/ServiceSynchronize.java | 3 +-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/Helper.java b/app/src/main/java/eu/faircode/email/Helper.java index ec62a107af..e620da7d71 100644 --- a/app/src/main/java/eu/faircode/email/Helper.java +++ b/app/src/main/java/eu/faircode/email/Helper.java @@ -56,6 +56,7 @@ import android.widget.Toast; import com.android.billingclient.api.BillingClient; import com.google.android.material.bottomnavigation.BottomNavigationView; +import com.sun.mail.imap.IMAPStore; import com.sun.mail.util.FolderClosedIOException; import com.sun.mail.util.MailConnectException; @@ -83,6 +84,7 @@ import java.text.DecimalFormat; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Objects; @@ -93,7 +95,6 @@ import javax.mail.AuthenticationFailedException; import javax.mail.FolderClosedException; import javax.mail.MessageRemovedException; import javax.mail.MessagingException; -import javax.mail.Store; import javax.mail.internet.InternetAddress; import javax.net.ssl.HttpsURLConnection; @@ -802,8 +803,7 @@ public class Helper { return true; } - static void connect(Context context, Store istore, EntityAccount account) throws - MessagingException { + static void connect(Context context, IMAPStore istore, EntityAccount account) throws MessagingException { try { istore.connect(account.host, account.port, account.user, account.password); } catch (AuthenticationFailedException ex) { @@ -814,6 +814,19 @@ public class Helper { } else throw ex; } + + // https://www.ietf.org/rfc/rfc2971.txt + if (istore.hasCapability("ID")) + try { + Map id = new LinkedHashMap<>(); + id.put("name", context.getString(R.string.app_name)); + id.put("version", BuildConfig.VERSION_NAME); + Map sid = istore.id(id); + for (String key : sid.keySet()) + Log.i("Server " + key + "=" + sid.get(key)); + } catch (MessagingException ex) { + Log.w(ex); + } } static String refreshToken(Context context, String type, String name, String current) { diff --git a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java index f0be2c4dc7..5ad8637f94 100644 --- a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java +++ b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java @@ -61,7 +61,6 @@ import javax.mail.MessageRemovedException; import javax.mail.MessagingException; import javax.mail.NoSuchProviderException; import javax.mail.Session; -import javax.mail.Store; import javax.mail.StoreClosedException; import javax.mail.UIDFolder; import javax.mail.event.ConnectionAdapter; @@ -487,7 +486,7 @@ public class ServiceSynchronize extends LifecycleService { isession.setDebug(debug); // adb -t 1 logcat | grep "fairemail\|System.out" - final Store istore = isession.getStore(account.getProtocol()); + final IMAPStore istore = (IMAPStore) isession.getStore(account.getProtocol()); final Map folders = new HashMap<>(); List idlers = new ArrayList<>();