|
1 | 1 | /*
|
2 | 2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
3 | 3 | *
|
4 |
| - * Copyright (c) 2009-2017 Oracle and/or its affiliates. All rights reserved. |
| 4 | + * Copyright (c) 2009-2018 Oracle and/or its affiliates. All rights reserved. |
5 | 5 | *
|
6 | 6 | * The contents of this file are subject to the terms of either the GNU
|
7 | 7 | * General Public License Version 2 only ("GPL") or the Common Development
|
@@ -113,4 +113,69 @@ public void search(String line) throws IOException {
|
113 | 113 | }
|
114 | 114 | }
|
115 | 115 | }
|
| 116 | + |
| 117 | + /** |
| 118 | + * Test that when the server supports UTF8 and the client enables it, |
| 119 | + * the client doesn't issue a SEARCH CHARSET command even if the search |
| 120 | + * term includes a non-ASCII character. |
| 121 | + * (see RFC 6855, section 3, last paragraph) |
| 122 | + */ |
| 123 | + @Test |
| 124 | + public void testUtf8Search() { |
| 125 | + TestServer server = null; |
| 126 | + try { |
| 127 | + server = new TestServer(new IMAPUtf8Handler() { |
| 128 | + @Override |
| 129 | + public void search(String line) throws IOException { |
| 130 | + if (line.contains("CHARSET")) |
| 131 | + bad("CHARSET not supported"); |
| 132 | + else |
| 133 | + ok(); |
| 134 | + } |
| 135 | + }); |
| 136 | + server.start(); |
| 137 | + |
| 138 | + final Properties properties = new Properties(); |
| 139 | + properties.setProperty("mail.imap.host", "localhost"); |
| 140 | + properties.setProperty("mail.imap.port", "" + server.getPort()); |
| 141 | + final Session session = Session.getInstance(properties); |
| 142 | + //session.setDebug(true); |
| 143 | + |
| 144 | + final Store store = session.getStore("imap"); |
| 145 | + Folder folder = null; |
| 146 | + try { |
| 147 | + store.connect("test", "test"); |
| 148 | + folder = store.getFolder("INBOX"); |
| 149 | + folder.open(Folder.READ_ONLY); |
| 150 | + Message[] msgs = folder.search(new SubjectTerm("\u2019")); |
| 151 | + } catch (Exception ex) { |
| 152 | + System.out.println(ex); |
| 153 | + //ex.printStackTrace(); |
| 154 | + fail(ex.toString()); |
| 155 | + } finally { |
| 156 | + if (folder != null) |
| 157 | + folder.close(false); |
| 158 | + store.close(); |
| 159 | + } |
| 160 | + } catch (final Exception e) { |
| 161 | + e.printStackTrace(); |
| 162 | + fail(e.getMessage()); |
| 163 | + } finally { |
| 164 | + if (server != null) { |
| 165 | + server.quit(); |
| 166 | + } |
| 167 | + } |
| 168 | + } |
| 169 | + |
| 170 | + /** |
| 171 | + * An IMAPHandler that enables UTF-8 support. |
| 172 | + */ |
| 173 | + private static class IMAPUtf8Handler extends IMAPHandler { |
| 174 | + {{ capabilities += " ENABLE UTF8=ACCEPT"; }} |
| 175 | + |
| 176 | + @Override |
| 177 | + public void enable(String line) throws IOException { |
| 178 | + ok(); |
| 179 | + } |
| 180 | + } |
116 | 181 | }
|
0 commit comments