1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-08-13 17:03:48 -04:00

Fixes Issue 722

This commit is contained in:
Daniel Applebaum 2009-11-07 20:16:15 +00:00
parent 90198382a4
commit 0baf9d6134

View File

@ -13,6 +13,8 @@ import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.security.GeneralSecurityException; import java.security.GeneralSecurityException;
import java.security.SecureRandom; import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.List;
import javax.net.ssl.SSLContext; import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager; import javax.net.ssl.TrustManager;
@ -153,14 +155,12 @@ public class SmtpTransport extends Transport {
localHost = localAddress.getHostName(); localHost = localAddress.getHostName();
} }
} catch (Exception e) { } catch (Exception e) {
if (Config.LOGD) { if (Email.DEBUG) {
if (Email.DEBUG) { Log.d(Email.LOG_TAG, "Unable to look up localhost");
Log.d(Email.LOG_TAG, "Unable to look up localhost");
}
} }
} }
String result = executeSimpleCommand("EHLO " + localHost); List<String> results = executeSimpleCommand("EHLO " + localHost);
/* /*
* TODO may need to add code to fall back to HELO I switched it from * TODO may need to add code to fall back to HELO I switched it from
@ -172,7 +172,7 @@ public class SmtpTransport extends Transport {
*/ */
if (mConnectionSecurity == CONNECTION_SECURITY_TLS_OPTIONAL if (mConnectionSecurity == CONNECTION_SECURITY_TLS_OPTIONAL
|| mConnectionSecurity == CONNECTION_SECURITY_TLS_REQUIRED) { || mConnectionSecurity == CONNECTION_SECURITY_TLS_REQUIRED) {
if (result.contains("-STARTTLS")) { if (results.contains("STARTTLS")) {
executeSimpleCommand("STARTTLS"); executeSimpleCommand("STARTTLS");
SSLContext sslContext = SSLContext.getInstance("TLS"); SSLContext sslContext = SSLContext.getInstance("TLS");
@ -190,7 +190,7 @@ public class SmtpTransport extends Transport {
* Now resend the EHLO. Required by RFC2487 Sec. 5.2, and more specifically, * Now resend the EHLO. Required by RFC2487 Sec. 5.2, and more specifically,
* Exim. * Exim.
*/ */
result = executeSimpleCommand("EHLO " + localHost); results = executeSimpleCommand("EHLO " + localHost);
} else if (mConnectionSecurity == CONNECTION_SECURITY_TLS_REQUIRED) { } else if (mConnectionSecurity == CONNECTION_SECURITY_TLS_REQUIRED) {
throw new MessagingException("TLS not supported but required"); throw new MessagingException("TLS not supported but required");
} }
@ -199,8 +199,19 @@ public class SmtpTransport extends Transport {
/* /*
* result contains the results of the EHLO in concatenated form * result contains the results of the EHLO in concatenated form
*/ */
boolean authLoginSupported = result.matches(".*AUTH.*LOGIN.*$"); boolean authLoginSupported = false;
boolean authPlainSupported = result.matches(".*AUTH.*PLAIN.*$"); boolean authPlainSupported = false;
for (String result : results)
{
if (result.matches(".*AUTH.*LOGIN.*$") == true)
{
authLoginSupported = true;
}
if (result.matches(".*AUTH.*PLAIN.*$") == true)
{
authPlainSupported = true;
}
}
if (mUsername != null && mUsername.length() > 0 && mPassword != null if (mUsername != null && mUsername.length() > 0 && mPassword != null
&& mPassword.length() > 0) { && mPassword.length() > 0) {
@ -297,19 +308,16 @@ public class SmtpTransport extends Transport {
} }
} }
String ret = sb.toString(); String ret = sb.toString();
if (true || Config.LOGD) { if (Email.DEBUG) {
if (Email.DEBUG) { Log.d(Email.LOG_TAG, "SMTP <<< " + ret);
Log.d(Email.LOG_TAG, "<<< " + ret);
}
} }
return ret; return ret;
} }
private void writeLine(String s) throws IOException { private void writeLine(String s) throws IOException {
if (true || Config.LOGD) { if (Email.DEBUG) {
if (Email.DEBUG) { Log.d(Email.LOG_TAG, "SMTP >>> " + s);
Log.d(Email.LOG_TAG, ">>> " + s);
}
} }
mOut.write(s.getBytes()); mOut.write(s.getBytes());
mOut.write('\r'); mOut.write('\r');
@ -329,22 +337,32 @@ public class SmtpTransport extends Transport {
} }
} }
private String executeSimpleCommand(String command) throws IOException, MessagingException { private List<String> executeSimpleCommand(String command) throws IOException, MessagingException {
List<String> results = new ArrayList<String>();
if (command != null) { if (command != null) {
writeLine(command); writeLine(command);
} }
String line = readLine(); boolean cont = false;
checkLine(line); do
{
String result = line; String line = readLine();
while (line.length() >= 4 && line.charAt(3) == '-') {
line = readLine();
checkLine(line); checkLine(line);
result += line.substring(3); if (line.length() > 4)
} {
return result; results.add(line.substring(4));
if (line.charAt(3) == '-')
{
cont = true;
}
else
{
cont = false;
}
}
} while (cont);
return results;
} }