Added SOCKS proxy support

This commit is contained in:
M66B
2019-10-21 13:26:15 +02:00
parent fe7649171c
commit 6b2f54a64f
4 changed files with 92 additions and 2 deletions

View File

@@ -3,8 +3,11 @@ package eu.faircode.email;
import android.accounts.Account;
import android.accounts.AccountManager;
import android.content.Context;
import android.content.SharedPreferences;
import android.text.TextUtils;
import androidx.preference.PreferenceManager;
import com.sun.mail.imap.IMAPFolder;
import com.sun.mail.imap.IMAPStore;
import com.sun.mail.smtp.SMTPTransport;
@@ -66,6 +69,24 @@ public class MailService implements AutoCloseable {
properties = MessageHelper.getSessionProperties();
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean socks_enabled = prefs.getBoolean("socks_enabled", false);
String socks_proxy = prefs.getString("socks_proxy", "localhost:9050");
// SOCKS proxy
if (socks_enabled) {
String[] address = socks_proxy.split(":");
String host = (address.length > 0 ? address[0] : null);
String port = (address.length > 1 ? address[1] : null);
if (TextUtils.isEmpty(host))
host = "localhost";
if (TextUtils.isEmpty(port))
port = "9050";
properties.put("mail." + protocol + ".socks.host", host);
properties.put("mail." + protocol + ".socks.port", port);
Log.i("Using SOCKS proxy=" + host + ":" + port);
}
properties.put("mail.event.scope", "folder");
properties.put("mail.event.executor", executor);