Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d1904900 authored by Philip Whitehouse's avatar Philip Whitehouse Committed by cketti
Browse files

SMTP: Add test for 8-bit encoding behaviour

parent 0d339ef5
Loading
Loading
Loading
Loading
+34 −0
Original line number Diff line number Diff line
@@ -21,6 +21,8 @@ import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -36,6 +38,7 @@ public class SmtpTransportTest {
    private String username;
    private String password;
    private String clientCertificateAlias;
    private List<String> extensions;
    private StoreConfig storeConfig = mock(StoreConfig.class);
    private TrustedSocketFactory socketFactory;

@@ -53,6 +56,7 @@ public class SmtpTransportTest {
        authenticationType = null;
        clientCertificateAlias = null;
        connectionSecurity = null;
        extensions = new ArrayList<>();
    }

    private SmtpTransport startServerAndCreateSmtpTransport(MockSmtpServer server)
@@ -83,6 +87,9 @@ public class SmtpTransportTest {
        server.expect("EHLO localhost");
        server.output("250-localhost Hello client.localhost");
        server.output("250-SIZE 1000000");
        for (String extension: extensions) {
            server.output("250-"+extension);
        }
        server.output("250 AUTH LOGIN PLAIN CRAM-MD5");
        server.expect("AUTH PLAIN AHVzZXIAcGFzc3dvcmQ=");
        server.output("235 2.7.0 Authentication successful");
@@ -220,6 +227,33 @@ public class SmtpTransportTest {
        server.output("221 BYE");


        SmtpTransport transport = startServerAndCreateSmtpTransport(server);
        transport.sendMessage(message);
    }

    @Test
    public void sendMessage_with8BitEncoding_usesEncoding()
            throws MessagingException, IOException, InterruptedException {
        extensions.add("8BITMIME");
        TestMessage message = new TestMessage();
        message.setFrom(new Address("user@localhost"));
        message.setRecipients(Message.RecipientType.TO, new Address[]{new Address("user2@localhost")});

        MockSmtpServer server = new MockSmtpServer();
        setupConnectAndPlainAuthentication(server);
        server.expect("MAIL FROM:<user@localhost> BODY=8BITMIME");
        server.output("250 OK");
        server.expect("RCPT TO:<user2@localhost>");
        server.output("250 OK");
        server.expect("DATA");
        server.output("354 End data with <CR><LF>.<CR><LF>");
        server.expect("");
        server.expect(".");
        server.output("250 OK: queued as 12345");
        server.expect("QUIT");
        server.output("221 BYE");


        SmtpTransport transport = startServerAndCreateSmtpTransport(server);
        transport.sendMessage(message);
    }