From 09fe51c6da8007fe40b1fe83a9b76e252f8bcc8b Mon Sep 17 00:00:00 2001 From: jmehrens Date: Mon, 19 Feb 2024 14:17:54 -0600 Subject: [PATCH] Wrong charset used in creating search terms when server supports UTF8 #474 Signed-off-by: jmehrens jason_mehrens@hotmail.com --- .../mail/imap/protocol/SearchSequence.java | 32 +++++++++++++++---- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/providers/imap/src/main/java/org/eclipse/angus/mail/imap/protocol/SearchSequence.java b/providers/imap/src/main/java/org/eclipse/angus/mail/imap/protocol/SearchSequence.java index 2874520..914908a 100644 --- a/providers/imap/src/main/java/org/eclipse/angus/mail/imap/protocol/SearchSequence.java +++ b/providers/imap/src/main/java/org/eclipse/angus/mail/imap/protocol/SearchSequence.java @@ -64,7 +64,7 @@ */ public class SearchSequence { - private IMAPProtocol protocol; // for hasCapability checks; may be null + private final IMAPProtocol protocol; // for hasCapability checks; may be null /** * Create a SearchSequence for this IMAPProtocol. @@ -79,8 +79,9 @@ public SearchSequence(IMAPProtocol p) { /** * Create a SearchSequence. */ - @Deprecated(since="2.0.3", forRemoval=true) + @Deprecated public SearchSequence() { + protocol = null; //TODO Deprecate for remove??? } /** @@ -285,7 +286,12 @@ protected Argument header(HeaderTerm term, String charset) Argument result = new Argument(); result.writeAtom("HEADER"); result.writeString(term.getHeaderName()); - result.writeString(term.getPattern(), charset); + String pattern = term.getPattern(); + if (protocol != null && protocol.supportsUtf8() && !isAscii(term)) { + result.writeBytes(new Utf8Literal(pattern, charset)); + } else { + result.writeString(pattern, charset); + } return result; } @@ -337,7 +343,11 @@ protected Argument from(String address, String charset) throws SearchException, IOException { Argument result = new Argument(); result.writeAtom("FROM"); - result.writeString(address, charset); + if (protocol != null && protocol.supportsUtf8() && !isAscii(address)) { + result.writeBytes(new Utf8Literal(address, charset)); + } else { + result.writeString(address, charset); + } return result; } @@ -355,7 +365,12 @@ else if (type == Message.RecipientType.BCC) else throw new SearchException("Illegal Recipient type"); - result.writeString(address, charset); + + if (protocol != null && protocol.supportsUtf8() && !isAscii(address)) { + result.writeBytes(new Utf8Literal(address, charset)); + } else { + result.writeString(address, charset); + } return result; } @@ -378,7 +393,12 @@ protected Argument body(BodyTerm term, String charset) Argument result = new Argument(); result.writeAtom("BODY"); - result.writeString(term.getPattern(), charset); + String pattern = term.getPattern(); + if (protocol != null && protocol.supportsUtf8() && !isAscii(term)) { + result.writeBytes(new Utf8Literal(pattern, charset)); + } else { + result.writeString(pattern, charset); + } return result; }