|
|
@ -355,12 +355,14 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
|
|
|
|
public Object doCommand(IMAPProtocol protocol) throws ProtocolException {
|
|
|
|
public Object doCommand(IMAPProtocol protocol) throws ProtocolException {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
// https://tools.ietf.org/html/rfc3501#section-6.4.4
|
|
|
|
// https://tools.ietf.org/html/rfc3501#section-6.4.4
|
|
|
|
Argument arg = new Argument();
|
|
|
|
|
|
|
|
if (criteria.query != null &&
|
|
|
|
if (criteria.query != null &&
|
|
|
|
criteria.query.startsWith("raw:") &&
|
|
|
|
criteria.query.startsWith("raw:") &&
|
|
|
|
state.iservice.hasCapability("X-GM-EXT-1")) {
|
|
|
|
state.iservice.hasCapability("X-GM-EXT-1")) {
|
|
|
|
// https://support.google.com/mail/answer/7190
|
|
|
|
// https://support.google.com/mail/answer/7190
|
|
|
|
// https://developers.google.com/gmail/imap/imap-extensions#extension_of_the_search_command_x-gm-raw
|
|
|
|
// https://developers.google.com/gmail/imap/imap-extensions#extension_of_the_search_command_x-gm-raw
|
|
|
|
|
|
|
|
Log.i("Boundary raw search=" + criteria.query);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Argument arg = new Argument();
|
|
|
|
arg.writeAtom("X-GM-RAW");
|
|
|
|
arg.writeAtom("X-GM-RAW");
|
|
|
|
arg.writeString(criteria.query.substring(4));
|
|
|
|
arg.writeString(criteria.query.substring(4));
|
|
|
|
|
|
|
|
|
|
|
@ -370,8 +372,6 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
|
|
|
|
if (!responses[responses.length - 1].isOK())
|
|
|
|
if (!responses[responses.length - 1].isOK())
|
|
|
|
throw new ProtocolException(responses[responses.length - 1]);
|
|
|
|
throw new ProtocolException(responses[responses.length - 1]);
|
|
|
|
|
|
|
|
|
|
|
|
Log.i("Boundary raw search=" + criteria.query);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<Integer> msgnums = new ArrayList<>();
|
|
|
|
List<Integer> msgnums = new ArrayList<>();
|
|
|
|
for (Response response : responses)
|
|
|
|
for (Response response : responses)
|
|
|
|
if (((IMAPResponse) response).keyEquals("SEARCH")) {
|
|
|
|
if (((IMAPResponse) response).keyEquals("SEARCH")) {
|
|
|
@ -388,47 +388,41 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
Log.i("Boundary server search=" + criteria);
|
|
|
|
Log.i("Boundary server search=" + criteria);
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
if (protocol.supportsUtf8())
|
|
|
|
if (protocol.supportsUtf8())
|
|
|
|
try {
|
|
|
|
return (Message[]) state.ifolder.doCommand(new IMAPFolder.ProtocolCommand() {
|
|
|
|
SearchTerm terms = criteria.getTerms(
|
|
|
|
@Override
|
|
|
|
true,
|
|
|
|
public Object doCommand(IMAPProtocol protocol) throws ProtocolException {
|
|
|
|
state.ifolder.getPermanentFlags(),
|
|
|
|
SearchTerm terms = criteria.getTerms(
|
|
|
|
browsable.keywords);
|
|
|
|
true,
|
|
|
|
|
|
|
|
state.ifolder.getPermanentFlags(),
|
|
|
|
SearchSequence ss = new SearchSequence(protocol);
|
|
|
|
browsable.keywords);
|
|
|
|
Argument args = ss.generateSequence(terms, StandardCharsets.UTF_8.name());
|
|
|
|
|
|
|
|
args.writeAtom("ALL");
|
|
|
|
try {
|
|
|
|
|
|
|
|
SearchSequence ss = new SearchSequence(protocol);
|
|
|
|
Response[] responses = protocol.command("SEARCH", args);
|
|
|
|
Argument args = ss.generateSequence(terms, StandardCharsets.UTF_8.name());
|
|
|
|
if (responses.length == 0)
|
|
|
|
args.writeAtom("ALL");
|
|
|
|
throw new ProtocolException("No response");
|
|
|
|
|
|
|
|
if (!responses[responses.length - 1].isOK())
|
|
|
|
Response[] responses = protocol.command("SEARCH", args);
|
|
|
|
throw new ProtocolException(responses[responses.length - 1]);
|
|
|
|
if (responses.length == 0)
|
|
|
|
|
|
|
|
throw new ProtocolException("No response");
|
|
|
|
List<Integer> msgnums = new ArrayList<>();
|
|
|
|
if (!responses[responses.length - 1].isOK())
|
|
|
|
for (Response response : responses)
|
|
|
|
throw new ProtocolException(responses[responses.length - 1]);
|
|
|
|
if (((IMAPResponse) response).keyEquals("SEARCH")) {
|
|
|
|
|
|
|
|
int msgnum;
|
|
|
|
List<Integer> msgnums = new ArrayList<>();
|
|
|
|
while ((msgnum = response.readNumber()) != -1)
|
|
|
|
for (Response response : responses)
|
|
|
|
msgnums.add(msgnum);
|
|
|
|
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);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
Message[] imessages = new Message[msgnums.size()];
|
|
|
|
} catch (MessagingException ex) {
|
|
|
|
for (int i = 0; i < msgnums.size(); i++)
|
|
|
|
Log.w(ex);
|
|
|
|
imessages[i] = state.ifolder.getMessage(msgnums.get(i));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return imessages;
|
|
|
|
|
|
|
|
} catch (Throwable ex) {
|
|
|
|
|
|
|
|
ProtocolException pex = new ProtocolException(
|
|
|
|
|
|
|
|
"Search unicode " + account.host + " " + criteria, ex);
|
|
|
|
|
|
|
|
Log.e(pex);
|
|
|
|
|
|
|
|
// Fallback to ASCII search
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SearchTerm terms = criteria.getTerms(
|
|
|
|
SearchTerm terms = criteria.getTerms(
|
|
|
|
false,
|
|
|
|
false,
|
|
|
@ -607,7 +601,7 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
|
|
|
|
static class SearchCriteria implements Serializable {
|
|
|
|
static class SearchCriteria implements Serializable {
|
|
|
|
String query;
|
|
|
|
String query;
|
|
|
|
boolean in_senders = true;
|
|
|
|
boolean in_senders = true;
|
|
|
|
boolean in_receipients = true;
|
|
|
|
boolean in_recipients = true;
|
|
|
|
boolean in_subject = true;
|
|
|
|
boolean in_subject = true;
|
|
|
|
boolean in_keywords = true;
|
|
|
|
boolean in_keywords = true;
|
|
|
|
boolean in_message = true;
|
|
|
|
boolean in_message = true;
|
|
|
@ -629,7 +623,7 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
|
|
|
|
boolean isQueryOnly() {
|
|
|
|
boolean isQueryOnly() {
|
|
|
|
return (!TextUtils.isEmpty(query) &&
|
|
|
|
return (!TextUtils.isEmpty(query) &&
|
|
|
|
in_senders &&
|
|
|
|
in_senders &&
|
|
|
|
in_receipients &&
|
|
|
|
in_recipients &&
|
|
|
|
in_subject &&
|
|
|
|
in_subject &&
|
|
|
|
in_keywords &&
|
|
|
|
in_keywords &&
|
|
|
|
in_message &&
|
|
|
|
in_message &&
|
|
|
@ -666,7 +660,7 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
|
|
|
|
|
|
|
|
|
|
|
|
if (in_senders)
|
|
|
|
if (in_senders)
|
|
|
|
or.add(new FromStringTerm(search));
|
|
|
|
or.add(new FromStringTerm(search));
|
|
|
|
if (in_receipients) {
|
|
|
|
if (in_recipients) {
|
|
|
|
or.add(new RecipientStringTerm(Message.RecipientType.TO, search));
|
|
|
|
or.add(new RecipientStringTerm(Message.RecipientType.TO, search));
|
|
|
|
or.add(new RecipientStringTerm(Message.RecipientType.CC, search));
|
|
|
|
or.add(new RecipientStringTerm(Message.RecipientType.CC, search));
|
|
|
|
or.add(new RecipientStringTerm(Message.RecipientType.BCC, search));
|
|
|
|
or.add(new RecipientStringTerm(Message.RecipientType.BCC, search));
|
|
|
@ -726,7 +720,7 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
|
|
|
|
SearchCriteria other = (SearchCriteria) obj;
|
|
|
|
SearchCriteria other = (SearchCriteria) obj;
|
|
|
|
return (Objects.equals(this.query, other.query) &&
|
|
|
|
return (Objects.equals(this.query, other.query) &&
|
|
|
|
this.in_senders == other.in_senders &&
|
|
|
|
this.in_senders == other.in_senders &&
|
|
|
|
this.in_receipients == other.in_receipients &&
|
|
|
|
this.in_recipients == other.in_recipients &&
|
|
|
|
this.in_subject == other.in_subject &&
|
|
|
|
this.in_subject == other.in_subject &&
|
|
|
|
this.in_keywords == other.in_keywords &&
|
|
|
|
this.in_keywords == other.in_keywords &&
|
|
|
|
this.in_message == other.in_message &&
|
|
|
|
this.in_message == other.in_message &&
|
|
|
@ -746,7 +740,7 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
|
|
|
|
public String toString() {
|
|
|
|
public String toString() {
|
|
|
|
return query +
|
|
|
|
return query +
|
|
|
|
" senders=" + in_senders +
|
|
|
|
" senders=" + in_senders +
|
|
|
|
" receipients=" + in_receipients +
|
|
|
|
" recipients=" + in_recipients +
|
|
|
|
" subject=" + in_subject +
|
|
|
|
" subject=" + in_subject +
|
|
|
|
" keywords=" + in_keywords +
|
|
|
|
" keywords=" + in_keywords +
|
|
|
|
" message=" + in_message +
|
|
|
|
" message=" + in_message +
|
|
|
|