mirror of
https://github.com/M66B/FairEmail.git
synced 2025-03-15 16:39:37 +00:00
Search improvements
This commit is contained in:
parent
a234d0f6b5
commit
2a2280c15d
3 changed files with 80 additions and 85 deletions
|
@ -35,6 +35,7 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
|
||||||
private ViewModelBrowse model;
|
private ViewModelBrowse model;
|
||||||
private Handler handler;
|
private Handler handler;
|
||||||
private IBoundaryCallbackMessages intf;
|
private IBoundaryCallbackMessages intf;
|
||||||
|
private boolean searching = false;
|
||||||
|
|
||||||
private static ExecutorService executor = Executors.newSingleThreadExecutor(Helper.backgroundThreadFactory);
|
private static ExecutorService executor = Executors.newSingleThreadExecutor(Helper.backgroundThreadFactory);
|
||||||
|
|
||||||
|
@ -66,7 +67,7 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isSearching() {
|
boolean isSearching() {
|
||||||
return model.isSearching();
|
return searching;
|
||||||
}
|
}
|
||||||
|
|
||||||
int getLoaded() {
|
int getLoaded() {
|
||||||
|
@ -90,6 +91,7 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
|
searching = true;
|
||||||
handler.post(new Runnable() {
|
handler.post(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -106,6 +108,7 @@ public class BoundaryCallbackMessages extends PagedList.BoundaryCallback<TupleMe
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} finally {
|
} finally {
|
||||||
|
searching = false;
|
||||||
handler.post(new Runnable() {
|
handler.post(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
|
@ -650,7 +650,7 @@ public class FragmentMessages extends FragmentEx {
|
||||||
|
|
||||||
new SimpleTask<Void>() {
|
new SimpleTask<Void>() {
|
||||||
@Override
|
@Override
|
||||||
protected Void onLoad(Context context, Bundle args) throws Throwable {
|
protected Void onLoad(Context context, Bundle args) {
|
||||||
DB.getInstance(context).message().deleteFoundMessages();
|
DB.getInstance(context).message().deleteFoundMessages();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,8 +36,8 @@ public class ViewModelBrowse extends ViewModel {
|
||||||
private IMAPStore istore = null;
|
private IMAPStore istore = null;
|
||||||
private IMAPFolder ifolder = null;
|
private IMAPFolder ifolder = null;
|
||||||
private Message[] imessages = null;
|
private Message[] imessages = null;
|
||||||
private int index;
|
|
||||||
private boolean searching = false;
|
private int index = -1;
|
||||||
private int loaded = 0;
|
private int loaded = 0;
|
||||||
|
|
||||||
void set(Context context, long folder, String search, int pageSize) {
|
void set(Context context, long folder, String search, int pageSize) {
|
||||||
|
@ -47,7 +47,6 @@ public class ViewModelBrowse extends ViewModel {
|
||||||
this.pageSize = pageSize;
|
this.pageSize = pageSize;
|
||||||
|
|
||||||
this.index = -1;
|
this.index = -1;
|
||||||
this.searching = false;
|
|
||||||
this.loaded = 0;
|
this.loaded = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,107 +54,100 @@ public class ViewModelBrowse extends ViewModel {
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isSearching() {
|
|
||||||
return searching;
|
|
||||||
}
|
|
||||||
|
|
||||||
int getLoaded() {
|
int getLoaded() {
|
||||||
return loaded;
|
return loaded;
|
||||||
}
|
}
|
||||||
|
|
||||||
void load() throws MessagingException, FolderClosedIOException {
|
void load() throws MessagingException, FolderClosedIOException {
|
||||||
try {
|
DB db = DB.getInstance(context);
|
||||||
searching = true;
|
EntityFolder folder = db.folder().getFolder(fid);
|
||||||
|
if (folder.account == null) // outbox
|
||||||
|
return;
|
||||||
|
EntityAccount account = db.account().getAccount(folder.account);
|
||||||
|
|
||||||
DB db = DB.getInstance(context);
|
if (imessages == null) {
|
||||||
EntityFolder folder = db.folder().getFolder(fid);
|
Properties props = MessageHelper.getSessionProperties(account.auth_type);
|
||||||
if (folder.account == null) // outbox
|
props.setProperty("mail.imap.throwsearchexception", "true");
|
||||||
return;
|
Session isession = Session.getInstance(props, null);
|
||||||
EntityAccount account = db.account().getAccount(folder.account);
|
|
||||||
|
|
||||||
if (imessages == null) {
|
Log.i(Helper.TAG, "Boundary connecting account=" + account.name);
|
||||||
Properties props = MessageHelper.getSessionProperties(account.auth_type);
|
istore = (IMAPStore) isession.getStore("imaps");
|
||||||
props.setProperty("mail.imap.throwsearchexception", "true");
|
Helper.connect(context, istore, account);
|
||||||
Session isession = Session.getInstance(props, null);
|
|
||||||
|
|
||||||
Log.i(Helper.TAG, "Boundary connecting account=" + account.name);
|
Log.i(Helper.TAG, "Boundary opening folder=" + folder.name);
|
||||||
istore = (IMAPStore) isession.getStore("imaps");
|
ifolder = (IMAPFolder) istore.getFolder(folder.name);
|
||||||
Helper.connect(context, istore, account);
|
ifolder.open(Folder.READ_WRITE);
|
||||||
|
|
||||||
Log.i(Helper.TAG, "Boundary opening folder=" + folder.name);
|
Log.i(Helper.TAG, "Boundary searching=" + search);
|
||||||
ifolder = (IMAPFolder) istore.getFolder(folder.name);
|
if (search == null)
|
||||||
ifolder.open(Folder.READ_WRITE);
|
imessages = ifolder.getMessages();
|
||||||
|
else
|
||||||
|
imessages = ifolder.search(
|
||||||
|
new OrTerm(
|
||||||
|
new OrTerm(
|
||||||
|
new FromStringTerm(search),
|
||||||
|
new RecipientStringTerm(Message.RecipientType.TO, search)
|
||||||
|
),
|
||||||
|
new OrTerm(
|
||||||
|
new SubjectTerm(search),
|
||||||
|
new BodyTerm(search)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
Log.i(Helper.TAG, "Boundary found messages=" + imessages.length);
|
||||||
|
|
||||||
Log.i(Helper.TAG, "Boundary searching=" + search);
|
index = imessages.length - 1;
|
||||||
if (search == null)
|
}
|
||||||
imessages = ifolder.getMessages();
|
|
||||||
else
|
|
||||||
imessages = ifolder.search(
|
|
||||||
new OrTerm(
|
|
||||||
new OrTerm(
|
|
||||||
new FromStringTerm(search),
|
|
||||||
new RecipientStringTerm(Message.RecipientType.TO, search)
|
|
||||||
),
|
|
||||||
new OrTerm(
|
|
||||||
new SubjectTerm(search),
|
|
||||||
new BodyTerm(search)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
Log.i(Helper.TAG, "Boundary found messages=" + imessages.length);
|
|
||||||
|
|
||||||
index = imessages.length - 1;
|
int count = 0;
|
||||||
}
|
while (index >= 0 && count < pageSize) {
|
||||||
|
Log.i(Helper.TAG, "Boundary index=" + index);
|
||||||
|
int from = Math.max(0, index - (pageSize - count) + 1);
|
||||||
|
Message[] isub = Arrays.copyOfRange(imessages, from, index + 1);
|
||||||
|
index -= (pageSize - count);
|
||||||
|
|
||||||
int count = 0;
|
FetchProfile fp = new FetchProfile();
|
||||||
while (index >= 0 && count < pageSize) {
|
fp.add(FetchProfile.Item.ENVELOPE);
|
||||||
Log.i(Helper.TAG, "Boundary index=" + index);
|
fp.add(FetchProfile.Item.FLAGS);
|
||||||
int from = Math.max(0, index - (pageSize - count) + 1);
|
fp.add(FetchProfile.Item.CONTENT_INFO); // body structure
|
||||||
Message[] isub = Arrays.copyOfRange(imessages, from, index + 1);
|
fp.add(UIDFolder.FetchProfileItem.UID);
|
||||||
index -= (pageSize - count);
|
fp.add(IMAPFolder.FetchProfileItem.HEADERS);
|
||||||
|
fp.add(FetchProfile.Item.SIZE);
|
||||||
|
fp.add(IMAPFolder.FetchProfileItem.INTERNALDATE);
|
||||||
|
ifolder.fetch(isub, fp);
|
||||||
|
|
||||||
FetchProfile fp = new FetchProfile();
|
try {
|
||||||
fp.add(FetchProfile.Item.ENVELOPE);
|
db.beginTransaction();
|
||||||
fp.add(FetchProfile.Item.FLAGS);
|
|
||||||
fp.add(FetchProfile.Item.CONTENT_INFO); // body structure
|
|
||||||
fp.add(UIDFolder.FetchProfileItem.UID);
|
|
||||||
fp.add(IMAPFolder.FetchProfileItem.HEADERS);
|
|
||||||
fp.add(FetchProfile.Item.SIZE);
|
|
||||||
fp.add(IMAPFolder.FetchProfileItem.INTERNALDATE);
|
|
||||||
ifolder.fetch(isub, fp);
|
|
||||||
|
|
||||||
try {
|
for (int j = isub.length - 1; j >= 0; j--)
|
||||||
db.beginTransaction();
|
try {
|
||||||
|
long uid = ifolder.getUID(isub[j]);
|
||||||
for (int j = isub.length - 1; j >= 0; j--)
|
Log.i(Helper.TAG, "Boundary sync uid=" + uid);
|
||||||
try {
|
EntityMessage message = db.message().getMessageByUid(fid, uid, search != null);
|
||||||
long uid = ifolder.getUID(isub[j]);
|
if (message == null) {
|
||||||
Log.i(Helper.TAG, "Boundary sync uid=" + uid);
|
|
||||||
ServiceSynchronize.synchronizeMessage(context, folder, ifolder, (IMAPMessage) isub[j], search != null);
|
ServiceSynchronize.synchronizeMessage(context, folder, ifolder, (IMAPMessage) isub[j], search != null);
|
||||||
count++;
|
count++;
|
||||||
loaded++;
|
loaded++;
|
||||||
} catch (MessageRemovedException ex) {
|
|
||||||
Log.w(Helper.TAG, "Boundary " + ex + "\n" + Log.getStackTraceString(ex));
|
|
||||||
} catch (FolderClosedException ex) {
|
|
||||||
throw ex;
|
|
||||||
} catch (FolderClosedIOException ex) {
|
|
||||||
throw ex;
|
|
||||||
} catch (Throwable ex) {
|
|
||||||
Log.e(Helper.TAG, "Boundary " + ex + "\n" + Log.getStackTraceString(ex));
|
|
||||||
} finally {
|
|
||||||
((IMAPMessage) isub[j]).invalidateHeaders();
|
|
||||||
}
|
}
|
||||||
|
} catch (MessageRemovedException ex) {
|
||||||
|
Log.w(Helper.TAG, "Boundary " + ex + "\n" + Log.getStackTraceString(ex));
|
||||||
|
} catch (FolderClosedException ex) {
|
||||||
|
throw ex;
|
||||||
|
} catch (FolderClosedIOException ex) {
|
||||||
|
throw ex;
|
||||||
|
} catch (Throwable ex) {
|
||||||
|
Log.e(Helper.TAG, "Boundary " + ex + "\n" + Log.getStackTraceString(ex));
|
||||||
|
} finally {
|
||||||
|
((IMAPMessage) isub[j]).invalidateHeaders();
|
||||||
|
}
|
||||||
|
|
||||||
db.setTransactionSuccessful();
|
db.setTransactionSuccessful();
|
||||||
} finally {
|
} finally {
|
||||||
db.endTransaction();
|
db.endTransaction();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.i(Helper.TAG, "Boundary done");
|
|
||||||
} finally {
|
|
||||||
searching = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Log.i(Helper.TAG, "Boundary done");
|
||||||
}
|
}
|
||||||
|
|
||||||
void clear() {
|
void clear() {
|
||||||
|
|
Loading…
Add table
Reference in a new issue