|
50 | 50 |
|
51 | 51 | import javax.mail.*; |
52 | 52 | import static javax.mail.Message.RecipientType.*; |
| 53 | +import static javax.mail.internet.MimeMessage.RecipientType.*; |
53 | 54 |
|
54 | 55 | import org.junit.*; |
55 | 56 | import static org.junit.Assert.assertArrayEquals; |
@@ -95,6 +96,72 @@ public void testSetRecipientStringNull() throws Exception { |
95 | 96 | assertArrayEquals("To: is removed", null, m.getRecipients(TO)); |
96 | 97 | } |
97 | 98 |
|
| 99 | + /** |
| 100 | + * Test that setFrom with an address containing a newline is folded |
| 101 | + * properly. |
| 102 | + * (Bug 7529) |
| 103 | + */ |
| 104 | + @Test |
| 105 | + public void testSetFromFold() throws Exception { |
| 106 | + InternetAddress addr = new InternetAddress("joe@bad.com", "Joe\r\nBad"); |
| 107 | + MimeMessage m = new MimeMessage(s); |
| 108 | + m.setFrom(addr); |
| 109 | + assertEquals("Joe\r\n Bad <joe@bad.com>", m.getHeader("From", null)); |
| 110 | + } |
| 111 | + |
| 112 | + /** |
| 113 | + * Test that setSender with an address containing a newline is folded |
| 114 | + * properly. |
| 115 | + * (Bug 7529) |
| 116 | + */ |
| 117 | + @Test |
| 118 | + public void testSetSenderFold() throws Exception { |
| 119 | + InternetAddress addr = new InternetAddress("joe@bad.com", "Joe\r\nBad"); |
| 120 | + MimeMessage m = new MimeMessage(s); |
| 121 | + m.setSender(addr); |
| 122 | + assertEquals("Joe\r\n Bad <joe@bad.com>", m.getHeader("Sender", null)); |
| 123 | + } |
| 124 | + |
| 125 | + /** |
| 126 | + * Test that setRecipient with a newsgroup address containing a newline is |
| 127 | + * handled properly. |
| 128 | + * (Bug 7529) |
| 129 | + */ |
| 130 | + @Test |
| 131 | + public void testSetNewsgroupWhitespace() throws Exception { |
| 132 | + NewsAddress addr = new NewsAddress("alt.\r\nbad"); |
| 133 | + MimeMessage m = new MimeMessage(s); |
| 134 | + m.setRecipient(NEWSGROUPS, addr); |
| 135 | + assertEquals("alt.bad", m.getHeader("Newsgroups", null)); |
| 136 | + } |
| 137 | + |
| 138 | + /** |
| 139 | + * Test that setRecipients with many newsgroup addresses is folded properly. |
| 140 | + * (Bug 7529) |
| 141 | + */ |
| 142 | + @Test |
| 143 | + public void testSetNewsgroupFold() throws Exception { |
| 144 | + NewsAddress[] longng = NewsAddress.parse( |
| 145 | + "alt.loooooooooooooooooooooooooooooooooooooooooooooooooong," + |
| 146 | + "alt.verylongggggggggggggggggggggggggggggggggggggggggggggg"); |
| 147 | + MimeMessage m = new MimeMessage(s); |
| 148 | + m.setRecipients(NEWSGROUPS, longng); |
| 149 | + assertTrue(m.getHeader("Newsgroups", null).indexOf("\r\n\t") > 0); |
| 150 | + } |
| 151 | + |
| 152 | + /** |
| 153 | + * Test that newsgroups can be set and read back (even if folded). |
| 154 | + */ |
| 155 | + @Test |
| 156 | + public void testSetGetNewsgroups() throws Exception { |
| 157 | + NewsAddress[] longng = NewsAddress.parse( |
| 158 | + "alt.loooooooooooooooooooooooooooooooooooooooooooooooooong," + |
| 159 | + "alt.verylongggggggggggggggggggggggggggggggggggggggggggggg"); |
| 160 | + MimeMessage m = new MimeMessage(s); |
| 161 | + m.setRecipients(NEWSGROUPS, longng); |
| 162 | + assertArrayEquals(longng, m.getRecipients(NEWSGROUPS)); |
| 163 | + } |
| 164 | + |
98 | 165 | /** |
99 | 166 | * Test that copying a DataHandler from one message to another |
100 | 167 | * has the desired effect. |
|
0 commit comments