Fixed checking command status

pull/153/head
M66B 6 years ago
parent 917fe43daa
commit 1d1e32bebe

@ -921,31 +921,32 @@ class Core {
}
if (uids.size() > 0) {
ifolder.doCommand(new IMAPFolder.ProtocolCommand() {
MessagingException ex = (MessagingException) ifolder.doCommand(new IMAPFolder.ProtocolCommand() {
@Override
public Object doCommand(IMAPProtocol protocol) {
Log.i("Executing uid fetch count=" + uids.size());
Response[] responses = protocol.command(
"UID FETCH " + TextUtils.join(",", uids) + " (UID)", null);
for (int i = 0; i < responses.length; i++) {
if (responses[i] instanceof FetchResponse) {
FetchResponse fr = (FetchResponse) responses[i];
UID uid = fr.getItem(UID.class);
if (uid != null)
uids.remove(uid.uid);
} else {
if (responses[i].isOK())
Log.i(folder.name + " response=" + responses[i]);
else {
Log.e(folder.name + " response=" + responses[i]);
db.folder().setFolderError(folder.id, responses[i].toString());
if (responses.length > 0 && responses[responses.length - 1].isOK()) {
for (Response response : responses)
if (response instanceof FetchResponse) {
FetchResponse fr = (FetchResponse) response;
UID uid = fr.getItem(UID.class);
if (uid != null)
uids.remove(uid.uid);
}
}
return null;
} else {
for (Response response : responses)
if (response.isNO() || response.isBAD() || response.isBYE())
return new MessagingException(response.toString());
return new MessagingException("UID FETCH failed");
}
return null;
}
});
if (ex != null)
throw ex;
long getuid = SystemClock.elapsedRealtime();
Log.i(folder.name + " remote uids=" + (SystemClock.elapsedRealtime() - getuid) + " ms");

@ -198,7 +198,6 @@ public class ViewModelBrowse extends ViewModel {
try {
// https://tools.ietf.org/html/rfc3501#section-6.4.4
Log.i("Boundary UTF8 search=" + state.search);
Argument arg = new Argument();
if (!protocol.supportsUtf8()) {
arg.writeAtom("CHARSET");
@ -221,48 +220,49 @@ public class ViewModelBrowse extends ViewModel {
arg.writeAtom("KEYWORD");
arg.writeBytes(state.search.getBytes());
}
Log.i("Boundary UTF8 search=" + state.search);
Response[] responses = protocol.command("SEARCH", arg);
if (responses.length > 0 && responses[responses.length - 1].isOK()) {
List<Integer> 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;
} else {
// Assume no UTF-8 support
String search = state.search.replace("ß", "ss"); // Eszett
search = Normalizer.normalize(search, Normalizer.Form.NFD)
.replaceAll("[^\\p{ASCII}]", "");
Log.i("Boundary ASCII search=" + search);
SearchTerm term = new OrTerm(
new OrTerm(
new FromStringTerm(search),
new RecipientStringTerm(Message.RecipientType.TO, search)
),
new OrTerm(
new SubjectTerm(search),
new BodyTerm(search)
)
);
if (keywords)
term = new OrTerm(term, new FlagTerm(
new Flags(Helper.sanitizeKeyword(search)), true));
return state.ifolder.search(term);
}
List<Integer> msgnums = new ArrayList<>();
for (Response response : responses)
if (response.isOK())
Log.i(folder.name + " response=" + response);
else if (((IMAPResponse) response).keyEquals("SEARCH")) {
int msgnum;
while ((msgnum = response.readNumber()) != -1)
msgnums.add(msgnum);
} else {
Log.w(folder.name + " response=" + response);
// Assume no UTF-8 support
String search = state.search.replace("ß", "ss"); // Eszett
search = Normalizer.normalize(search, Normalizer.Form.NFD)
.replaceAll("[^\\p{ASCII}]", "");
Log.i("Boundary ASCII search=" + search);
SearchTerm term = new OrTerm(
new OrTerm(
new FromStringTerm(search),
new RecipientStringTerm(Message.RecipientType.TO, search)
),
new OrTerm(
new SubjectTerm(search),
new BodyTerm(search)
)
);
if (keywords)
term = new OrTerm(term, new FlagTerm(
new Flags(Helper.sanitizeKeyword(search)), true));
return state.ifolder.search(term);
}
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 (MessagingException ex) {
Log.e(ex);
return ex;

Loading…
Cancel
Save