mirror of
https://github.com/M66B/FairEmail.git
synced 2026-01-02 19:10:11 +01:00
Allow updating OAuth accounts
This commit is contained in:
@@ -511,80 +511,88 @@ public class FragmentOAuth extends FragmentBase {
|
||||
try {
|
||||
db.beginTransaction();
|
||||
|
||||
EntityAccount primary = db.account().getPrimaryAccount();
|
||||
EntityAccount update = db.account().getAccount(username, AUTH_TYPE_OAUTH);
|
||||
if (update == null) {
|
||||
EntityAccount primary = db.account().getPrimaryAccount();
|
||||
|
||||
// Create account
|
||||
EntityAccount account = new EntityAccount();
|
||||
// Create account
|
||||
EntityAccount account = new EntityAccount();
|
||||
|
||||
account.host = provider.imap.host;
|
||||
account.encryption = aencryption;
|
||||
account.port = provider.imap.port;
|
||||
account.auth_type = AUTH_TYPE_OAUTH;
|
||||
account.provider = provider.id;
|
||||
account.user = username;
|
||||
account.password = state;
|
||||
account.host = provider.imap.host;
|
||||
account.encryption = aencryption;
|
||||
account.port = provider.imap.port;
|
||||
account.auth_type = AUTH_TYPE_OAUTH;
|
||||
account.provider = provider.id;
|
||||
account.user = username;
|
||||
account.password = state;
|
||||
|
||||
int at = address.indexOf('@');
|
||||
String user = address.substring(0, at);
|
||||
int at = address.indexOf('@');
|
||||
String user = address.substring(0, at);
|
||||
|
||||
account.name = provider.name + "/" + user;
|
||||
account.name = provider.name + "/" + user;
|
||||
|
||||
account.synchronize = true;
|
||||
account.primary = (primary == null);
|
||||
account.synchronize = true;
|
||||
account.primary = (primary == null);
|
||||
|
||||
if (provider.keepalive > 0)
|
||||
account.poll_interval = provider.keepalive;
|
||||
if (provider.keepalive > 0)
|
||||
account.poll_interval = provider.keepalive;
|
||||
|
||||
account.partial_fetch = provider.partial;
|
||||
account.partial_fetch = provider.partial;
|
||||
|
||||
account.created = new Date().getTime();
|
||||
account.last_connected = account.created;
|
||||
account.created = new Date().getTime();
|
||||
account.last_connected = account.created;
|
||||
|
||||
account.id = db.account().insertAccount(account);
|
||||
args.putLong("account", account.id);
|
||||
EntityLog.log(context, "OAuth account=" + account.name);
|
||||
account.id = db.account().insertAccount(account);
|
||||
args.putLong("account", account.id);
|
||||
EntityLog.log(context, "OAuth account=" + account.name);
|
||||
|
||||
// Create folders
|
||||
for (EntityFolder folder : folders) {
|
||||
EntityFolder existing = db.folder().getFolderByName(account.id, folder.name);
|
||||
if (existing == null) {
|
||||
folder.account = account.id;
|
||||
folder.id = db.folder().insertFolder(folder);
|
||||
EntityLog.log(context, "OAuth folder=" + folder.name + " type=" + folder.type);
|
||||
if (folder.synchronize)
|
||||
EntityOperation.sync(context, folder.id, false);
|
||||
// Create folders
|
||||
for (EntityFolder folder : folders) {
|
||||
EntityFolder existing = db.folder().getFolderByName(account.id, folder.name);
|
||||
if (existing == null) {
|
||||
folder.account = account.id;
|
||||
folder.id = db.folder().insertFolder(folder);
|
||||
EntityLog.log(context, "OAuth folder=" + folder.name + " type=" + folder.type);
|
||||
if (folder.synchronize)
|
||||
EntityOperation.sync(context, folder.id, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Set swipe left/right folder
|
||||
for (EntityFolder folder : folders)
|
||||
if (EntityFolder.TRASH.equals(folder.type))
|
||||
account.swipe_left = folder.id;
|
||||
else if (EntityFolder.ARCHIVE.equals(folder.type))
|
||||
account.swipe_right = folder.id;
|
||||
// Set swipe left/right folder
|
||||
for (EntityFolder folder : folders)
|
||||
if (EntityFolder.TRASH.equals(folder.type))
|
||||
account.swipe_left = folder.id;
|
||||
else if (EntityFolder.ARCHIVE.equals(folder.type))
|
||||
account.swipe_right = folder.id;
|
||||
|
||||
db.account().updateAccount(account);
|
||||
db.account().updateAccount(account);
|
||||
|
||||
// Create identities
|
||||
for (Pair<String, String> identity : identities) {
|
||||
EntityIdentity ident = new EntityIdentity();
|
||||
ident.name = identity.second;
|
||||
ident.email = identity.first;
|
||||
ident.account = account.id;
|
||||
// Create identities
|
||||
for (Pair<String, String> identity : identities) {
|
||||
EntityIdentity ident = new EntityIdentity();
|
||||
ident.name = identity.second;
|
||||
ident.email = identity.first;
|
||||
ident.account = account.id;
|
||||
|
||||
ident.host = provider.smtp.host;
|
||||
ident.encryption = iencryption;
|
||||
ident.port = provider.smtp.port;
|
||||
ident.auth_type = AUTH_TYPE_OAUTH;
|
||||
ident.provider = provider.id;
|
||||
ident.user = username;
|
||||
ident.password = state;
|
||||
ident.synchronize = true;
|
||||
ident.primary = ident.user.equals(ident.email);
|
||||
ident.max_size = max_size;
|
||||
ident.host = provider.smtp.host;
|
||||
ident.encryption = iencryption;
|
||||
ident.port = provider.smtp.port;
|
||||
ident.auth_type = AUTH_TYPE_OAUTH;
|
||||
ident.provider = provider.id;
|
||||
ident.user = username;
|
||||
ident.password = state;
|
||||
ident.synchronize = true;
|
||||
ident.primary = ident.user.equals(ident.email);
|
||||
ident.max_size = max_size;
|
||||
|
||||
ident.id = db.identity().insertIdentity(ident);
|
||||
EntityLog.log(context, "OAuth identity=" + ident.name + " email=" + ident.email);
|
||||
ident.id = db.identity().insertIdentity(ident);
|
||||
EntityLog.log(context, "OAuth identity=" + ident.name + " email=" + ident.email);
|
||||
}
|
||||
} else {
|
||||
args.putLong("account", update.id);
|
||||
EntityLog.log(context, "OAuth update account=" + update.name);
|
||||
db.account().setAccountPassword(update.id, state);
|
||||
db.identity().setIdentityPassword(update.id, update.user, state, update.auth_type);
|
||||
}
|
||||
|
||||
db.setTransactionSuccessful();
|
||||
|
||||
Reference in New Issue
Block a user