Skip to content

Commit

Permalink
Wrong charset used in creating search terms when server supports UTF8
Browse files Browse the repository at this point in the history
#474
Signed-off-by: jmehrens [email protected]
  • Loading branch information
jmehrens committed Feb 19, 2024
1 parent 18d484e commit 09fe51c
Showing 1 changed file with 26 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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???
}

/**
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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;
}

Expand Down

0 comments on commit 09fe51c

Please sign in to comment.