diff --git a/greenmail-core/src/test/java/com/icegreen/greenmail/test/specificmessages/EncodingTest.java b/greenmail-core/src/test/java/com/icegreen/greenmail/test/specificmessages/EncodingTest.java index b232fa1a22..b5ce3ea623 100644 --- a/greenmail-core/src/test/java/com/icegreen/greenmail/test/specificmessages/EncodingTest.java +++ b/greenmail-core/src/test/java/com/icegreen/greenmail/test/specificmessages/EncodingTest.java @@ -15,6 +15,7 @@ import java.io.IOException; import java.io.InputStream; +import java.io.UnsupportedEncodingException; import java.nio.charset.StandardCharsets; import java.util.Arrays; @@ -189,6 +190,52 @@ public void messagesAdded(MessageCountEvent e) { } } + @Test + public void testAttachmentWithUTF8NameAndGreenMailApi() throws MessagingException, IOException { + greenMail.setUser("to@localhost", "pwd"); + final IMAPStore store = greenMail.getImap().createStore(); + store.connect("to@localhost", "pwd"); + try { + Folder inboxFolder = store.getFolder("INBOX"); + inboxFolder.open(Folder.READ_ONLY); + Message[] messages = new Message[] { null }; + MessageCountListener listener = new MessageCountListener() { + @Override + public void messagesRemoved(MessageCountEvent e) { + } + + @Override + public void messagesAdded(MessageCountEvent e) { + messages[0] = e.getMessages()[0]; + } + }; + inboxFolder.addMessageCountListener(listener); + new Thread(() -> { + try { + Thread.sleep(100); + } catch (InterruptedException e1) { + // Ignore + } + try { + String fileName = MimeUtility.encodeText("кирилица testimage_ünicöde_\uD83C\uDF36"); + GreenMailUtil.sendAttachmentEmail( + "to@localhost", "from@localhost", "subject", "body", + new byte[]{0, 1, 2}, "image/gif", fileName, + "testimage_description", greenMail.getSmtp().getServerSetup()); + } catch (UnsupportedEncodingException ex) { + assertThat(false).isTrue(); + } + }).start(); + ((IMAPFolder) inboxFolder).idle(true); + + assertThat(messages[0].getContent() != null).isTrue(); + + inboxFolder.close(); + } finally { + store.close(); + } + } + private void sendMessage(InternetAddress fromAddress, InternetAddress toAddress) throws MessagingException { final Session session = greenMail.getSmtp().createSession(); MimeMessage message = new MimeMessage(session);