1
0
mirror of https://github.com/moparisthebest/k-9 synced 2025-01-05 18:58:10 -05:00

Follow redirects during autoconfig (since Mozilla is issuing redirects now), cleanup our sockets, and fix some strings.

This commit is contained in:
Andrew Chen 2012-08-09 23:35:37 -07:00
parent d84a2d158c
commit b1d4bc39f8
2 changed files with 29 additions and 31 deletions

View File

@ -368,7 +368,7 @@ http://k9mail.googlecode.com/
<string name="account_setup_check_settings_fetch">Fetching account settings\u2026</string>
<string name="account_setup_check_settings_canceling_msg">Canceling\u2026</string>
<string name="account_setup_autoconfig_title">Autoconfiguration attempt</string>
<string name="account_setup_autoconfig_title">Account autoconfiguration</string>
<string name="account_setup_confirm_incoming_title">Confirm incoming server settings</string>
<string name="account_setup_confirm_outgoing_title">Confirm outgoing server settings</string>
<string name="account_setup_autoconfig_info">Attempting to configure your account&#8230;</string>
@ -380,14 +380,13 @@ http://k9mail.googlecode.com/
<string name="account_setup_autoconfig_processing">Parsing and processing the retrieved settings&#8230;</string>
<string name="account_setup_autoconfig_found">found!</string>
<string name="account_setup_autoconfig_missing">not found!</string>
<string name="account_setup_autoconfig_succesful">successful!</string>
<string name="account_setup_autoconfig_fail">failed!</string>
<string name="account_setup_autoconfig_forcemanual">Autoconfiguration was not possible, please use manual configuration to continue.</string>
<string name="account_setup_autoconfig_trynext">Searching other places for configuration settings&#8230;</string>
<string name="account_setup_autoconfig_trydns">Checking for DNS redirects&#8230;</string>
<string name="account_setup_autoconfig_new_domain">Retrying autoconfiguration for a new domain.</string>
<string name="account_setup_autoconfig_trying">Attempting to configure your account&#8230;</string>
<string name="account_setup_autoconfig_succesful_attempt">Succesfuly configured your account!</string>
<string name="account_setup_autoconfig_success">Successfully configured your account!</string>
<string name="account_setup_names_title">You\'re almost done!</string>
<string name="account_setup_names_instructions">Your account is set up, and mail is on its way!</string>

View File

@ -14,7 +14,6 @@ import com.fsck.k9.R;
import com.fsck.k9.activity.K9Activity;
import com.fsck.k9.helper.configxmlparser.AutoconfigInfo;
import com.fsck.k9.helper.configxmlparser.ConfigurationXMLHandler;
import com.fsck.k9.mail.store.TrustManagerFactory;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
@ -171,43 +170,43 @@ public class AccountSetupAutoConfiguration extends K9Activity implements View.On
Checks if an url is available / exists
*/
private String getXMLData(URL url) throws IOException, ErrorCodeException, SocketTimeoutException, FileNotFoundException {
// think we should assume no redirects
// TODO: use k9's own TrustManager so the right exception gets throwed and the user can choose to accept the certificate
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
conn.setInstanceFollowRedirects(false);
conn.setInstanceFollowRedirects(true);
// prepare request
conn.setConnectTimeout(TIMEOUT);
// get the data
String tmp, line;
tmp = "";
StringBuilder response = new StringBuilder();
BufferedReader reader = null;
try {
reader = new BufferedReader(new InputStreamReader(
conn.getInputStream()));
while ((line = reader.readLine()) != null)
tmp += line;
reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
response.append(line);
}
if (conn.getResponseCode() != 200)
throw new ErrorCodeException(
"Server did not return as expected.",
conn.getResponseCode());
} catch (SocketTimeoutException ex) {
throw ex;
} catch (FileNotFoundException e){
throw e;
}catch (ConnectException ex) {
// ignore this, it just means the url doesn't exist which happens
// often, we test for it!
} finally {
if (reader != null)
reader.close();
conn.disconnect();
}
if (conn.getResponseCode() != 200) {
throw new ErrorCodeException(
"Server did not return as expected.",
conn.getResponseCode());
}
} catch (ConnectException ex) {
// ignore this, it just means the url doesn't exist which happens
// often, we test for it!
} finally {
if (reader != null) {
reader.close();
}
if (conn.getInputStream() != null) {
conn.getInputStream().close();
}
conn.disconnect();
}
return tmp;
return response.toString();
}
@ -492,7 +491,7 @@ public class AccountSetupAutoConfiguration extends K9Activity implements View.On
// parse and finish
setMessage(R.string.account_setup_autoconfig_processing,true);
parse(data);
setMessage(R.string.account_setup_autoconfig_succesful,false);
setMessage(R.string.account_setup_autoconfig_success,false);
// alert user these settings might be tampered with!!! ( no https )
if( templateIndex >= UNSAFE_URL_START ) bUnsafe = true;
@ -584,7 +583,7 @@ public class AccountSetupAutoConfiguration extends K9Activity implements View.On
// 1. All good, continue
if( !bForceManual ){
mStatusTitle.setText(R.string.account_setup_autoconfig_succesful_attempt);
mStatusTitle.setText(R.string.account_setup_autoconfig_success);
mDoneMark.setVisibility(View.VISIBLE);
// 2. Nothing came up, must manually config.. + help?
}else{