From a645ea08b32480acc4d44317b8fae3e7d01d7567 Mon Sep 17 00:00:00 2001 From: dzan Date: Tue, 16 Aug 2011 17:02:15 +0200 Subject: [PATCH] Tied it all together, very rough working version of the setup is in place now. --- .../setup/AbstractSetupConfirmActivity.java | 30 ++------ .../setup/AccountSetupAutoConfiguration.java | 2 +- .../setup/AccountSetupConfirmIncoming.java | 21 +++++- .../setup/AccountSetupConfirmOutgoing.java | 71 ++++++++++++++++++- .../k9/activity/setup/AccountSetupIndex.java | 1 + .../configxmlparser/AutoconfigInfo.java | 22 +++++- 6 files changed, 119 insertions(+), 28 deletions(-) diff --git a/src/com/fsck/k9/activity/setup/AbstractSetupConfirmActivity.java b/src/com/fsck/k9/activity/setup/AbstractSetupConfirmActivity.java index b139ca4da..cecaa1cfc 100644 --- a/src/com/fsck/k9/activity/setup/AbstractSetupConfirmActivity.java +++ b/src/com/fsck/k9/activity/setup/AbstractSetupConfirmActivity.java @@ -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 diff --git a/src/com/fsck/k9/activity/setup/AccountSetupAutoConfiguration.java b/src/com/fsck/k9/activity/setup/AccountSetupAutoConfiguration.java index 2d1c22912..88cedd182 100644 --- a/src/com/fsck/k9/activity/setup/AccountSetupAutoConfiguration.java +++ b/src/com/fsck/k9/activity/setup/AccountSetupAutoConfiguration.java @@ -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; diff --git a/src/com/fsck/k9/activity/setup/AccountSetupConfirmIncoming.java b/src/com/fsck/k9/activity/setup/AccountSetupConfirmIncoming.java index 61eb3b0e2..e45eac86a 100644 --- a/src/com/fsck/k9/activity/setup/AccountSetupConfirmIncoming.java +++ b/src/com/fsck/k9/activity/setup/AccountSetupConfirmIncoming.java @@ -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 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(); } } diff --git a/src/com/fsck/k9/activity/setup/AccountSetupConfirmOutgoing.java b/src/com/fsck/k9/activity/setup/AccountSetupConfirmOutgoing.java index 65d7ded1c..a6bf30084 100644 --- a/src/com/fsck/k9/activity/setup/AccountSetupConfirmOutgoing.java +++ b/src/com/fsck/k9/activity/setup/AccountSetupConfirmOutgoing.java @@ -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 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(); + } + } } } \ No newline at end of file diff --git a/src/com/fsck/k9/activity/setup/AccountSetupIndex.java b/src/com/fsck/k9/activity/setup/AccountSetupIndex.java index 3f40242b8..152ad83a5 100644 --- a/src/com/fsck/k9/activity/setup/AccountSetupIndex.java +++ b/src/com/fsck/k9/activity/setup/AccountSetupIndex.java @@ -186,6 +186,7 @@ public class AccountSetupIndex extends K9ListActivity implements OnItemClickList private void startSettingsDetection(String email, String password) { AccountSetupAutoConfiguration.actionAttemptConfiguration(this, email, password); + finish(); } /* diff --git a/src/com/fsck/k9/helper/configxmlparser/AutoconfigInfo.java b/src/com/fsck/k9/helper/configxmlparser/AutoconfigInfo.java index 6c57f1922..5bd0d8943 100644 --- a/src/com/fsck/k9/helper/configxmlparser/AutoconfigInfo.java +++ b/src/com/fsck/k9/helper/configxmlparser/AutoconfigInfo.java @@ -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;