Test Mail Server Add CC: and BCC: Headers
Allow assertions of proper population in tests. Also set Github tab size to 4. Fix BODYSTRUCTURE metadata to match actual body (1 line, 5 octets). Fix RFC822.SIZE to match actual message.
This commit is contained in:
committed by
Artem Bilan
parent
6c2200a03f
commit
4bf266be50
11
.editorconfig
Normal file
11
.editorconfig
Normal file
@@ -0,0 +1,11 @@
|
||||
root=true
|
||||
|
||||
[*.java]
|
||||
indent_style = tab
|
||||
indent_size = 4
|
||||
continuation_indent_size = 8
|
||||
|
||||
[*.xml]
|
||||
indent_style = tab
|
||||
indent_size = 4
|
||||
continuation_indent_size = 8
|
||||
@@ -38,6 +38,7 @@ import static org.mockito.Mockito.verify;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Arrays;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
@@ -218,14 +219,15 @@ public class ImapMailReceiverTests {
|
||||
else {
|
||||
org.springframework.messaging.Message<?> received = channel.receive(10000);
|
||||
assertNotNull(received);
|
||||
assertNotNull(received.getHeaders().get(MailHeaders.RAW_HEADERS));
|
||||
assertThat((String) received.getHeaders().get(MailHeaders.CONTENT_TYPE),
|
||||
equalTo("TEXT/PLAIN; charset=ISO-8859-1"));
|
||||
assertThat((String) received.getHeaders().get(MessageHeaders.CONTENT_TYPE),
|
||||
equalTo("TEXT/PLAIN; charset=ISO-8859-1"));
|
||||
assertThat((String) received.getHeaders().get(MailHeaders.FROM), equalTo("Bar <bar@baz>"));
|
||||
assertThat(((String[]) received.getHeaders().get(MailHeaders.TO))[0], equalTo("Foo <foo@bar>"));
|
||||
assertThat((String) received.getHeaders().get(MailHeaders.SUBJECT), equalTo("Test Email"));
|
||||
MessageHeaders headers = received.getHeaders();
|
||||
assertNotNull(headers.get(MailHeaders.RAW_HEADERS));
|
||||
assertThat(headers.get(MailHeaders.CONTENT_TYPE), equalTo("TEXT/PLAIN; charset=ISO-8859-1"));
|
||||
assertThat(headers.get(MessageHeaders.CONTENT_TYPE), equalTo("TEXT/PLAIN; charset=ISO-8859-1"));
|
||||
assertThat(headers.get(MailHeaders.FROM), equalTo("Bar <bar@baz>"));
|
||||
assertThat((headers.get(MailHeaders.TO, String[].class))[0], equalTo("Foo <foo@bar>"));
|
||||
assertThat(Arrays.toString(headers.get(MailHeaders.CC, String[].class)), equalTo("[a@b, c@d]"));
|
||||
assertThat(Arrays.toString(headers.get(MailHeaders.BCC, String[].class)), equalTo("[e@f, g@h]"));
|
||||
assertThat(headers.get(MailHeaders.SUBJECT), equalTo("Test Email"));
|
||||
if (simple) {
|
||||
assertThat(received.getPayload(), equalTo(TestMailServer.MailServer.MailHandler.BODY + "\r\n"));
|
||||
}
|
||||
@@ -448,7 +450,6 @@ public class ImapMailReceiverTests {
|
||||
verify(receiver, times(0)).deleteMessages((Message[]) Mockito.any());
|
||||
}
|
||||
|
||||
@SuppressWarnings("resource")
|
||||
@Test
|
||||
@Ignore
|
||||
public void testMessageHistory() throws Exception {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016 the original author or authors.
|
||||
* Copyright 2016-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -20,6 +20,8 @@ import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
@@ -65,6 +67,8 @@ public class Pop3Tests {
|
||||
assertNotNull(message);
|
||||
MessageHeaders headers = message.getHeaders();
|
||||
assertEquals("Foo <foo@bar>", headers.get(MailHeaders.TO, String[].class)[0]);
|
||||
assertEquals("[a@b, c@d]", Arrays.toString(headers.get(MailHeaders.CC, String[].class)));
|
||||
assertEquals("[e@f, g@h]", Arrays.toString(headers.get(MailHeaders.BCC, String[].class)));
|
||||
assertEquals("Bar <bar@baz>", headers.get(MailHeaders.FROM));
|
||||
assertEquals("Test Email", headers.get(MailHeaders.SUBJECT));
|
||||
assertEquals("foo\r\n\r\n", message.getPayload());
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2016 the original author or authors.
|
||||
* Copyright 2014-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -289,21 +289,28 @@ public class TestMailServer {
|
||||
assertions.add("searchWithUserFlag");
|
||||
}
|
||||
else if (line.contains("FETCH 1 (ENVELOPE")) {
|
||||
write("* 1 FETCH (RFC822.SIZE 6909 INTERNALDATE \"27-May-2013 09:45:41 +0000\" "
|
||||
write("* 1 FETCH (RFC822.SIZE "
|
||||
+ MESSAGE.length()
|
||||
+ " INTERNALDATE \"27-May-2013 09:45:41 +0000\" "
|
||||
+ "FLAGS (\\Seen) "
|
||||
+ "ENVELOPE (\"Mon, 27 May 2013 15:14:49 +0530\" "
|
||||
+ "\"Test Email\" ((\"Bar\" NIL \"bar\" \"baz\")) "
|
||||
+ "((\"Bar\" NIL \"bar\" \"baz\")) "
|
||||
+ "((\"Bar\" NIL \"bar\" \"baz\")) "
|
||||
+ "((\"Foo\" NIL \"foo\" \"bar\")) NIL NIL "
|
||||
+ "\"<4DA0A7E4.3010506@baz.net>\" "
|
||||
+ "\"<CACVnpJkAUUfa3d_-4GNZW2WpxbB39tBCHC=T0gc7hty6dOEHcA@foo.bar.com>\") "
|
||||
+ "BODYSTRUCTURE (\"TEXT\" \"PLAIN\" (\"CHARSET\" \"ISO-8859-1\") NIL NIL \"7BIT\" 1176 43)))");
|
||||
+ "\"Test Email\" "
|
||||
+ "((\"Bar\" NIL \"bar\" \"baz\")) " // From
|
||||
+ "((\"Bar\" NIL \"bar\" \"baz\")) " // Sender
|
||||
+ "((\"Bar\" NIL \"bar\" \"baz\")) " // Reply To
|
||||
+ "((\"Foo\" NIL \"foo\" \"bar\")) " // To
|
||||
+ "((NIL NIL \"a\" \"b\") (NIL NIL \"c\" \"d\")) " // cc
|
||||
+ "((NIL NIL \"e\" \"f\") (NIL NIL \"g\" \"h\")) " // bcc
|
||||
+ "\"<4DA0A7E4.3010506@baz.net>\" " // In reply to
|
||||
+ "\"<CACVnpJkAUUfa3d_-4GNZW2WpxbB39tBCHC=T0gc7hty6dOEHcA@foo.bar.com>\") " // msgid
|
||||
+ "BODYSTRUCTURE "
|
||||
+ "(\"TEXT\" \"PLAIN\" (\"CHARSET\" \"ISO-8859-1\") NIL NIL \"7BIT\" 1 5)))");
|
||||
write(tag + "OK FETCH completed");
|
||||
}
|
||||
else if (line.contains("FETCH 2 (BODYSTRUCTURE)")) {
|
||||
write("* 2 FETCH " +
|
||||
"BODYSTRUCTURE (\"TEXT\" \"PLAIN\" (\"CHARSET\" \"ISO-8859-1\") NIL NIL \"7BIT\" 1176 43)))");
|
||||
"BODYSTRUCTURE "
|
||||
+ "(\"TEXT\" \"PLAIN\" (\"CHARSET\" \"ISO-8859-1\") NIL NIL \"7BIT\" 1 5)))");
|
||||
write(tag + "OK FETCH completed");
|
||||
}
|
||||
else if (line.contains("STORE 1 +FLAGS (\\Flagged)")) {
|
||||
@@ -446,7 +453,12 @@ public class TestMailServer {
|
||||
public static final String BODY = "foo\r\n";
|
||||
|
||||
public static final String MESSAGE =
|
||||
"To: Foo <foo@bar>\r\nFrom: Bar <bar@baz>\r\nSubject: Test Email\r\n\r\n" + BODY;
|
||||
"To: Foo <foo@bar>\r\n"
|
||||
+ "cc: a@b, c@d\r\n"
|
||||
+ "bcc: e@f, g@h\r\n"
|
||||
+ "From: Bar <bar@baz>\r\n"
|
||||
+ "Subject: Test Email\r\n"
|
||||
+ "\r\n" + BODY;
|
||||
|
||||
protected final Socket socket;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user