1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-08-13 17:03:48 -04:00

Tied it all together, very rough working version of the setup is in place now.

This commit is contained in:
dzan 2011-08-16 17:02:15 +02:00 committed by Andrew Chen
parent 854c0e51d4
commit a645ea08b3
6 changed files with 119 additions and 28 deletions

View File

@ -12,14 +12,12 @@ package com.fsck.k9.activity.setup;
'browse' through the available hosts. This consists of 2 auto hidden/unhidden buttons and the necessary callbacks.
The need for this is questionable, if the devs/community decide for, I'll finish the code, if not it will be removed.
*/
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.Html;
import android.text.TextWatcher;
import android.text.method.LinkMovementMethod;
import android.text.method.MovementMethod;
import android.view.View;
import android.widget.*;
import android.widget.AdapterView.OnItemSelectedListener;
@ -38,29 +36,14 @@ import java.util.List;
public abstract class AbstractSetupConfirmActivity extends K9Activity implements View.OnClickListener, OnItemSelectedListener {
private static final String EXTRA_ACCOUNT = "account";
private static final String EXTRA_CONFIG_INFO = "configInfo";
private static final String EXTRA_EMAIL = "email";
private static final String EXTRA_PASSWORD = "password";
protected static final String EXTRA_ACCOUNT = "account";
protected static final String EXTRA_CONFIG_INFO = "configInfo";
protected static final String EXTRA_EMAIL = "email";
protected static final String EXTRA_PASSWORD = "password";
private final String LOCALPART_EMAIL = "%EMAILLOCALPART%";
private final String WHOLE_EMAIL = "%EMAILADDRESS%";
public static void actionConfirmIncoming(Context context, Account account, AutoconfigInfo info) {
Intent i = new Intent(context, AccountSetupConfirmIncoming.class);
i.putExtra(EXTRA_ACCOUNT, account.getUuid());
i.putExtra(EXTRA_CONFIG_INFO, info);
context.startActivity(i);
}
public static void actionConfirmIncoming(Context context, String email, String password, AutoconfigInfo info){
Intent i = new Intent(context, AccountSetupConfirmIncoming.class);
i.putExtra(EXTRA_EMAIL, email);
i.putExtra(EXTRA_PASSWORD, password);
i.putExtra(EXTRA_CONFIG_INFO, info);
context.startActivity(i);
}
// data
protected Account mAccount;
protected AutoconfigInfo mConfigInfo;
@ -116,7 +99,7 @@ public abstract class AbstractSetupConfirmActivity extends K9Activity implements
mPassword = getIntent().getStringExtra(EXTRA_PASSWORD);
String accountUuid = getIntent().getStringExtra(EXTRA_ACCOUNT);
if(accountUuid != null)
if(accountUuid != null && !accountUuid.isEmpty())
mAccount = Preferences.getPreferences(this).getAccount(accountUuid);
else mAccount = Account.getBlankAccount(this, mEmail, mPassword);
@ -164,7 +147,6 @@ public abstract class AbstractSetupConfirmActivity extends K9Activity implements
switch( view.getId() ){
case R.id.confirm_ok_button:
finishAction();
finish();
break;
case R.id.confirm_next_server_button:
// TODO: write this,... it will probably never be used since no isp has 2 host for exact the same thing

View File

@ -384,7 +384,7 @@ public class AccountSetupAutoConfiguration extends K9Activity implements View.On
// launch confirm activities
}else{
AccountSetupConfirmIncoming.actionConfirmIncoming
(this, mEmailAddress, mPassword, mAutoConfigInfo);
(this, null, mEmailAddress, mPassword, mAutoConfigInfo);
finish();
}
break;

View File

@ -6,7 +6,10 @@ package com.fsck.k9.activity.setup;
the final settings.
*/
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import com.fsck.k9.Account;
import com.fsck.k9.K9;
import com.fsck.k9.helper.configxmlparser.AutoconfigInfo;
import com.fsck.k9.helper.configxmlparser.AutoconfigInfo.ServerType;
@ -19,6 +22,19 @@ import java.net.URLEncoder;
import java.util.List;
public class AccountSetupConfirmIncoming extends AbstractSetupConfirmActivity {
// account is allowed to be null
public static void actionConfirmIncoming(Context context, Account account, String email, String password, AutoconfigInfo info) {
Intent i = new Intent(context, AccountSetupConfirmIncoming.class);
if( account != null )
i.putExtra(EXTRA_ACCOUNT, account.getUuid());
else i.putExtra(EXTRA_ACCOUNT, "");
i.putExtra(EXTRA_EMAIL, email);
i.putExtra(EXTRA_PASSWORD, password);
i.putExtra(EXTRA_CONFIG_INFO, info);
context.startActivity(i);
}
@Override
protected List<? extends AutoconfigInfo.Server> getServers() {
return mConfigInfo.incomingServer;
@ -42,7 +58,9 @@ public class AccountSetupConfirmIncoming extends AbstractSetupConfirmActivity {
mCurrentServer.hostname,
mCurrentServer.port,
null,null,null);
mAccount.setTransportUri(uri.toString());
mAccount.setStoreUri(uri.toString());
AccountSetupConfirmOutgoing.actionConfirmOutgoing(this, mAccount, mEmail, mPassword, mConfigInfo);
}
catch (UnsupportedEncodingException enc) {}
catch (URISyntaxException use) {
@ -51,5 +69,6 @@ public class AccountSetupConfirmIncoming extends AbstractSetupConfirmActivity {
* convenience.
*/
}
finish();
}
}

View File

@ -6,11 +6,33 @@ package com.fsck.k9.activity.setup;
the final settings.
*/
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import com.fsck.k9.Account;
import com.fsck.k9.K9;
import com.fsck.k9.Preferences;
import com.fsck.k9.helper.configxmlparser.AutoconfigInfo;
import com.fsck.k9.helper.configxmlparser.AutoconfigInfo.ServerType;
import com.fsck.k9.helper.configxmlparser.AutoconfigInfo.AuthenticationType;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URLEncoder;
import java.util.List;
public class AccountSetupConfirmOutgoing extends AbstractSetupConfirmActivity{
// account is allowed to be null
public static void actionConfirmOutgoing(Context context, Account account, String email, String password, AutoconfigInfo info) {
Intent i = new Intent(context, AccountSetupConfirmOutgoing.class);
i.putExtra(EXTRA_ACCOUNT, account.getUuid());
i.putExtra(EXTRA_EMAIL, email);
i.putExtra(EXTRA_PASSWORD, password);
i.putExtra(EXTRA_CONFIG_INFO, info);
context.startActivity(i);
}
@Override
protected List<? extends AutoconfigInfo.Server> getServers() {
return mConfigInfo.outgoingServer;
@ -23,6 +45,53 @@ public class AccountSetupConfirmOutgoing extends AbstractSetupConfirmActivity{
@Override
protected void finishAction() {
//To change body of implemented methods use File | Settings | File Templates.
try {
String userInfo = null;
// check if authentication is required
if (mCurrentServer.authentication != AuthenticationType.none &&
mCurrentServer.authentication != AuthenticationType.clientIPaddress )
{
userInfo = URLEncoder.encode(mUsername, "UTF-8") + ":" +
URLEncoder.encode(mPassword, "UTF-8") + ":" +
mCurrentServer.authentication.getAuthString();
}
URI uri = new URI(
getScheme(),
userInfo,
mCurrentServer.hostname,
mCurrentServer.port,
null,null,null);
mAccount.setTransportUri(uri.toString());
AccountSetupCheckSettings.actionCheckSettings(this, mAccount, true, true);
} catch (UnsupportedEncodingException enc) {
// This really shouldn't happen since the encoding is hardcoded to UTF-8
Log.e(K9.LOG_TAG, "Couldn't urlencode username or password.", enc);
} catch (Exception e) {
/*
* It's unrecoverable if we cannot create a URI from components that
* we validated to be safe.
*/
// TODO: handle this
//failure(e);
}
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
if (Intent.ACTION_EDIT.equals(getIntent().getAction())) {
mAccount.save(Preferences.getPreferences(this));
finish();
} else {
// have to pop up to ask if it should be default account now
// hard-coded now for test purposes
AccountSetupOptions.actionOptions(this, mAccount, true);
finish();
}
}
}
}

View File

@ -186,6 +186,7 @@ public class AccountSetupIndex extends K9ListActivity implements OnItemClickList
private void startSettingsDetection(String email, String password) {
AccountSetupAutoConfiguration.actionAttemptConfiguration(this, email, password);
finish();
}
/*

View File

@ -7,6 +7,9 @@
package com.fsck.k9.helper.configxmlparser;
import java.io.UnsupportedEncodingException;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@ -52,7 +55,24 @@ public class AutoconfigInfo implements Parcelable {
/*******************************************************************************
Define types for some of the data
*******************************************************************************/
public static enum AuthenticationType { plain, secure, NTLM, GSSAPI, clientIPaddress, TLSclientcert, none, UNSET };
public static enum AuthenticationType {
plain(1), secure(2), NTLM(-1), GSSAPI(-1), clientIPaddress(0), TLSclientcert(-1), none(0), UNSET(-1);
/*
K-9 only supports plain or CRAM-MD5 so we'll toss an error for all the rest and just check this manually
*/
private int type;
AuthenticationType(int type){ this.type = type; }
public String getAuthString() throws UnsupportedEncodingException {
switch( type ){
case 0: return "";
case 1: return "PLAIN";
case 2: return "CRAM_MD5";
default: throw new UnsupportedEncodingException();
}
}
};
public static enum SocketType { plain(""), SSL("ssl"), STARTTLS("tls"), UNSET("");
private String schemeName;