|
26 | 26 | import java.io.IOException; |
27 | 27 | import java.io.InputStream; |
28 | 28 | import java.io.InputStreamReader; |
| 29 | +import java.nio.charset.StandardCharsets; |
29 | 30 | import java.util.Enumeration; |
30 | 31 | import java.util.Properties; |
31 | 32 |
|
@@ -87,6 +88,7 @@ public synchronized void loadMessage() throws MessagingException { |
87 | 88 | TestableMimeMessageWrapper mw = null; |
88 | 89 | TestableMimeMessageWrapper onlyHeader = null; |
89 | 90 | final String content = "Subject: foo\r\nContent-Transfer-Encoding2: plain"; |
| 91 | + final String contentUtf8 = "Subject: fée\r\nContent-Transfer-Encoding2: plain"; |
90 | 92 | final String sep = "\r\n\r\n"; |
91 | 93 | final String body = "bar\r\n"; |
92 | 94 |
|
@@ -276,6 +278,35 @@ public void testSize() throws MessagingException { |
276 | 278 | assertThat(mw.getSize()).isEqualTo(body.length()); |
277 | 279 | } |
278 | 280 |
|
| 281 | + @Test |
| 282 | + public void testSizeUtf8() throws Exception { |
| 283 | + TestableMimeMessageWrapper message = getMessageFromSources(contentUtf8 + sep + body); |
| 284 | + ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
| 285 | + message.writeTo(baos); |
| 286 | + |
| 287 | + assertThat(message.getMessageSize()) |
| 288 | + .isEqualTo(baos.size()); |
| 289 | + } |
| 290 | + |
| 291 | + @Test |
| 292 | + public void testWriteToUtf8() throws Exception { |
| 293 | + TestableMimeMessageWrapper message = getMessageFromSources(contentUtf8 + sep + body); |
| 294 | + ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
| 295 | + message.writeTo(baos); |
| 296 | + |
| 297 | + assertThat(baos.toString(StandardCharsets.UTF_8)).isEqualTo(contentUtf8 + sep + body); |
| 298 | + } |
| 299 | + |
| 300 | + @Test |
| 301 | + public void testWriteToUtf8AfterHeaderModification() throws Exception { |
| 302 | + TestableMimeMessageWrapper message = getMessageFromSources(contentUtf8 + sep + body); |
| 303 | + message.addHeader("Another", "header"); |
| 304 | + ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
| 305 | + message.writeTo(baos); |
| 306 | + |
| 307 | + assertThat(baos.toString(StandardCharsets.UTF_8)).contains("Subject: fée\r\n"); |
| 308 | + } |
| 309 | + |
279 | 310 | @Test |
280 | 311 | public void getSizeShouldReturnZeroWhenNoHeaderAndAddHeader() throws MessagingException { |
281 | 312 | onlyHeader.addHeader("a", "b"); |
|
0 commit comments