Skip to content

Commit

Permalink
Stash of random changes #474
Browse files Browse the repository at this point in the history
Signed-off-by: jmehrens [email protected]
  • Loading branch information
jmehrens committed Feb 19, 2024
1 parent 0f07c0d commit 18d484e
Showing 1 changed file with 22 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -136,30 +122,14 @@ 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;
try {
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);
Expand All @@ -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.
Expand Down

0 comments on commit 18d484e

Please sign in to comment.