From 0f14ee0fd2c47f74e07b149c7bd62ac1f9bcbe3f Mon Sep 17 00:00:00 2001 From: M66B Date: Sun, 3 May 2020 23:28:14 +0200 Subject: [PATCH] Fixed UTF-8 search --- .../email/BoundaryCallbackMessages.java | 63 +++++++++++++------ 1 file changed, 45 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/BoundaryCallbackMessages.java b/app/src/main/java/eu/faircode/email/BoundaryCallbackMessages.java index 7852279125..3036d50591 100644 --- a/app/src/main/java/eu/faircode/email/BoundaryCallbackMessages.java +++ b/app/src/main/java/eu/faircode/email/BoundaryCallbackMessages.java @@ -38,10 +38,12 @@ import com.sun.mail.imap.IMAPMessage; import com.sun.mail.imap.IMAPStore; import com.sun.mail.imap.protocol.IMAPProtocol; import com.sun.mail.imap.protocol.IMAPResponse; +import com.sun.mail.imap.protocol.SearchSequence; import java.io.File; import java.io.IOException; import java.io.Serializable; +import java.nio.charset.StandardCharsets; import java.text.Normalizer; import java.util.ArrayList; import java.util.Arrays; @@ -386,28 +388,53 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback msgnums = new ArrayList<>(); + for (Response response : responses) + if (((IMAPResponse) response).keyEquals("SEARCH")) { + int msgnum; + while ((msgnum = response.readNumber()) != -1) + msgnums.add(msgnum); + } + Message[] imessages = new Message[msgnums.size()]; + for (int i = 0; i < msgnums.size(); i++) + imessages[i] = state.ifolder.getMessage(msgnums.get(i)); + + return imessages; + } catch (Throwable ex) { + throw new ProtocolException("Search", ex); + } + } + }); + } catch (MessagingException ex) { + Log.w(ex); + } SearchTerm terms = criteria.getTerms( - utf8, + false, state.ifolder.getPermanentFlags(), browsable.keywords); - if (terms == null) - return new Message[0]; - - try { - return state.ifolder.search(terms); - } catch (MessagingException ex) { - if (utf8) { - Log.w(ex); - terms = criteria.getTerms( - false, - state.ifolder.getPermanentFlags(), - browsable.keywords); - return state.ifolder.search(terms); - } else - throw ex; - } + return state.ifolder.search(terms); } } catch (MessagingException ex) { ProtocolException pex = new ProtocolException(