Skip to content

Commit 4bf266b

Browse files
garyrussellartembilan
authored andcommitted
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.
1 parent 6c2200a commit 4bf266b

File tree

4 files changed

+49
-21
lines changed

4 files changed

+49
-21
lines changed

.editorconfig

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
root=true
2+
3+
[*.java]
4+
indent_style = tab
5+
indent_size = 4
6+
continuation_indent_size = 8
7+
8+
[*.xml]
9+
indent_style = tab
10+
indent_size = 4
11+
continuation_indent_size = 8

spring-integration-mail/src/test/java/org/springframework/integration/mail/ImapMailReceiverTests.java

+10-9
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838

3939
import java.io.IOException;
4040
import java.lang.reflect.Field;
41+
import java.util.Arrays;
4142
import java.util.Properties;
4243
import java.util.concurrent.CountDownLatch;
4344
import java.util.concurrent.ExecutorService;
@@ -218,14 +219,15 @@ public void testIdleWithServerGuts(ImapMailReceiver receiver, boolean mapped, bo
218219
else {
219220
org.springframework.messaging.Message<?> received = channel.receive(10000);
220221
assertNotNull(received);
221-
assertNotNull(received.getHeaders().get(MailHeaders.RAW_HEADERS));
222-
assertThat((String) received.getHeaders().get(MailHeaders.CONTENT_TYPE),
223-
equalTo("TEXT/PLAIN; charset=ISO-8859-1"));
224-
assertThat((String) received.getHeaders().get(MessageHeaders.CONTENT_TYPE),
225-
equalTo("TEXT/PLAIN; charset=ISO-8859-1"));
226-
assertThat((String) received.getHeaders().get(MailHeaders.FROM), equalTo("Bar <bar@baz>"));
227-
assertThat(((String[]) received.getHeaders().get(MailHeaders.TO))[0], equalTo("Foo <foo@bar>"));
228-
assertThat((String) received.getHeaders().get(MailHeaders.SUBJECT), equalTo("Test Email"));
222+
MessageHeaders headers = received.getHeaders();
223+
assertNotNull(headers.get(MailHeaders.RAW_HEADERS));
224+
assertThat(headers.get(MailHeaders.CONTENT_TYPE), equalTo("TEXT/PLAIN; charset=ISO-8859-1"));
225+
assertThat(headers.get(MessageHeaders.CONTENT_TYPE), equalTo("TEXT/PLAIN; charset=ISO-8859-1"));
226+
assertThat(headers.get(MailHeaders.FROM), equalTo("Bar <bar@baz>"));
227+
assertThat((headers.get(MailHeaders.TO, String[].class))[0], equalTo("Foo <foo@bar>"));
228+
assertThat(Arrays.toString(headers.get(MailHeaders.CC, String[].class)), equalTo("[a@b, c@d]"));
229+
assertThat(Arrays.toString(headers.get(MailHeaders.BCC, String[].class)), equalTo("[e@f, g@h]"));
230+
assertThat(headers.get(MailHeaders.SUBJECT), equalTo("Test Email"));
229231
if (simple) {
230232
assertThat(received.getPayload(), equalTo(TestMailServer.MailServer.MailHandler.BODY + "\r\n"));
231233
}
@@ -448,7 +450,6 @@ public void receiveAndIgnoreMarkAsReadDontDelete() throws Exception {
448450
verify(receiver, times(0)).deleteMessages((Message[]) Mockito.any());
449451
}
450452

451-
@SuppressWarnings("resource")
452453
@Test
453454
@Ignore
454455
public void testMessageHistory() throws Exception {

spring-integration-mail/src/test/java/org/springframework/integration/mail/config/Pop3Tests.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016 the original author or authors.
2+
* Copyright 2016-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,6 +20,8 @@
2020
import static org.junit.Assert.assertNotNull;
2121
import static org.junit.Assert.assertTrue;
2222

23+
import java.util.Arrays;
24+
2325
import org.junit.AfterClass;
2426
import org.junit.BeforeClass;
2527
import org.junit.Test;
@@ -65,6 +67,8 @@ public void testPop3() throws Exception {
6567
assertNotNull(message);
6668
MessageHeaders headers = message.getHeaders();
6769
assertEquals("Foo <foo@bar>", headers.get(MailHeaders.TO, String[].class)[0]);
70+
assertEquals("[a@b, c@d]", Arrays.toString(headers.get(MailHeaders.CC, String[].class)));
71+
assertEquals("[e@f, g@h]", Arrays.toString(headers.get(MailHeaders.BCC, String[].class)));
6872
assertEquals("Bar <bar@baz>", headers.get(MailHeaders.FROM));
6973
assertEquals("Test Email", headers.get(MailHeaders.SUBJECT));
7074
assertEquals("foo\r\n\r\n", message.getPayload());

spring-integration-test-support/src/main/java/org/springframework/integration/test/mail/TestMailServer.java

+23-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2016 the original author or authors.
2+
* Copyright 2014-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -289,21 +289,28 @@ else if (line.endsWith("SEARCH NOT (DELETED) NOT (SEEN) NOT (KEYWORD testSIUserF
289289
assertions.add("searchWithUserFlag");
290290
}
291291
else if (line.contains("FETCH 1 (ENVELOPE")) {
292-
write("* 1 FETCH (RFC822.SIZE 6909 INTERNALDATE \"27-May-2013 09:45:41 +0000\" "
292+
write("* 1 FETCH (RFC822.SIZE "
293+
+ MESSAGE.length()
294+
+ " INTERNALDATE \"27-May-2013 09:45:41 +0000\" "
293295
+ "FLAGS (\\Seen) "
294296
+ "ENVELOPE (\"Mon, 27 May 2013 15:14:49 +0530\" "
295-
+ "\"Test Email\" ((\"Bar\" NIL \"bar\" \"baz\")) "
296-
+ "((\"Bar\" NIL \"bar\" \"baz\")) "
297-
+ "((\"Bar\" NIL \"bar\" \"baz\")) "
298-
+ "((\"Foo\" NIL \"foo\" \"bar\")) NIL NIL "
299-
+ "\"<[email protected]>\" "
300-
+ "\"<[email protected]>\") "
301-
+ "BODYSTRUCTURE (\"TEXT\" \"PLAIN\" (\"CHARSET\" \"ISO-8859-1\") NIL NIL \"7BIT\" 1176 43)))");
297+
+ "\"Test Email\" "
298+
+ "((\"Bar\" NIL \"bar\" \"baz\")) " // From
299+
+ "((\"Bar\" NIL \"bar\" \"baz\")) " // Sender
300+
+ "((\"Bar\" NIL \"bar\" \"baz\")) " // Reply To
301+
+ "((\"Foo\" NIL \"foo\" \"bar\")) " // To
302+
+ "((NIL NIL \"a\" \"b\") (NIL NIL \"c\" \"d\")) " // cc
303+
+ "((NIL NIL \"e\" \"f\") (NIL NIL \"g\" \"h\")) " // bcc
304+
+ "\"<[email protected]>\" " // In reply to
305+
+ "\"<[email protected]>\") " // msgid
306+
+ "BODYSTRUCTURE "
307+
+ "(\"TEXT\" \"PLAIN\" (\"CHARSET\" \"ISO-8859-1\") NIL NIL \"7BIT\" 1 5)))");
302308
write(tag + "OK FETCH completed");
303309
}
304310
else if (line.contains("FETCH 2 (BODYSTRUCTURE)")) {
305311
write("* 2 FETCH " +
306-
"BODYSTRUCTURE (\"TEXT\" \"PLAIN\" (\"CHARSET\" \"ISO-8859-1\") NIL NIL \"7BIT\" 1176 43)))");
312+
"BODYSTRUCTURE "
313+
+ "(\"TEXT\" \"PLAIN\" (\"CHARSET\" \"ISO-8859-1\") NIL NIL \"7BIT\" 1 5)))");
307314
write(tag + "OK FETCH completed");
308315
}
309316
else if (line.contains("STORE 1 +FLAGS (\\Flagged)")) {
@@ -446,7 +453,12 @@ public abstract class MailHandler implements Runnable {
446453
public static final String BODY = "foo\r\n";
447454

448455
public static final String MESSAGE =
449-
"To: Foo <foo@bar>\r\nFrom: Bar <bar@baz>\r\nSubject: Test Email\r\n\r\n" + BODY;
456+
"To: Foo <foo@bar>\r\n"
457+
+ "cc: a@b, c@d\r\n"
458+
+ "bcc: e@f, g@h\r\n"
459+
+ "From: Bar <bar@baz>\r\n"
460+
+ "Subject: Test Email\r\n"
461+
+ "\r\n" + BODY;
450462

451463
protected final Socket socket;
452464

0 commit comments

Comments
 (0)