DO NOT MERGE Send local IP address with EHLO instead of "localhost".
Bug 1515345 Backport of: I181c9f0d79fbdf62f7df77f72a1ec9653797b6dd Change-Id: If9da2d9f717814bff6a3aa7e6f1a0a44a49f34d6
This commit is contained in:
parent
d711bab919
commit
be2ef97220
|
@ -19,6 +19,7 @@ package com.android.email.mail;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
import java.net.InetAddress;
|
||||||
import java.net.SocketException;
|
import java.net.SocketException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
|
||||||
|
@ -159,4 +160,9 @@ public interface Transport {
|
||||||
*/
|
*/
|
||||||
String readLine() throws IOException;
|
String readLine() throws IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return The local address. If we have an open socket, get the local address from this.
|
||||||
|
* Otherwise simply use {@link InetAddress#getLocalHost}.
|
||||||
|
*/
|
||||||
|
InetAddress getLocalAddress() throws IOException;
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,7 @@ import java.io.BufferedOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
import java.net.InetAddress;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.net.SocketAddress;
|
import java.net.SocketAddress;
|
||||||
|
@ -342,5 +343,11 @@ public class MailTransport implements Transport {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public InetAddress getLocalAddress() {
|
||||||
|
if (isOpen()) {
|
||||||
|
return mSocket.getLocalAddress();
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -120,15 +120,11 @@ public class SmtpSender extends Sender {
|
||||||
executeSimpleCommand(null);
|
executeSimpleCommand(null);
|
||||||
|
|
||||||
String localHost = "localhost";
|
String localHost = "localhost";
|
||||||
try {
|
// Try to get local address in the X.X.X.X format.
|
||||||
InetAddress localAddress = InetAddress.getLocalHost();
|
InetAddress localAddress = mTransport.getLocalAddress();
|
||||||
localHost = localAddress.getHostName();
|
if (localAddress != null) {
|
||||||
} catch (Exception e) {
|
localHost = localAddress.getHostAddress();
|
||||||
if (Config.LOGD && Email.DEBUG) {
|
|
||||||
Log.d(Email.LOG_TAG, "Unable to look up localhost");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String result = executeSimpleCommand("EHLO " + localHost);
|
String result = executeSimpleCommand("EHLO " + localHost);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -23,6 +23,7 @@ import android.util.Log;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
import java.net.InetAddress;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
@ -49,9 +50,10 @@ public class MockTransport implements Transport {
|
||||||
private int mConnectionSecurity;
|
private int mConnectionSecurity;
|
||||||
private boolean mTrustCertificates;
|
private boolean mTrustCertificates;
|
||||||
private String mHost;
|
private String mHost;
|
||||||
|
private InetAddress mLocalAddress;
|
||||||
|
|
||||||
private ArrayList<String> mQueuedInput = new ArrayList<String>();
|
private ArrayList<String> mQueuedInput = new ArrayList<String>();
|
||||||
|
|
||||||
private static class Transaction {
|
private static class Transaction {
|
||||||
public static final int ACTION_INJECT_TEXT = 0;
|
public static final int ACTION_INJECT_TEXT = 0;
|
||||||
public static final int ACTION_SERVER_CLOSE = 1;
|
public static final int ACTION_SERVER_CLOSE = 1;
|
||||||
|
@ -186,6 +188,10 @@ public class MockTransport implements Transport {
|
||||||
return mHost;
|
return mHost;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setMockLocalAddress(InetAddress address) {
|
||||||
|
mLocalAddress = address;
|
||||||
|
}
|
||||||
|
|
||||||
public InputStream getInputStream() {
|
public InputStream getInputStream() {
|
||||||
SmtpSenderUnitTests.assertTrue(mOpen);
|
SmtpSenderUnitTests.assertTrue(mOpen);
|
||||||
return new MockInputStream();
|
return new MockInputStream();
|
||||||
|
@ -360,4 +366,12 @@ public class MockTransport implements Transport {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public InetAddress getLocalAddress() {
|
||||||
|
if (isOpen()) {
|
||||||
|
return mLocalAddress;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -36,6 +36,9 @@ import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
import java.net.InetAddress;
|
||||||
|
import java.net.UnknownHostException;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is a series of unit tests for the SMTP Sender class. These tests must be locally
|
* This is a series of unit tests for the SMTP Sender class. These tests must be locally
|
||||||
|
@ -50,6 +53,7 @@ public class SmtpSenderUnitTests extends ProviderTestCase2<EmailProvider> {
|
||||||
EmailProvider mProvider;
|
EmailProvider mProvider;
|
||||||
Context mProviderContext;
|
Context mProviderContext;
|
||||||
Context mContext;
|
Context mContext;
|
||||||
|
private static final String LOCAL_ADDRESS = "1.2.3.4";
|
||||||
|
|
||||||
/* These values are provided by setUp() */
|
/* These values are provided by setUp() */
|
||||||
private SmtpSender mSender = null;
|
private SmtpSender mSender = null;
|
||||||
|
@ -79,7 +83,7 @@ public class SmtpSenderUnitTests extends ProviderTestCase2<EmailProvider> {
|
||||||
/**
|
/**
|
||||||
* Confirms simple non-SSL non-TLS login
|
* Confirms simple non-SSL non-TLS login
|
||||||
*/
|
*/
|
||||||
public void testSimpleLogin() throws MessagingException {
|
public void testSimpleLogin() throws Exception {
|
||||||
|
|
||||||
MockTransport mockTransport = openAndInjectMockTransport();
|
MockTransport mockTransport = openAndInjectMockTransport();
|
||||||
|
|
||||||
|
@ -100,7 +104,7 @@ public class SmtpSenderUnitTests extends ProviderTestCase2<EmailProvider> {
|
||||||
/**
|
/**
|
||||||
* Test: Open and send a single message (sunny day)
|
* Test: Open and send a single message (sunny day)
|
||||||
*/
|
*/
|
||||||
public void testSendMessageWithBody() throws MessagingException {
|
public void testSendMessageWithBody() throws Exception {
|
||||||
MockTransport mockTransport = openAndInjectMockTransport();
|
MockTransport mockTransport = openAndInjectMockTransport();
|
||||||
|
|
||||||
// Since SmtpSender.sendMessage() does a close then open, we need to preset for the open
|
// Since SmtpSender.sendMessage() does a close then open, we need to preset for the open
|
||||||
|
@ -341,7 +345,7 @@ public class SmtpSenderUnitTests extends ProviderTestCase2<EmailProvider> {
|
||||||
/**
|
/**
|
||||||
* Test: Recover from a server closing early (or returning an empty string)
|
* Test: Recover from a server closing early (or returning an empty string)
|
||||||
*/
|
*/
|
||||||
public void testEmptyLineResponse() {
|
public void testEmptyLineResponse() throws Exception {
|
||||||
MockTransport mockTransport = openAndInjectMockTransport();
|
MockTransport mockTransport = openAndInjectMockTransport();
|
||||||
|
|
||||||
// Since SmtpSender.sendMessage() does a close then open, we need to preset for the open
|
// Since SmtpSender.sendMessage() does a close then open, we need to preset for the open
|
||||||
|
@ -349,7 +353,7 @@ public class SmtpSenderUnitTests extends ProviderTestCase2<EmailProvider> {
|
||||||
|
|
||||||
// Load up just the bare minimum to expose the error
|
// Load up just the bare minimum to expose the error
|
||||||
mockTransport.expect(null, "220 MockTransport 2000 Ready To Assist You Peewee");
|
mockTransport.expect(null, "220 MockTransport 2000 Ready To Assist You Peewee");
|
||||||
mockTransport.expect("EHLO .*", "");
|
mockTransport.expect("EHLO " + Pattern.quote(LOCAL_ADDRESS), "");
|
||||||
|
|
||||||
// Now trigger the transmission
|
// Now trigger the transmission
|
||||||
// Note, a null message is sufficient here, as we won't even get past open()
|
// Note, a null message is sufficient here, as we won't even get past open()
|
||||||
|
@ -365,11 +369,12 @@ public class SmtpSenderUnitTests extends ProviderTestCase2<EmailProvider> {
|
||||||
/**
|
/**
|
||||||
* Set up a basic MockTransport. open it, and inject it into mStore
|
* Set up a basic MockTransport. open it, and inject it into mStore
|
||||||
*/
|
*/
|
||||||
private MockTransport openAndInjectMockTransport() {
|
private MockTransport openAndInjectMockTransport() throws UnknownHostException {
|
||||||
// Create mock transport and inject it into the SmtpSender that's already set up
|
// Create mock transport and inject it into the SmtpSender that's already set up
|
||||||
MockTransport mockTransport = new MockTransport();
|
MockTransport mockTransport = new MockTransport();
|
||||||
mockTransport.setSecurity(Transport.CONNECTION_SECURITY_NONE, false);
|
mockTransport.setSecurity(Transport.CONNECTION_SECURITY_NONE, false);
|
||||||
mSender.setTransport(mockTransport);
|
mSender.setTransport(mockTransport);
|
||||||
|
mockTransport.setMockLocalAddress(InetAddress.getByName(LOCAL_ADDRESS));
|
||||||
return mockTransport;
|
return mockTransport;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue