diff --git a/providers/angus-mail/src/test/java/org/eclipse/angus/mail/imap/IMAPSearchTest.java b/providers/angus-mail/src/test/java/org/eclipse/angus/mail/imap/IMAPSearchTest.java index 5018653..c870f98 100644 --- a/providers/angus-mail/src/test/java/org/eclipse/angus/mail/imap/IMAPSearchTest.java +++ b/providers/angus-mail/src/test/java/org/eclipse/angus/mail/imap/IMAPSearchTest.java @@ -109,22 +109,8 @@ public void testUtf8Search() { server = new TestServer(new IMAPUtf8Handler() { @Override public void search(String line) throws IOException { - //TODO Could use java.util.HexFormat - //TODO this patch doesn't seem correct because - //UTF-8 should be a literal not quoted string. - System.out.println(line); - line.codePoints().forEach(c -> { - System.out.append("0x") - .append(Integer.toHexString(c)) - .append(", "); - }); - System.out.println(); - - if (line.contains("CHARSET")) bad("CHARSET not supported"); - if (!line.contains(find)) - bad("UTF-8 encoding/decoding not used"); else ok(); } @@ -136,23 +122,6 @@ public void search(String line) throws IOException { properties.setProperty("mail.imap.port", String.valueOf(server.getPort())); final Session session = Session.getInstance(properties); //session.setDebug(true); - - SubjectTerm term = new SubjectTerm(find); - InputStream in = new ByteArrayInputStream(new byte[0]); - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - PrintStream out = new PrintStream(baos, true, "UTF-8"); - - IMAPProtocol p = new IMAPProtocol(in, out, properties, session.getDebug()) { - public boolean supportsUtf8() { - return true; - } - }; - SearchSequence ss = new SearchSequence(p); - try { - ss.generateSequence(term, "UTF-8").write(p); - } catch(IOException ignore) { - } - System.out.println(baos.toString("UTF-8")); final Store store = session.getStore("imap"); Folder folder = null; @@ -160,6 +129,7 @@ public boolean supportsUtf8() { store.connect("test", "test"); folder = store.getFolder("INBOX"); folder.open(Folder.READ_ONLY); + SubjectTerm term = new SubjectTerm(find); Message[] msgs = folder.search(term); } catch (Exception ex) { System.out.println(ex); @@ -179,6 +149,27 @@ public boolean supportsUtf8() { } } } + + @Test + public void testUtf8SubjectLiteral() throws Exception { + final String find = "\u2019\u7cfb\u7edf"; + SubjectTerm term = new SubjectTerm(find); + InputStream in = new ByteArrayInputStream(new byte[0]); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + PrintStream out = new PrintStream(baos, true, "UTF-8"); + Properties props = new Properties(); + + IMAPProtocol p = new IMAPProtocol(in, out, props, false) { + public boolean supportsUtf8() { + return true; + } + }; + + SearchSequence ss = new SearchSequence(p); + ss.generateSequence(term, "UTF-8").write(p); + + System.out.println(baos.toString("UTF-8")); + } /** * An IMAPHandler that enables UTF-8 support.