Merge "Allow globals in the providers.xml"
This commit is contained in:
commit
e369f2772c
@ -233,220 +233,8 @@
|
||||
<incoming uri="pop3://pop-server.roadrunner.com" username="$email" />
|
||||
<outgoing uri="smtp://mobile-smtp.roadrunner.com" username="$email" />
|
||||
</provider>
|
||||
<provider id="rr-austin" label="RoadRunner" domain="austin.rr.com">
|
||||
<incoming uri="pop3://pop-server.austin.rr.com" username="$email" />
|
||||
<outgoing uri="smtp://mobile-smtp.roadrunner.com" username="$email" />
|
||||
</provider>
|
||||
<provider id="rr-bak" label="RoadRunner" domain="bak.rr.com">
|
||||
<incoming uri="pop3://pop-server.bak.rr.com" username="$email" />
|
||||
<outgoing uri="smtp://mobile-smtp.roadrunner.com" username="$email" />
|
||||
</provider>
|
||||
<provider id="rr-berkshire" label="RoadRunner" domain="berkshire.rr.com">
|
||||
<incoming uri="pop3://pop-server.berkshire.rr.com" username="$email" />
|
||||
<outgoing uri="smtp://mobile-smtp.roadrunner.com" username="$email" />
|
||||
</provider>
|
||||
<provider id="rr-bham" label="RoadRunner" domain="bham.rr.com">
|
||||
<incoming uri="pop3://pop-server.bham.rr.com" username="$email" />
|
||||
<outgoing uri="smtp://mobile-smtp.roadrunner.com" username="$email" />
|
||||
</provider>
|
||||
<provider id="rr-ca" label="RoadRunner" domain="ca.rr.com">
|
||||
<incoming uri="pop3://pop-server.ca.rr.com" username="$email" />
|
||||
<outgoing uri="smtp://mobile-smtp.roadrunner.com" username="$email" />
|
||||
</provider>
|
||||
<provider id="rr-carolina" label="RoadRunner" domain="carolina.rr.com">
|
||||
<incoming uri="pop3://pop-server.carolina.rr.com" username="$email" />
|
||||
<outgoing uri="smtp://mobile-smtp.roadrunner.com" username="$email" />
|
||||
</provider>
|
||||
<provider id="rr-cfl" label="RoadRunner" domain="cfl.rr.com">
|
||||
<incoming uri="pop3://pop-server.cfl.rr.com" username="$email" />
|
||||
<outgoing uri="smtp://mobile-smtp.roadrunner.com" username="$email" />
|
||||
</provider>
|
||||
<provider id="rr-cinci" label="RoadRunner" domain="cinci.rr.com">
|
||||
<incoming uri="pop3://pop-server.cinci.rr.com" username="$email" />
|
||||
<outgoing uri="smtp://mobile-smtp.roadrunner.com" username="$email" />
|
||||
</provider>
|
||||
<provider id="rr-columbus" label="RoadRunner" domain="columbus.rr.com">
|
||||
<incoming uri="pop3://pop-server.columbus.rr.com" username="$email" />
|
||||
<outgoing uri="smtp://mobile-smtp.roadrunner.com" username="$email" />
|
||||
</provider>
|
||||
<provider id="rr-dc" label="RoadRunner" domain="dc.rr.com">
|
||||
<incoming uri="pop3://pop-server.dc.rr.com" username="$email" />
|
||||
<outgoing uri="smtp://mobile-smtp.roadrunner.com" username="$email" />
|
||||
</provider>
|
||||
<provider id="rr-ec" label="RoadRunner" domain="ec.rr.com">
|
||||
<incoming uri="pop3://pop-server.ec.rr.com" username="$email" />
|
||||
<outgoing uri="smtp://mobile-smtp.roadrunner.com" username="$email" />
|
||||
</provider>
|
||||
<provider id="rr-elmore" label="RoadRunner" domain="elmore.rr.com">
|
||||
<incoming uri="pop3://pop-server.elmore.rr.com" username="$email" />
|
||||
<outgoing uri="smtp://mobile-smtp.roadrunner.com" username="$email" />
|
||||
</provider>
|
||||
<provider id="rr-elp" label="RoadRunner" domain="elp.rr.com">
|
||||
<incoming uri="pop3://pop-server.elp.rr.com" username="$email" />
|
||||
<outgoing uri="smtp://mobile-smtp.roadrunner.com" username="$email" />
|
||||
</provider>
|
||||
<provider id="rr-eufaula" label="RoadRunner" domain="eufaula.rr.com">
|
||||
<incoming uri="pop3://pop-server.eufaula.rr.com" username="$email" />
|
||||
<outgoing uri="smtp://mobile-smtp.roadrunner.com" username="$email" />
|
||||
</provider>
|
||||
<provider id="rr-gt" label="RoadRunner" domain="gt.rr.com">
|
||||
<incoming uri="pop3://pop-server.gt.rr.com" username="$email" />
|
||||
<outgoing uri="smtp://mobile-smtp.roadrunner.com" username="$email" />
|
||||
</provider>
|
||||
<provider id="rr-hawaii" label="RoadRunner" domain="hawaii.rr.com">
|
||||
<incoming uri="pop3://pop-server.hawaii.rr.com" username="$email" />
|
||||
<outgoing uri="smtp://mobile-smtp.roadrunner.com" username="$email" />
|
||||
</provider>
|
||||
<provider id="rr-hot" label="RoadRunner" domain="hot.rr.com">
|
||||
<incoming uri="pop3://pop-server.hot.rr.com" username="$email" />
|
||||
<outgoing uri="smtp://mobile-smtp.roadrunner.com" username="$email" />
|
||||
</provider>
|
||||
<provider id="rr-hvc" label="RoadRunner" domain="hvc.rr.com">
|
||||
<incoming uri="pop3://pop-server.hvc.rr.com" username="$email" />
|
||||
<outgoing uri="smtp://mobile-smtp.roadrunner.com" username="$email" />
|
||||
</provider>
|
||||
<provider id="rr-indy" label="RoadRunner" domain="indy.rr.com">
|
||||
<incoming uri="pop3://pop-server.indy.rr.com" username="$email" />
|
||||
<outgoing uri="smtp://mobile-smtp.roadrunner.com" username="$email" />
|
||||
</provider>
|
||||
<provider id="rr-insight" label="RoadRunner" domain="insight.rr.com">
|
||||
<incoming uri="pop3://pop-server.insight.rr.com" username="$email" />
|
||||
<outgoing uri="smtp://mobile-smtp.roadrunner.com" username="$email" />
|
||||
</provider>
|
||||
<provider id="rr-kc" label="RoadRunner" domain="kc.rr.com">
|
||||
<incoming uri="pop3://pop-server.kc.rr.com" username="$email" />
|
||||
<outgoing uri="smtp://mobile-smtp.roadrunner.com" username="$email" />
|
||||
</provider>
|
||||
<provider id="rr-ma" label="RoadRunner" domain="ma.rr.com">
|
||||
<incoming uri="pop3://pop-server.ma.rr.com" username="$email" />
|
||||
<outgoing uri="smtp://mobile-smtp.roadrunner.com" username="$email" />
|
||||
</provider>
|
||||
<provider id="rr-maine" label="RoadRunner" domain="maine.rr.com">
|
||||
<incoming uri="pop3://pop-server.maine.rr.com" username="$email" />
|
||||
<outgoing uri="smtp://mobile-smtp.roadrunner.com" username="$email" />
|
||||
</provider>
|
||||
<provider id="rr-mass" label="RoadRunner" domain="mass.rr.com">
|
||||
<incoming uri="pop3://pop-server.mass.rr.com" username="$email" />
|
||||
<outgoing uri="smtp://mobile-smtp.roadrunner.com" username="$email" />
|
||||
</provider>
|
||||
<provider id="rr-mi" label="RoadRunner" domain="mi.rr.com">
|
||||
<incoming uri="pop3://pop-server.mi.rr.com" username="$email" />
|
||||
<outgoing uri="smtp://mobile-smtp.roadrunner.com" username="$email" />
|
||||
</provider>
|
||||
<provider id="rr-nc" label="RoadRunner" domain="nc.rr.com">
|
||||
<incoming uri="pop3://pop-server.nc.rr.com" username="$email" />
|
||||
<outgoing uri="smtp://mobile-smtp.roadrunner.com" username="$email" />
|
||||
</provider>
|
||||
<provider id="rr-ne" label="RoadRunner" domain="ne.rr.com">
|
||||
<incoming uri="pop3://pop-server.ne.rr.com" username="$email" />
|
||||
<outgoing uri="smtp://mobile-smtp.roadrunner.com" username="$email" />
|
||||
</provider>
|
||||
<provider id="rr-neb" label="RoadRunner" domain="neb.rr.com">
|
||||
<incoming uri="pop3://pop-server.neb.rr.com" username="$email" />
|
||||
<outgoing uri="smtp://mobile-smtp.roadrunner.com" username="$email" />
|
||||
</provider>
|
||||
<provider id="rr-neo" label="RoadRunner" domain="neo.rr.com">
|
||||
<incoming uri="pop3://pop-server.neo.rr.com" username="$email" />
|
||||
<outgoing uri="smtp://mobile-smtp.roadrunner.com" username="$email" />
|
||||
</provider>
|
||||
<provider id="rr-new" label="RoadRunner" domain="new.rr.com">
|
||||
<incoming uri="pop3://pop-server.new.rr.com" username="$email" />
|
||||
<outgoing uri="smtp://mobile-smtp.roadrunner.com" username="$email" />
|
||||
</provider>
|
||||
<provider id="rr-nj" label="RoadRunner" domain="nj.rr.com">
|
||||
<incoming uri="pop3://pop-server.nj.rr.com" username="$email" />
|
||||
<outgoing uri="smtp://mobile-smtp.roadrunner.com" username="$email" />
|
||||
</provider>
|
||||
<provider id="rr-nyc" label="RoadRunner" domain="nyc.rr.com">
|
||||
<incoming uri="pop3://pop-server.nyc.rr.com" username="$email" />
|
||||
<outgoing uri="smtp://mobile-smtp.roadrunner.com" username="$email" />
|
||||
</provider>
|
||||
<provider id="rr-nycap" label="RoadRunner" domain="nycap.rr.com">
|
||||
<incoming uri="pop3://pop-server.nycap.rr.com" username="$email" />
|
||||
<outgoing uri="smtp://mobile-smtp.roadrunner.com" username="$email" />
|
||||
</provider>
|
||||
<provider id="rr-oh" label="RoadRunner" domain="oh.rr.com">
|
||||
<incoming uri="pop3://pop-server.oh.rr.com" username="$email" />
|
||||
<outgoing uri="smtp://mobile-smtp.roadrunner.com" username="$email" />
|
||||
</provider>
|
||||
<provider id="rr-pa" label="RoadRunner" domain="pa.rr.com">
|
||||
<incoming uri="pop3://pop-server.pa.rr.com" username="$email" />
|
||||
<outgoing uri="smtp://mobile-smtp.roadrunner.com" username="$email" />
|
||||
</provider>
|
||||
<provider id="rr-panhandle" label="RoadRunner" domain="panhandle.rr.com">
|
||||
<incoming uri="pop3://pop-server.panhandle.rr.com" username="$email" />
|
||||
<outgoing uri="smtp://mobile-smtp.roadrunner.com" username="$email" />
|
||||
</provider>
|
||||
<provider id="rr-rgv" label="RoadRunner" domain="rgv.rr.com">
|
||||
<incoming uri="pop3://pop-server.rgv.rr.com" username="$email" />
|
||||
<outgoing uri="smtp://mobile-smtp.roadrunner.com" username="$email" />
|
||||
</provider>
|
||||
<provider id="rr-rochester" label="RoadRunner" domain="rochester.rr.com">
|
||||
<incoming uri="pop3://pop-server.rochester.rr.com" username="$email" />
|
||||
<outgoing uri="smtp://mobile-smtp.roadrunner.com" username="$email" />
|
||||
</provider>
|
||||
<provider id="rr-san" label="RoadRunner" domain="san.rr.com">
|
||||
<incoming uri="pop3://pop-server.san.rr.com" username="$email" />
|
||||
<outgoing uri="smtp://mobile-smtp.roadrunner.com" username="$email" />
|
||||
</provider>
|
||||
<provider id="rr-satx" label="RoadRunner" domain="satx.rr.com">
|
||||
<incoming uri="pop3://pop-server.satx.rr.com" username="$email" />
|
||||
<outgoing uri="smtp://mobile-smtp.roadrunner.com" username="$email" />
|
||||
</provider>
|
||||
<provider id="rr-sc" label="RoadRunner" domain="sc.rr.com">
|
||||
<incoming uri="pop3://pop-server.sc.rr.com" username="$email" />
|
||||
<outgoing uri="smtp://mobile-smtp.roadrunner.com" username="$email" />
|
||||
</provider>
|
||||
<provider id="rr-si" label="RoadRunner" domain="si.rr.com">
|
||||
<incoming uri="pop3://pop-server.si.rr.com" username="$email" />
|
||||
<outgoing uri="smtp://mobile-smtp.roadrunner.com" username="$email" />
|
||||
</provider>
|
||||
<provider id="rr-socal" label="RoadRunner" domain="socal.rr.com">
|
||||
<incoming uri="pop3://pop-server.socal.rr.com" username="$email" />
|
||||
<outgoing uri="smtp://mobile-smtp.roadrunner.com" username="$email" />
|
||||
</provider>
|
||||
<provider id="rr-stny" label="RoadRunner" domain="stny.rr.com">
|
||||
<incoming uri="pop3://pop-server.stny.rr.com" username="$email" />
|
||||
<outgoing uri="smtp://mobile-smtp.roadrunner.com" username="$email" />
|
||||
</provider>
|
||||
<provider id="rr-stx" label="RoadRunner" domain="stx.rr.com">
|
||||
<incoming uri="pop3://pop-server.stx.rr.com" username="$email" />
|
||||
<outgoing uri="smtp://mobile-smtp.roadrunner.com" username="$email" />
|
||||
</provider>
|
||||
<provider id="rr-sw" label="RoadRunner" domain="sw.rr.com">
|
||||
<incoming uri="pop3://pop-server.sw.rr.com" username="$email" />
|
||||
<outgoing uri="smtp://mobile-smtp.roadrunner.com" username="$email" />
|
||||
</provider>
|
||||
<provider id="rr-tampabay" label="RoadRunner" domain="tampabay.rr.com">
|
||||
<incoming uri="pop3://pop-server.tampabay.rr.com" username="$email" />
|
||||
<outgoing uri="smtp://mobile-smtp.roadrunner.com" username="$email" />
|
||||
</provider>
|
||||
<provider id="rr-triad" label="RoadRunner" domain="triad.rr.com">
|
||||
<incoming uri="pop3://pop-server.triad.rr.com" username="$email" />
|
||||
<outgoing uri="smtp://mobile-smtp.roadrunner.com" username="$email" />
|
||||
</provider>
|
||||
<provider id="rr-twcny" label="RoadRunner" domain="twcny.rr.com">
|
||||
<incoming uri="pop3://pop-server.twcny.rr.com" username="$email" />
|
||||
<outgoing uri="smtp://mobile-smtp.roadrunner.com" username="$email" />
|
||||
</provider>
|
||||
<provider id="rr-twmi" label="RoadRunner" domain="twmi.rr.com">
|
||||
<incoming uri="pop3://pop-server.twmi.rr.com" username="$email" />
|
||||
<outgoing uri="smtp://mobile-smtp.roadrunner.com" username="$email" />
|
||||
</provider>
|
||||
<provider id="rr-tx" label="RoadRunner" domain="tx.rr.com">
|
||||
<incoming uri="pop3://pop-server.tx.rr.com" username="$email" />
|
||||
<outgoing uri="smtp://mobile-smtp.roadrunner.com" username="$email" />
|
||||
</provider>
|
||||
<provider id="rr-we" label="RoadRunner" domain="we.rr.com">
|
||||
<incoming uri="pop3://pop-server.we.rr.com" username="$email" />
|
||||
<outgoing uri="smtp://mobile-smtp.roadrunner.com" username="$email" />
|
||||
</provider>
|
||||
<provider id="rr-wi" label="RoadRunner" domain="wi.rr.com">
|
||||
<incoming uri="pop3://pop-server.wi.rr.com" username="$email" />
|
||||
<outgoing uri="smtp://mobile-smtp.roadrunner.com" username="$email" />
|
||||
</provider>
|
||||
<provider id="rr-woh" label="RoadRunner" domain="woh.rr.com">
|
||||
<incoming uri="pop3://pop-server.woh.rr.com" username="$email" />
|
||||
<provider id="rr-global" label="RoadRunner" domain="*.rr.com">
|
||||
<incoming uri="pop3://pop-server.$domain" username="$email" />
|
||||
<outgoing uri="smtp://mobile-smtp.roadrunner.com" username="$email" />
|
||||
</provider>
|
||||
|
||||
|
@ -31,7 +31,6 @@ import android.util.Log;
|
||||
import android.widget.EditText;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.net.URI;
|
||||
|
||||
public class AccountSettingsUtils {
|
||||
|
||||
@ -101,21 +100,29 @@ public class AccountSettingsUtils {
|
||||
* @param resourceId Id of the provider resource to scan
|
||||
* @return suitable Provider definition, or null if no match found
|
||||
*/
|
||||
private static Provider findProviderForDomain(Context context, String domain, int resourceId) {
|
||||
/*package*/ static Provider findProviderForDomain(
|
||||
Context context, String domain, int resourceId) {
|
||||
try {
|
||||
XmlResourceParser xml = context.getResources().getXml(resourceId);
|
||||
int xmlEventType;
|
||||
Provider provider = null;
|
||||
while ((xmlEventType = xml.next()) != XmlResourceParser.END_DOCUMENT) {
|
||||
if (xmlEventType == XmlResourceParser.START_TAG
|
||||
&& "provider".equals(xml.getName())
|
||||
&& domain.equalsIgnoreCase(getXmlAttribute(context, xml, "domain"))) {
|
||||
&& "provider".equals(xml.getName())) {
|
||||
String providerDomain = getXmlAttribute(context, xml, "domain");
|
||||
try {
|
||||
if (globMatchIgnoreCase(domain, providerDomain)) {
|
||||
provider = new Provider();
|
||||
provider.id = getXmlAttribute(context, xml, "id");
|
||||
provider.label = getXmlAttribute(context, xml, "label");
|
||||
provider.domain = getXmlAttribute(context, xml, "domain");
|
||||
provider.domain = domain.toLowerCase();
|
||||
provider.note = getXmlAttribute(context, xml, "note");
|
||||
}
|
||||
} catch (IllegalArgumentException e) {
|
||||
Log.w(Logging.LOG_TAG, "providers line: " + xml.getLineNumber() +
|
||||
"; Domain contains multiple globals");
|
||||
}
|
||||
}
|
||||
else if (xmlEventType == XmlResourceParser.START_TAG
|
||||
&& "incoming".equals(xml.getName())
|
||||
&& provider != null) {
|
||||
@ -141,6 +148,42 @@ public class AccountSettingsUtils {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares the two strings. glob may have at most a single global character ('*') that
|
||||
* will match any number of characters in the input string.
|
||||
* @return true if the strings match. otherwise, false.
|
||||
* @throws IllegalArgumentException if the strings are null or glob has multiple globals.
|
||||
*/
|
||||
/*package*/ static boolean globMatchIgnoreCase(String in, String glob)
|
||||
throws IllegalArgumentException {
|
||||
if (in == null || glob == null) {
|
||||
throw new IllegalArgumentException("one or both strings are null");
|
||||
}
|
||||
|
||||
// Handle the possible global in the domain name
|
||||
String[] globParts = glob.split("\\*");
|
||||
String inLower = in.toLowerCase();
|
||||
switch (globParts.length) {
|
||||
case 1:
|
||||
// No globals; test for simple equality
|
||||
if (!inLower.equals(globParts[0].toLowerCase())) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
// Global; test the front & end parts of the domain
|
||||
String d1 = globParts[0].toLowerCase();
|
||||
String d2 = globParts[1].toLowerCase();
|
||||
if (!inLower.startsWith(d1) || !inLower.substring(d1.length()).endsWith(d2)) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("Multiple globals");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to get the given attribute as a String resource first, and if it fails
|
||||
* returns the attribute as a simple String value.
|
||||
@ -168,7 +211,27 @@ public class AccountSettingsUtils {
|
||||
public String incomingUsernameTemplate;
|
||||
public String outgoingUriTemplate;
|
||||
public String outgoingUsernameTemplate;
|
||||
public String incomingUri;
|
||||
public String incomingUsername;
|
||||
public String outgoingUri;
|
||||
public String outgoingUsername;
|
||||
public String note;
|
||||
public void expandTemplates(String email) {
|
||||
String[] emailParts = email.split("@");
|
||||
String user = emailParts[0];
|
||||
|
||||
incomingUri = expandTemplate(incomingUriTemplate, email, user);
|
||||
incomingUsername = expandTemplate(incomingUsernameTemplate, email, user);
|
||||
outgoingUri = expandTemplate(outgoingUriTemplate, email, user);
|
||||
outgoingUsername = expandTemplate(outgoingUsernameTemplate, email, user);
|
||||
}
|
||||
private String expandTemplate(String template, String email, String user) {
|
||||
String returnString = template;
|
||||
returnString = returnString.replaceAll("\\$email", email);
|
||||
returnString = returnString.replaceAll("\\$user", user);
|
||||
returnString = returnString.replaceAll("\\$domain", domain);
|
||||
return returnString;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -418,36 +418,25 @@ public class AccountSetupBasics extends AccountSetupActivity
|
||||
private void finishAutoSetup() {
|
||||
String email = mEmailView.getText().toString().trim();
|
||||
String password = mPasswordView.getText().toString();
|
||||
String[] emailParts = email.split("@");
|
||||
String user = emailParts[0];
|
||||
String domain = emailParts[1];
|
||||
|
||||
try {
|
||||
String incomingUsername = mProvider.incomingUsernameTemplate;
|
||||
incomingUsername = incomingUsername.replaceAll("\\$email", email);
|
||||
incomingUsername = incomingUsername.replaceAll("\\$user", user);
|
||||
incomingUsername = incomingUsername.replaceAll("\\$domain", domain);
|
||||
mProvider.expandTemplates(email);
|
||||
|
||||
Account account = SetupData.getAccount();
|
||||
HostAuth recvAuth = account.getOrCreateHostAuthRecv(this);
|
||||
Utility.setHostAuthFromString(recvAuth, mProvider.incomingUriTemplate);
|
||||
recvAuth.setLogin(incomingUsername, password);
|
||||
|
||||
String outgoingUsername = mProvider.outgoingUsernameTemplate;
|
||||
outgoingUsername = outgoingUsername.replaceAll("\\$email", email);
|
||||
outgoingUsername = outgoingUsername.replaceAll("\\$user", user);
|
||||
outgoingUsername = outgoingUsername.replaceAll("\\$domain", domain);
|
||||
Utility.setHostAuthFromString(recvAuth, mProvider.incomingUri);
|
||||
recvAuth.setLogin(mProvider.incomingUsername, password);
|
||||
|
||||
HostAuth sendAuth = account.getOrCreateHostAuthSend(this);
|
||||
Utility.setHostAuthFromString(sendAuth, mProvider.outgoingUriTemplate);
|
||||
sendAuth.setLogin(outgoingUsername, password);
|
||||
Utility.setHostAuthFromString(sendAuth, mProvider.outgoingUri);
|
||||
sendAuth.setLogin(mProvider.outgoingUsername, password);
|
||||
|
||||
// Populate the setup data, assuming that the duplicate account check will succeed
|
||||
populateSetupData(getOwnerName(), email, mDefaultView.isChecked());
|
||||
|
||||
// Stop here if the login credentials duplicate an existing account
|
||||
// Launch an Async task to do the work
|
||||
new DuplicateCheckTask(this, recvAuth.mAddress, incomingUsername).execute();
|
||||
new DuplicateCheckTask(this, recvAuth.mAddress, mProvider.incomingUsername).execute();
|
||||
} catch (URISyntaxException e) {
|
||||
/*
|
||||
* If there is some problem with the URI we give up and go on to manual setup.
|
||||
|
64
tests/res/xml/test_providers.xml
Normal file
64
tests/res/xml/test_providers.xml
Normal file
@ -0,0 +1,64 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2011 The Android Open Source Project
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<!--
|
||||
This file contains email provider configuration for testing purposes. The complete
|
||||
format specification for this file can be found in res/xml/providers.xml.
|
||||
-->
|
||||
|
||||
<providers>
|
||||
|
||||
<!-- Gmail variants -->
|
||||
<provider id="gmail" label="Gmail" domain="gmail.com">
|
||||
<incoming uri="imap+ssl+://imap.gmail.com" username="$email" />
|
||||
<outgoing uri="smtp+ssl+://smtp.gmail.com" username="$email" />
|
||||
</provider>
|
||||
|
||||
<!-- Yahoo! Mail variants -->
|
||||
<provider id="generic" label="Generic Y!" domain="mail*yahoo.com">
|
||||
<incoming uri="pop3://pop-server.$domain" username="$email" />
|
||||
<outgoing uri="smtp://smtp-server.foo.com" username="$email" />
|
||||
</provider>
|
||||
<provider id="yahoo" label="Yahoo!" domain="yahoo.com">
|
||||
<incoming uri="imap+ssl+://android.imap.mail.yahoo.com" username="$email" />
|
||||
<outgoing uri="smtp+ssl+://android.smtp.mail.yahoo.com" username="$email" />
|
||||
</provider>
|
||||
<provider id="yahoo" label="Yahoo!" domain="yahoo.com.yahoo.com">
|
||||
<incoming uri="imap+ssl+://android.imap.mail.yahoo.com" username="$email" />
|
||||
<outgoing uri="smtp+ssl+://android.smtp.mail.yahoo.com" username="$email" />
|
||||
</provider>
|
||||
|
||||
<!-- Roadrunner variants -->
|
||||
<provider id="rr-roadrunner" label="RoadRunner" domain="roadrunner.com">
|
||||
<incoming uri="pop3://pop-server.roadrunner.com" username="$email" />
|
||||
<outgoing uri="smtp://mobile-smtp.roadrunner.com" username="$email" />
|
||||
</provider>
|
||||
<provider id="rr-global" label="RoadRunner" domain="leonard.rr.com">
|
||||
<incoming uri="pop3://pop-server.firstonewins.com" username="$email" />
|
||||
<outgoing uri="smtp://mobile-smtp.roadrunner.com" username="$email" />
|
||||
</provider>
|
||||
<provider id="rr-global" label="RoadRunner" domain="*.rr.com">
|
||||
<incoming uri="pop3://pop-server.$domain" username="$email" />
|
||||
<outgoing uri="smtp://mobile-smtp.roadrunner.com" username="$email" />
|
||||
</provider>
|
||||
|
||||
<!-- USA (other)-->
|
||||
<provider id="tuffmail" label="Tuffmail" domain="tuffmail.com">
|
||||
<incoming uri="imap+ssl+://mail.mxes.net" username="$user_$domain" />
|
||||
<outgoing uri="smtp+ssl+://smtp.mxes.net" username="$user_$domain" />
|
||||
</provider>
|
||||
|
||||
</providers>
|
@ -16,6 +16,10 @@
|
||||
|
||||
package com.android.email.activity.setup;
|
||||
|
||||
import com.android.email.tests.R;
|
||||
import com.android.email.activity.setup.AccountSettingsUtils.Provider;
|
||||
|
||||
import android.content.Context;
|
||||
import android.test.AndroidTestCase;
|
||||
import android.test.suitebuilder.annotation.SmallTest;
|
||||
|
||||
@ -28,6 +32,14 @@ import android.test.suitebuilder.annotation.SmallTest;
|
||||
@SmallTest
|
||||
public class AccountSettingsUtilsTests extends AndroidTestCase {
|
||||
|
||||
private Context mTestContext;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
mTestContext = getTestContext();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test server name inferences
|
||||
*
|
||||
@ -51,4 +63,154 @@ public class AccountSettingsUtilsTests extends AndroidTestCase {
|
||||
assertEquals("MaiL.y.z", AccountSettingsUtils.inferServerName("MaiL.y.z", null, "bar"));
|
||||
}
|
||||
|
||||
public void testFindProviderForDomain() {
|
||||
Provider testProvider;
|
||||
// <provider id="gmail" label="Gmail" domain="gmail.com">
|
||||
// <incoming uri="imap+ssl+://imap.gmail.com" username="$email" />
|
||||
// <outgoing uri="smtp+ssl+://smtp.gmail.com" username="$email" />
|
||||
// </provider>
|
||||
testProvider = AccountSettingsUtils.findProviderForDomain(
|
||||
mTestContext, "gmail.com", R.xml.test_providers);
|
||||
assertNotNull(testProvider);
|
||||
assertEquals("imap+ssl+://imap.gmail.com", testProvider.incomingUriTemplate);
|
||||
assertEquals("smtp+ssl+://smtp.gmail.com", testProvider.outgoingUriTemplate);
|
||||
assertEquals("gmail.com", testProvider.domain);
|
||||
|
||||
// <provider id="rr-generic" label="RoadRunner" domain="*.rr.com">
|
||||
// <incoming uri="pop3://pop-server.$domain" username="$email" />
|
||||
// <outgoing uri="smtp://mobile-smtp.roadrunner.com" username="$email" />
|
||||
// </provider>
|
||||
testProvider = AccountSettingsUtils.findProviderForDomain(
|
||||
mTestContext, "elmore.rr.com", R.xml.test_providers);
|
||||
assertNotNull(testProvider);
|
||||
assertEquals("pop3://pop-server.$domain", testProvider.incomingUriTemplate);
|
||||
assertEquals("smtp://mobile-smtp.roadrunner.com", testProvider.outgoingUriTemplate);
|
||||
assertEquals("elmore.rr.com", testProvider.domain);
|
||||
|
||||
// Domain matches 2 providers; first one wins
|
||||
testProvider = AccountSettingsUtils.findProviderForDomain(
|
||||
mTestContext, "leonard.rr.com", R.xml.test_providers);
|
||||
assertNotNull(testProvider);
|
||||
assertEquals("pop3://pop-server.firstonewins.com", testProvider.incomingUriTemplate);
|
||||
|
||||
// Domains that don't exist
|
||||
testProvider = AccountSettingsUtils.findProviderForDomain(
|
||||
mTestContext, "nonexist.com", R.xml.test_providers);
|
||||
assertNull(testProvider);
|
||||
}
|
||||
|
||||
public void testGlobMatchIgnoreCase() {
|
||||
boolean testMatch;
|
||||
|
||||
assertTrue(AccountSettingsUtils.globMatchIgnoreCase(
|
||||
"mail.yahoo.com", "mail*yahoo.com"));
|
||||
assertTrue(AccountSettingsUtils.globMatchIgnoreCase(
|
||||
"mail.foo.bar.yahoo.com", "mail*yahoo.com"));
|
||||
assertTrue(AccountSettingsUtils.globMatchIgnoreCase(
|
||||
"mail.notwhatyouwant.myyahoo.com", "mail*yahoo.com"));
|
||||
|
||||
// Test other combinations
|
||||
assertTrue(AccountSettingsUtils.globMatchIgnoreCase(
|
||||
"yahoo.com", "yahoo.com"));
|
||||
assertFalse(AccountSettingsUtils.globMatchIgnoreCase(
|
||||
"yahoo.com.au", "yahoo.com"));
|
||||
assertFalse(AccountSettingsUtils.globMatchIgnoreCase(
|
||||
"yahoo.com", "yahoo.com.au"));
|
||||
|
||||
// Try mixed case in the domain name
|
||||
assertTrue(AccountSettingsUtils.globMatchIgnoreCase(
|
||||
"GmAiL.cOm", "gMaIl.CoM"));
|
||||
|
||||
assertFalse(AccountSettingsUtils.globMatchIgnoreCase(
|
||||
"nonexist.frr.com", "*.rr.com"));
|
||||
assertFalse(AccountSettingsUtils.globMatchIgnoreCase(
|
||||
"rr.com", "*.rr.com"));
|
||||
assertTrue(AccountSettingsUtils.globMatchIgnoreCase(
|
||||
"abbc.com", "ab*bc.com"));
|
||||
assertFalse(AccountSettingsUtils.globMatchIgnoreCase(
|
||||
"abc.com", "ab*bc.com"));
|
||||
|
||||
try {
|
||||
AccountSettingsUtils.globMatchIgnoreCase(
|
||||
"abc.com", "ab*bc*.com");
|
||||
fail("Should have thrown an IllegalArgumentException");
|
||||
} catch (IllegalArgumentException e) {
|
||||
}
|
||||
try {
|
||||
AccountSettingsUtils.globMatchIgnoreCase(
|
||||
null, "ab*bc*.com");
|
||||
fail("Should have thrown an IllegalArgumentException");
|
||||
} catch (IllegalArgumentException e) {
|
||||
}
|
||||
try {
|
||||
AccountSettingsUtils.globMatchIgnoreCase(
|
||||
"abc.com", null);
|
||||
fail("Should have thrown an IllegalArgumentException");
|
||||
} catch (IllegalArgumentException e) {
|
||||
}
|
||||
}
|
||||
|
||||
public void testExpandTemplates() {
|
||||
Provider testProvider;
|
||||
// <provider id="cox" label="Cox" domain="cox.net">
|
||||
// <incoming uri="pop3+ssl+://pop.east.cox.net" username="$user" />
|
||||
// <outgoing uri="smtp+ssl+://smtp.east.cox.net" username="$user" />
|
||||
// </provider>
|
||||
testProvider = new Provider();
|
||||
testProvider.domain = "cox.net";
|
||||
testProvider.incomingUriTemplate = "pop3+ssl+://pop.east.$domain";
|
||||
testProvider.outgoingUriTemplate = "smtp+ssl+://smtp.east.$domain";
|
||||
testProvider.incomingUsernameTemplate = "$user";
|
||||
testProvider.outgoingUsernameTemplate = "$user";
|
||||
testProvider.expandTemplates("replUser@cox.net");
|
||||
assertEquals("replUser", testProvider.incomingUsername);
|
||||
assertEquals("replUser", testProvider.outgoingUsername);
|
||||
assertEquals("pop3+ssl+://pop.east.cox.net", testProvider.incomingUri);
|
||||
assertEquals("smtp+ssl+://smtp.east.cox.net", testProvider.outgoingUri);
|
||||
|
||||
// <provider id="earthlink" label="Earthlink" domain="earthlink.net">
|
||||
// <incoming uri="pop3://pop.earthlink.net" username="$email" />
|
||||
// <outgoing uri="smtp://smtpauth.earthlink.net:587" username="$email" />
|
||||
// </provider>
|
||||
testProvider = new Provider();
|
||||
testProvider.domain = "earthlink.net";
|
||||
testProvider.incomingUriTemplate = "pop3://pop.earthlink.net";
|
||||
testProvider.outgoingUriTemplate = "smtp://smtpauth.earthlink.net:587";
|
||||
testProvider.incomingUsernameTemplate = "$email";
|
||||
testProvider.outgoingUsernameTemplate = "$email";
|
||||
testProvider.expandTemplates("replUser@earthlink.net");
|
||||
assertEquals("replUser@earthlink.net", testProvider.incomingUsername);
|
||||
assertEquals("replUser@earthlink.net", testProvider.outgoingUsername);
|
||||
assertEquals("pop3://pop.earthlink.net", testProvider.incomingUri);
|
||||
assertEquals("smtp://smtpauth.earthlink.net:587", testProvider.outgoingUri);
|
||||
|
||||
// <provider id="tuffmail" label="Tuffmail" domain="tuffmail.com">
|
||||
// <incoming uri="imap+ssl+://mail.mxes.net" username="$user_$domain" />
|
||||
// <outgoing uri="smtp+ssl+://smtp.mxes.net" username="$user_$domain" />
|
||||
// </provider>
|
||||
testProvider = new Provider();
|
||||
testProvider.domain = "tuffmail.com";
|
||||
testProvider.incomingUriTemplate = "imap+ssl+://mail.mxes.net";
|
||||
testProvider.outgoingUriTemplate = "smtp+ssl+://smtp.mxes.net";
|
||||
testProvider.incomingUsernameTemplate = "$user_$domain";
|
||||
testProvider.outgoingUsernameTemplate = "$user_$domain";
|
||||
testProvider.expandTemplates("replUser@tuffmail.com");
|
||||
assertEquals("replUser_tuffmail.com", testProvider.incomingUsername);
|
||||
assertEquals("replUser_tuffmail.com", testProvider.outgoingUsername);
|
||||
assertEquals("imap+ssl+://mail.mxes.net", testProvider.incomingUri);
|
||||
assertEquals("smtp+ssl+://smtp.mxes.net", testProvider.outgoingUri);
|
||||
|
||||
// Everything hardcoded; not effective in the wild
|
||||
testProvider = new Provider();
|
||||
testProvider.domain = "yahoo.com";
|
||||
testProvider.incomingUriTemplate = "imap+ssl+://pop.yahoo.com";
|
||||
testProvider.outgoingUriTemplate = "smtp+ssl+://smtp.yahoo.com";
|
||||
testProvider.incomingUsernameTemplate = "joe_smith";
|
||||
testProvider.outgoingUsernameTemplate = "joe_smith";
|
||||
testProvider.expandTemplates("replUser@yahoo.com");
|
||||
assertEquals("joe_smith", testProvider.incomingUsername);
|
||||
assertEquals("joe_smith", testProvider.outgoingUsername);
|
||||
assertEquals("imap+ssl+://pop.yahoo.com", testProvider.incomingUri);
|
||||
assertEquals("smtp+ssl+://smtp.yahoo.com", testProvider.outgoingUri);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user