Revert "POP support"

This reverts commit f246284812.
This commit is contained in:
M66B 2019-02-09 09:03:07 +00:00
parent 3dc68763fd
commit af5ae44c82
11 changed files with 35 additions and 1615 deletions

File diff suppressed because it is too large Load Diff

View File

@ -49,7 +49,7 @@ import io.requery.android.database.sqlite.RequerySQLiteOpenHelperFactory;
// https://developer.android.com/topic/libraries/architecture/room.html
@Database(
version = 42,
version = 41,
entities = {
EntityIdentity.class,
EntityAccount.class,
@ -482,13 +482,6 @@ public abstract class DB extends RoomDatabase {
db.execSQL("ALTER TABLE `message` ADD COLUMN `flags` TEXT");
}
})
.addMigrations(new Migration(41, 42) {
@Override
public void migrate(SupportSQLiteDatabase db) {
Log.i("DB migration from version " + startVersion + " to " + endVersion);
db.execSQL("ALTER TABLE `account` ADD COLUMN `pop` INTEGER NOT NULL DEFAULT 0");
}
})
.build();
}

View File

@ -49,9 +49,7 @@ public class EntityAccount implements Serializable {
@NonNull
public Integer auth_type;
@NonNull
public Boolean pop = false;
@NonNull
public String host; // POP3/IMAP
public String host; // IMAP
@NonNull
public Boolean starttls;
@NonNull
@ -88,10 +86,6 @@ public class EntityAccount implements Serializable {
public String error;
public Long last_connected;
String getProtocol() {
return (pop ? "pop3" : "imap") + (starttls ? "" : "s");
}
static String getNotificationChannelName(long account) {
return "notification." + account;
}
@ -116,7 +110,6 @@ public class EntityAccount implements Serializable {
JSONObject json = new JSONObject();
json.put("id", id);
json.put("auth_type", auth_type);
json.put("pop", pop);
json.put("host", host);
json.put("starttls", starttls);
json.put("insecure", insecure);
@ -149,8 +142,6 @@ public class EntityAccount implements Serializable {
EntityAccount account = new EntityAccount();
// id
account.auth_type = json.getInt("auth_type");
if (json.has("pop"))
account.pop = json.getBoolean("pop");
account.host = json.getString("host");
account.starttls = (json.has("starttls") && json.getBoolean("starttls"));
account.insecure = (json.has("insecure") && json.getBoolean("insecure"));

View File

@ -87,10 +87,6 @@ public class EntityIdentity {
public String error;
public Long last_connected;
String getProtocol() {
return (starttls ? "smtp" : "smtps");
}
public JSONObject toJSON() throws JSONException {
JSONObject json = new JSONObject();
json.put("id", id);

View File

@ -74,11 +74,9 @@ import java.util.Properties;
import javax.mail.AuthenticationFailedException;
import javax.mail.Folder;
import javax.mail.Session;
import javax.mail.Store;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.SwitchCompat;
import androidx.constraintlayout.widget.Group;
import androidx.fragment.app.FragmentTransaction;
@ -93,7 +91,6 @@ public class FragmentAccount extends FragmentBase {
private Button btnAutoConfig;
private Button btnAuthorize;
private SwitchCompat swPop;
private EditText etHost;
private CheckBox cbStartTls;
private CheckBox cbInsecure;
@ -168,7 +165,6 @@ public class FragmentAccount extends FragmentBase {
btnAutoConfig = view.findViewById(R.id.btnAutoConfig);
btnAuthorize = view.findViewById(R.id.btnAuthorize);
swPop = view.findViewById(R.id.swPop);
etHost = view.findViewById(R.id.etHost);
etPort = view.findViewById(R.id.etPort);
cbStartTls = view.findViewById(R.id.cbStartTls);
@ -239,7 +235,6 @@ public class FragmentAccount extends FragmentBase {
auth_type = Helper.AUTH_TYPE_PASSWORD;
swPop.setChecked(false);
etHost.setText(provider.imap_host);
etPort.setText(provider.imap_host == null ? null : Integer.toString(provider.imap_port));
cbStartTls.setChecked(provider.imap_starttls);
@ -285,33 +280,10 @@ public class FragmentAccount extends FragmentBase {
}
});
swPop.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
boolean starttls = cbStartTls.isChecked();
if (isChecked) {
etHost.setHint("pop.domain.tld");
etPort.setHint(starttls ? "110" : "995");
etRealm.setText(null);
cbBrowse.setChecked(false);
etPrefix.setText(null);
} else {
etHost.setHint("imap.domain.tld");
etPort.setHint(starttls ? "143" : "993");
}
etRealm.setEnabled(!isChecked);
cbBrowse.setEnabled(!isChecked);
etPrefix.setEnabled(!isChecked);
}
});
cbStartTls.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
if (swPop.isChecked())
etPort.setHint(checked ? "110" : "995");
else
etPort.setHint(checked ? "143" : "993");
etPort.setHint(checked ? "143" : "993");
}
});
@ -500,7 +472,6 @@ public class FragmentAccount extends FragmentBase {
@Override
protected void onExecuted(Bundle args, EmailProvider provider) {
swPop.setChecked(false);
etHost.setText(provider.imap_host);
etPort.setText(Integer.toString(provider.imap_port));
cbStartTls.setChecked(provider.imap_starttls);
@ -520,7 +491,6 @@ public class FragmentAccount extends FragmentBase {
Bundle args = new Bundle();
args.putLong("id", id);
args.putInt("auth_type", auth_type);
args.putBoolean("pop", swPop.isChecked());
args.putString("host", etHost.getText().toString());
args.putBoolean("starttls", cbStartTls.isChecked());
args.putBoolean("insecure", cbInsecure.isChecked());
@ -553,7 +523,6 @@ public class FragmentAccount extends FragmentBase {
protected CheckResult onExecute(Context context, Bundle args) throws Throwable {
long id = args.getLong("id");
int auth_type = args.getInt("auth_type");
boolean pop = args.getBoolean("pop");
String host = args.getString("host");
boolean starttls = args.getBoolean("starttls");
boolean insecure = args.getBoolean("insecure");
@ -565,10 +534,7 @@ public class FragmentAccount extends FragmentBase {
if (TextUtils.isEmpty(host))
throw new IllegalArgumentException(context.getString(R.string.title_no_host));
if (TextUtils.isEmpty(port))
if (pop)
port = (starttls ? "110" : "995");
else
port = (starttls ? "143" : "993");
port = (starttls ? "143" : "993");
if (TextUtils.isEmpty(user))
throw new IllegalArgumentException(context.getString(R.string.title_no_user));
if (TextUtils.isEmpty(password) && !insecure)
@ -587,9 +553,9 @@ public class FragmentAccount extends FragmentBase {
Properties props = MessageHelper.getSessionProperties(auth_type, realm, insecure);
Session isession = Session.getInstance(props, null);
isession.setDebug(true);
Store istore = null;
IMAPStore istore = null;
try {
istore = isession.getStore((pop ? "pop3" : "imap") + (starttls ? "" : "s"));
istore = (IMAPStore) isession.getStore(starttls ? "imap" : "imaps");
try {
istore.connect(host, Integer.parseInt(port), user, password);
} catch (AuthenticationFailedException ex) {
@ -600,8 +566,7 @@ public class FragmentAccount extends FragmentBase {
throw ex;
}
if (istore instanceof IMAPStore)
result.idle = ((IMAPStore) istore).hasCapability("IDLE");
result.idle = istore.hasCapability("IDLE");
boolean inbox = false;
boolean archive = false;
@ -618,11 +583,7 @@ public class FragmentAccount extends FragmentBase {
for (Folder ifolder : istore.getDefaultFolder().list("*")) {
// Check folder attributes
String fullName = ifolder.getFullName();
String[] attrs;
if (ifolder instanceof IMAPFolder)
attrs = ((IMAPFolder) ifolder).getAttributes();
else
attrs = new String[0];
String[] attrs = ((IMAPFolder) ifolder).getAttributes();
Log.i(fullName + " attrs=" + TextUtils.join(" ", attrs));
String type = EntityFolder.getType(attrs, fullName);
@ -699,15 +660,9 @@ public class FragmentAccount extends FragmentBase {
@Override
protected void onExecuted(Bundle args, CheckResult result) {
boolean pop = args.getBoolean("pop");
tvIdle.setVisibility(result.idle ? View.GONE : View.VISIBLE);
tvIdle.setVisibility(result.idle || pop ? View.GONE : View.VISIBLE);
if (pop) {
grpFolders.setVisibility(View.GONE);
btnSave.setVisibility(View.VISIBLE);
} else
setFolders(result.folders, result.account);
setFolders(result.folders, result.account);
new Handler().post(new Runnable() {
@Override
@ -766,7 +721,6 @@ public class FragmentAccount extends FragmentBase {
args.putLong("id", id);
args.putInt("auth_type", auth_type);
args.putBoolean("pop", swPop.isChecked());
args.putString("host", etHost.getText().toString());
args.putBoolean("starttls", cbStartTls.isChecked());
args.putBoolean("insecure", cbInsecure.isChecked());
@ -816,7 +770,6 @@ public class FragmentAccount extends FragmentBase {
long id = args.getLong("id");
int auth_type = args.getInt("auth_type");
boolean pop = args.getBoolean("pop");
String host = args.getString("host");
boolean starttls = args.getBoolean("starttls");
boolean insecure = args.getBoolean("insecure");
@ -846,10 +799,7 @@ public class FragmentAccount extends FragmentBase {
if (TextUtils.isEmpty(host))
throw new IllegalArgumentException(context.getString(R.string.title_no_host));
if (TextUtils.isEmpty(port))
if (pop)
port = (starttls ? "110" : "995");
else
port = (starttls ? "143" : "993");
port = (starttls ? "143" : "993");
if (TextUtils.isEmpty(user))
throw new IllegalArgumentException(context.getString(R.string.title_no_user));
if (synchronize && TextUtils.isEmpty(password) && !insecure)
@ -875,7 +825,6 @@ public class FragmentAccount extends FragmentBase {
boolean check = (synchronize && (account == null ||
auth_type != account.auth_type ||
pop != account.pop ||
!host.equals(account.host) || Integer.parseInt(port) != account.port ||
!user.equals(account.user) || !password.equals(account.password) ||
(realm == null ? accountRealm != null : !realm.equals(accountRealm))));
@ -895,9 +844,9 @@ public class FragmentAccount extends FragmentBase {
Session isession = Session.getInstance(props, null);
isession.setDebug(true);
Store istore = null;
IMAPStore istore = null;
try {
istore = isession.getStore((pop ? "pop3" : "imap") + (starttls ? "" : "s"));
istore = (IMAPStore) isession.getStore(starttls ? "imap" : "imaps");
try {
istore.connect(host, Integer.parseInt(port), user, password);
} catch (AuthenticationFailedException ex) {
@ -912,11 +861,7 @@ public class FragmentAccount extends FragmentBase {
for (Folder ifolder : istore.getDefaultFolder().list("*")) {
// Check folder attributes
String fullName = ifolder.getFullName();
String[] attrs;
if (ifolder instanceof IMAPFolder)
attrs = ((IMAPFolder) ifolder).getAttributes();
else
attrs = new String[0];
String[] attrs = ((IMAPFolder) ifolder).getAttributes();
Log.i(fullName + " attrs=" + TextUtils.join(" ", attrs));
String type = EntityFolder.getType(attrs, fullName);
@ -949,7 +894,6 @@ public class FragmentAccount extends FragmentBase {
account = new EntityAccount();
account.auth_type = auth_type;
account.pop = pop;
account.host = host;
account.starttls = starttls;
account.insecure = insecure;
@ -1167,7 +1111,6 @@ public class FragmentAccount extends FragmentBase {
spProvider.setTag(1);
spProvider.setSelection(1);
}
swPop.setChecked(account.pop);
etHost.setText(account.host);
etPort.setText(Long.toString(account.port));
}
@ -1230,15 +1173,6 @@ public class FragmentAccount extends FragmentBase {
// Consider previous check/save/delete as cancelled
pbWait.setVisibility(View.GONE);
if (account != null && account.pop) {
etRealm.setEnabled(false);
cbBrowse.setEnabled(false);
etPrefix.setEnabled(false);
grpFolders.setVisibility(View.GONE);
btnSave.setVisibility(View.VISIBLE);
return;
}
args.putLong("account", account == null ? -1 : account.id);
new SimpleTask<List<EntityFolder>>() {

View File

@ -581,11 +581,11 @@ public class FragmentIdentity extends FragmentBase {
// Check SMTP server
if (check) {
String protocol = (starttls ? "smtp" : "smtps");
String transportType = (starttls ? "smtp" : "smtps");
Properties props = MessageHelper.getSessionProperties(auth_type, realm, insecure);
Session isession = Session.getInstance(props, null);
isession.setDebug(true);
Transport itransport = isession.getTransport(protocol);
Transport itransport = isession.getTransport(transportType);
try {
try {
itransport.connect(host, Integer.parseInt(port), user, password);

View File

@ -165,26 +165,6 @@ public class MessageHelper {
props.put("mail.smtp.writetimeout", Integer.toString(NETWORK_TIMEOUT)); // one thread overhead
props.put("mail.smtp.timeout", Integer.toString(NETWORK_TIMEOUT));
// https://javaee.github.io/javamail/docs/api/com/sun/mail/pop3/package-summary.html
props.put("mail.pop3s.ssl.checkserveridentity", checkserveridentity);
props.put("mail.pop3s.ssl.trust", "*");
props.put("mail.pop3s.starttls.enable", "false");
props.put("mail.pop3s.starttls.required", "false");
props.put("mail.pop3s.connectiontimeout", Integer.toString(NETWORK_TIMEOUT));
props.put("mail.pop3s.timeout", Integer.toString(NETWORK_TIMEOUT));
props.put("mail.pop3s.writetimeout", Integer.toString(NETWORK_TIMEOUT)); // one thread overhead
props.put("mail.pop3.ssl.checkserveridentity", checkserveridentity);
props.put("mail.pop3.ssl.trust", "*");
props.put("mail.pop3.starttls.enable", "true");
props.put("mail.pop3.starttls.required", "true");
props.put("mail.pop3.connectiontimeout", Integer.toString(NETWORK_TIMEOUT));
props.put("mail.pop3.timeout", Integer.toString(NETWORK_TIMEOUT));
props.put("mail.pop3.writetimeout", Integer.toString(NETWORK_TIMEOUT)); // one thread overhead
// MIME
props.put("mail.mime.allowutf8", "true"); // SMTPTransport, MimeMessage
props.put("mail.mime.address.strict", "false");

View File

@ -817,7 +817,7 @@ public class ServiceSynchronize extends LifecycleService {
isession.setDebug(debug);
// adb -t 1 logcat | grep "fairemail\|System.out"
final IMAPStore istore = (IMAPStore) isession.getStore(account.getProtocol());
final IMAPStore istore = (IMAPStore) isession.getStore(account.starttls ? "imap" : "imaps");
final Map<EntityFolder, IMAPFolder> folders = new HashMap<>();
List<Thread> idlers = new ArrayList<>();
List<Handler> handlers = new ArrayList<>();
@ -1889,6 +1889,8 @@ public class ServiceSynchronize extends LifecycleService {
db.message().setMessageLastAttempt(message.id, message.last_attempt);
}
String transportType = (ident.starttls ? "smtp" : "smtps");
// Get properties
Properties props = MessageHelper.getSessionProperties(ident.auth_type, ident.realm, ident.insecure);
props.put("mail.smtp.localhost", ident.host);
@ -1923,7 +1925,7 @@ public class ServiceSynchronize extends LifecycleService {
// Create transport
// TODO: cache transport?
Transport itransport = isession.getTransport(ident.getProtocol());
Transport itransport = isession.getTransport(transportType);
try {
// Connect transport
db.identity().setIdentityState(ident.id, "connecting");

View File

@ -158,7 +158,7 @@ public class ViewModelBrowse extends ViewModel {
isession.setDebug(true);
Log.i("Boundary connecting account=" + account.name);
state.istore = (IMAPStore) isession.getStore(account.getProtocol());
state.istore = (IMAPStore) isession.getStore(account.starttls ? "imap" : "imaps");
Helper.connect(state.context, state.istore, account);
Log.i("Boundary opening folder=" + folder.name);

View File

@ -75,37 +75,27 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/etDomain" />
<!-- IMAP/POP3 -->
<!-- IMAP -->
<TextView
android:id="@+id/tvImap"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/title_imap"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Small"
app:layout_constraintBottom_toBottomOf="@+id/swPop"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/swPop" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swPop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="6dp"
android:layout_marginTop="12dp"
app:layout_constraintStart_toEndOf="@id/tvImap"
android:text="@string/title_imap"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/btnAutoConfig" />
<TextView
android:id="@+id/tvPop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="6dp"
android:text="@string/title_pop3"
android:textAppearance="@style/Base.TextAppearance.AppCompat.Small"
app:layout_constraintBottom_toBottomOf="@id/swPop"
app:layout_constraintStart_toEndOf="@id/swPop"
app:layout_constraintTop_toTopOf="@id/swPop" />
android:text="@string/title_pop"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textStyle="italic"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvImap" />
<!-- host -->
@ -117,7 +107,7 @@
android:text="@string/title_host"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swPop" />
app:layout_constraintTop_toBottomOf="@id/tvPop" />
<EditText
android:id="@+id/etHost"
@ -681,36 +671,24 @@
android:id="@+id/grpServer"
android:layout_width="0dp"
android:layout_height="0dp"
app:constraint_referenced_ids="
tvDomain,tvDomainHint,etDomain,btnAutoConfig,
tvImap,swPop,tvPop,tvHost,etHost,cbStartTls,cbInsecure,tvPort,etPort" />
app:constraint_referenced_ids="tvDomain,tvDomainHint,etDomain,btnAutoConfig,tvImap,tvPop,tvHost,etHost,cbStartTls,cbInsecure,tvPort,etPort" />
<androidx.constraintlayout.widget.Group
android:id="@+id/grpAuthorize"
android:layout_width="0dp"
android:layout_height="0dp"
app:constraint_referenced_ids="
tvUser,etUser,tvPassword,tilPassword,tvRealm,etRealm,
tvName,tvNameRemark,etName,btnColor,vwColor,ibColorDefault" />
app:constraint_referenced_ids="tvUser,etUser,tvPassword,tilPassword,tvRealm,etRealm,tvName,tvNameRemark,etName,btnColor,vwColor,ibColorDefault" />
<androidx.constraintlayout.widget.Group
android:id="@+id/grpAdvanced"
android:layout_width="0dp"
android:layout_height="0dp"
app:constraint_referenced_ids="
tvPrefix,tvPrefixRemark,etPrefix,cbNotify,
cbSynchronize,cbPrimary,cbBrowse,tvBrowseHint,tvInterval,etInterval" />
app:constraint_referenced_ids="tvPrefix,tvPrefixRemark,etPrefix,cbNotify,cbSynchronize,cbPrimary,cbBrowse,tvBrowseHint,tvInterval,etInterval" />
<androidx.constraintlayout.widget.Group
android:id="@+id/grpFolders"
android:layout_width="0dp"
android:layout_height="0dp"
app:constraint_referenced_ids="
tvDrafts,spDrafts,tvDraftsRemark,
tvSent,spSent,
tvAll,spAll,
tvTrash,spTrash,
tvJunk,spJunk,
vSeparatorSwipe,tvLeft,spLeft,tvRight,spRight" />
app:constraint_referenced_ids="tvDrafts,spDrafts,tvDraftsRemark,tvSent,spSent,tvAll,spAll,tvTrash,spTrash,tvJunk,spJunk,vSeparatorSwipe,tvLeft,spLeft,tvRight,spRight" />
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>

View File

@ -210,7 +210,6 @@
<string name="title_domain">Domain name</string>
<string name="title_autoconfig">Get settings</string>
<string name="title_imap" translatable="false">IMAP</string>
<string name="title_pop3" translatable="false">POP3</string>
<string name="title_smtp" translatable="false">SMTP</string>
<string name="title_provider">Provider</string>
<string name="title_custom">Custom</string>