1
0
mirror of https://github.com/moparisthebest/k-9 synced 2025-01-07 11:48:07 -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_fetch">Fetching account settings\u2026</string>
<string name="account_setup_check_settings_canceling_msg">Canceling\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_incoming_title">Confirm incoming server settings</string>
<string name="account_setup_confirm_outgoing_title">Confirm outgoing 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> <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_processing">Parsing and processing the retrieved settings&#8230;</string>
<string name="account_setup_autoconfig_found">found!</string> <string name="account_setup_autoconfig_found">found!</string>
<string name="account_setup_autoconfig_missing">not 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_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_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_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_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_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_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_title">You\'re almost done!</string>
<string name="account_setup_names_instructions">Your account is set up, and mail is on its way!</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.activity.K9Activity;
import com.fsck.k9.helper.configxmlparser.AutoconfigInfo; import com.fsck.k9.helper.configxmlparser.AutoconfigInfo;
import com.fsck.k9.helper.configxmlparser.ConfigurationXMLHandler; import com.fsck.k9.helper.configxmlparser.ConfigurationXMLHandler;
import com.fsck.k9.mail.store.TrustManagerFactory;
import org.apache.http.HttpResponse; import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient; 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 Checks if an url is available / exists
*/ */
private String getXMLData(URL url) throws IOException, ErrorCodeException, SocketTimeoutException, FileNotFoundException { 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 // 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(); HttpURLConnection conn = (HttpURLConnection)url.openConnection();
conn.setInstanceFollowRedirects(false); conn.setInstanceFollowRedirects(true);
// prepare request // prepare request
conn.setConnectTimeout(TIMEOUT); conn.setConnectTimeout(TIMEOUT);
// get the data // get the data
String tmp, line; StringBuilder response = new StringBuilder();
tmp = "";
BufferedReader reader = null; BufferedReader reader = null;
try { try {
reader = new BufferedReader(new InputStreamReader( reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
conn.getInputStream())); String line;
while ((line = reader.readLine()) != null) while ((line = reader.readLine()) != null) {
tmp += line; response.append(line);
}
if (conn.getResponseCode() != 200) if (conn.getResponseCode() != 200) {
throw new ErrorCodeException( throw new ErrorCodeException(
"Server did not return as expected.", "Server did not return as expected.",
conn.getResponseCode()); conn.getResponseCode());
} catch (SocketTimeoutException ex) { }
throw ex; } catch (ConnectException ex) {
} catch (FileNotFoundException e){ // ignore this, it just means the url doesn't exist which happens
throw e; // often, we test for it!
}catch (ConnectException ex) { } finally {
// ignore this, it just means the url doesn't exist which happens if (reader != null) {
// often, we test for it! reader.close();
} finally { }
if (reader != null) if (conn.getInputStream() != null) {
reader.close(); conn.getInputStream().close();
conn.disconnect(); }
} conn.disconnect();
}
return tmp; return response.toString();
} }
@ -492,7 +491,7 @@ public class AccountSetupAutoConfiguration extends K9Activity implements View.On
// parse and finish // parse and finish
setMessage(R.string.account_setup_autoconfig_processing,true); setMessage(R.string.account_setup_autoconfig_processing,true);
parse(data); 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 ) // alert user these settings might be tampered with!!! ( no https )
if( templateIndex >= UNSAFE_URL_START ) bUnsafe = true; if( templateIndex >= UNSAFE_URL_START ) bUnsafe = true;
@ -584,7 +583,7 @@ public class AccountSetupAutoConfiguration extends K9Activity implements View.On
// 1. All good, continue // 1. All good, continue
if( !bForceManual ){ if( !bForceManual ){
mStatusTitle.setText(R.string.account_setup_autoconfig_succesful_attempt); mStatusTitle.setText(R.string.account_setup_autoconfig_success);
mDoneMark.setVisibility(View.VISIBLE); mDoneMark.setVisibility(View.VISIBLE);
// 2. Nothing came up, must manually config.. + help? // 2. Nothing came up, must manually config.. + help?
}else{ }else{