diff --git a/src/com/fsck/k9/activity/setup/AccountSetupAccountType.java b/src/com/fsck/k9/activity/setup/AccountSetupAccountType.java index f4a7f34cb..203c5ee92 100644 --- a/src/com/fsck/k9/activity/setup/AccountSetupAccountType.java +++ b/src/com/fsck/k9/activity/setup/AccountSetupAccountType.java @@ -14,7 +14,12 @@ import com.fsck.k9.K9; import com.fsck.k9.Preferences; import com.fsck.k9.R; import com.fsck.k9.activity.K9Activity; +import com.fsck.k9.helper.Contacts; + +import java.io.UnsupportedEncodingException; import java.net.URI; +import java.net.URISyntaxException; +import java.net.URLEncoder; /** * Prompts the user to select an account type. The account type, along with the @@ -22,12 +27,14 @@ import java.net.URI; * AccountSetupIncoming activity. */ public class AccountSetupAccountType extends K9Activity implements OnClickListener { - private static final String EXTRA_ACCOUNT = "account"; + private static final String EXTRA_IS_MANUAL = "mManual"; + private static final String EXTRA_EMAIL = "email"; + private static final String EXTRA_PASSWORD = "password"; + private static final String EXTRA_ACCOUNT = "account"; private static final String EXTRA_MAKE_DEFAULT = "makeDefault"; private Account mAccount; - private boolean mMakeDefault; public static void actionSelectAccountType(Context context, Account account, boolean makeDefault) { @@ -37,6 +44,93 @@ public class AccountSetupAccountType extends K9Activity implements OnClickListen context.startActivity(i); } + public static void actionStartManualConfiguration(Context context, String email, String password, boolean makeDefault) { + Intent i = new Intent(context, AccountSetupAccountType.class); + i.putExtra(EXTRA_IS_MANUAL, true); + i.putExtra(EXTRA_EMAIL, email); + i.putExtra(EXTRA_PASSWORD, password); + i.putExtra(EXTRA_MAKE_DEFAULT, makeDefault); + context.startActivity(i); + } + + + /* + Initialises a new account blank. + */ + private void initialiseAccount(String email, String password) { + String[] emailParts = splitEmail(email); + String user = emailParts[0]; + String domain = emailParts[1]; + + mAccount = Preferences.getPreferences(this).newAccount(); + mAccount.setName(getOwnerName()); + mAccount.setEmail(email); + try { + String userEnc = URLEncoder.encode(user, "UTF-8"); + String passwordEnc = URLEncoder.encode(password, "UTF-8"); + + URI uri = new URI("placeholder", userEnc + ":" + passwordEnc, "mail." + domain, -1, null, + null, null); + mAccount.setStoreUri(uri.toString()); + mAccount.setTransportUri(uri.toString()); + } 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 (URISyntaxException use) { + /* + * If we can't set up the URL we just continue. It's only for + * convenience. + */ + } + mAccount.setDraftsFolderName(getString(R.string.special_mailbox_name_drafts)); + mAccount.setTrashFolderName(getString(R.string.special_mailbox_name_trash)); + mAccount.setSentFolderName(getString(R.string.special_mailbox_name_sent)); + } + + /* + Helper methods for the above, these could be in a static class in the helper package. But since + this is the only place they are used for now I'll leave them here. + */ + private String[] splitEmail(String email) { + String[] retParts = new String[2]; + String[] emailParts = email.split("@"); + retParts[0] = (emailParts.length > 0) ? emailParts[0] : ""; + retParts[1] = (emailParts.length > 1) ? emailParts[1] : ""; + return retParts; + } + + private String getOwnerName() { + String name = null; + try { + name = Contacts.getInstance(this).getOwnerName(); + } catch (Exception e) { + Log.e(K9.LOG_TAG, "Could not get owner name, using default account name", e); + } + if (name == null || name.length() == 0) { + try { + name = getDefaultAccountName(); + } catch (Exception e) { + Log.e(K9.LOG_TAG, "Could not get default account name", e); + } + } + if (name == null) { + name = ""; + } + return name; + } + + private String getDefaultAccountName() { + String name = null; + Account account = Preferences.getPreferences(this).getDefaultAccount(); + if (account != null) { + name = account.getName(); + } + return name; + } + + /* + 'Constructor' + */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -45,9 +139,14 @@ public class AccountSetupAccountType extends K9Activity implements OnClickListen ((Button)findViewById(R.id.imap)).setOnClickListener(this); ((Button)findViewById(R.id.webdav)).setOnClickListener(this); - String accountUuid = getIntent().getStringExtra(EXTRA_ACCOUNT); - mAccount = Preferences.getPreferences(this).getAccount(accountUuid); - mMakeDefault = getIntent().getBooleanExtra(EXTRA_MAKE_DEFAULT, false); + if( getIntent().getStringExtra(EXTRA_IS_MANUAL) != null){ + initialiseAccount(getIntent().getStringExtra(EXTRA_EMAIL), + getIntent().getStringExtra(EXTRA_PASSWORD)); + }else{ + String accountUuid = getIntent().getStringExtra(EXTRA_ACCOUNT); + mAccount = Preferences.getPreferences(this).getAccount(accountUuid); + mMakeDefault = getIntent().getBooleanExtra(EXTRA_MAKE_DEFAULT, false); + } } private void onPop() { diff --git a/src/com/fsck/k9/activity/setup/AccountSetupIndex.java b/src/com/fsck/k9/activity/setup/AccountSetupIndex.java index 342284765..3f40242b8 100644 --- a/src/com/fsck/k9/activity/setup/AccountSetupIndex.java +++ b/src/com/fsck/k9/activity/setup/AccountSetupIndex.java @@ -180,35 +180,7 @@ public class AccountSetupIndex extends K9ListActivity implements OnItemClickList } private void onManualSetup(String email, String password) { - String[] emailParts = splitEmail(email); - String user = emailParts[0]; - String domain = emailParts[1]; - - mAccount = Preferences.getPreferences(this).newAccount(); - mAccount.setName(getOwnerName()); - mAccount.setEmail(email); - try { - String userEnc = URLEncoder.encode(user, "UTF-8"); - String passwordEnc = URLEncoder.encode(password, "UTF-8"); - - URI uri = new URI("placeholder", userEnc + ":" + passwordEnc, "mail." + domain, -1, null, - null, null); - mAccount.setStoreUri(uri.toString()); - mAccount.setTransportUri(uri.toString()); - } 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 (URISyntaxException use) { - /* - * If we can't set up the URL we just continue. It's only for - * convenience. - */ - } - mAccount.setDraftsFolderName(getString(R.string.special_mailbox_name_drafts)); - mAccount.setTrashFolderName(getString(R.string.special_mailbox_name_trash)); - mAccount.setSentFolderName(getString(R.string.special_mailbox_name_sent)); - - AccountSetupAccountType.actionSelectAccountType(this, mAccount, bTmpDefaultAccount); + AccountSetupAccountType.actionStartManualConfiguration(this, email, password, bTmpDefaultAccount); finish(); } @@ -247,46 +219,6 @@ public class AccountSetupIndex extends K9ListActivity implements OnItemClickList } } - /* - Some helpers copy pasted from previous setup. Need a review. - */ - private String[] splitEmail(String email) { - String[] retParts = new String[2]; - String[] emailParts = email.split("@"); - retParts[0] = (emailParts.length > 0) ? emailParts[0] : ""; - retParts[1] = (emailParts.length > 1) ? emailParts[1] : ""; - return retParts; - } - - private String getOwnerName() { - String name = null; - try { - name = Contacts.getInstance(this).getOwnerName(); - } catch (Exception e) { - Log.e(K9.LOG_TAG, "Could not get owner name, using default account name", e); - } - if (name == null || name.length() == 0) { - try { - name = getDefaultAccountName(); - } catch (Exception e) { - Log.e(K9.LOG_TAG, "Could not get default account name", e); - } - } - if (name == null) { - name = ""; - } - return name; - } - - private String getDefaultAccountName() { - String name = null; - Account account = Preferences.getPreferences(this).getDefaultAccount(); - if (account != null) { - name = account.getName(); - } - return name; - } - /* Simple class to wrap account suggestion data */ diff --git a/src/com/fsck/k9/helper/configxmlparser/ConfigurationXMLHandler.java b/src/com/fsck/k9/helper/configxmlparser/ConfigurationXMLHandler.java index 1cd7861d4..066d4516c 100644 --- a/src/com/fsck/k9/helper/configxmlparser/ConfigurationXMLHandler.java +++ b/src/com/fsck/k9/helper/configxmlparser/ConfigurationXMLHandler.java @@ -252,6 +252,7 @@ public class ConfigurationXMLHandler extends DefaultHandler { Dealing with unpredictable input like this we better make sure we don't crash k-9. */ private void validateServer(Server mServerInProgress) throws SAXException{ + // TODO: check if basic information is provided } /*