1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-02 00:25:10 -04:00

Provide for doing a full poll/sync of a folder whenever the IMAP IDLE

connection is established.  Turned off for now, but just get rid of
the false && on line 2641 in order to enable it.
This commit is contained in:
Daniel Applebaum 2010-04-27 03:02:17 +00:00
parent 02f4d08396
commit 78a101547c
3 changed files with 49 additions and 8 deletions

View File

@ -14,6 +14,7 @@ import com.fsck.k9.mail.store.LocalStore.LocalFolder;
import com.fsck.k9.service.SleepService; import com.fsck.k9.service.SleepService;
import java.util.List; import java.util.List;
import java.util.concurrent.CountDownLatch;
public class MessagingControllerPushReceiver implements PushReceiver public class MessagingControllerPushReceiver implements PushReceiver
{ {
@ -75,6 +76,37 @@ public class MessagingControllerPushReceiver implements PushReceiver
controller.messagesArrived(account, folder, messages, false); controller.messagesArrived(account, folder, messages, false);
} }
public void syncFolder(Folder folder)
{
Log.i(K9.LOG_TAG, "syncFolder(" + folder.getName() + ")");
final CountDownLatch latch = new CountDownLatch(1);
controller.synchronizeMailbox(account, folder.getName(), new MessagingListener()
{
public void synchronizeMailboxFinished(Account account, String folder,
int totalMessagesInMailbox, int numNewMessages)
{
latch.countDown();
}
public void synchronizeMailboxFailed(Account account, String folder,
String message)
{
latch.countDown();
}
});
Log.i(K9.LOG_TAG, "syncFolder(" + folder.getName() + ") about to await latch release");
try
{
latch.await();
Log.i(K9.LOG_TAG, "syncFolder(" + folder.getName() + ") got latch release");
}
catch (Exception e)
{
Log.e(K9.LOG_TAG, "Interrupted while awaiting latch release", e);
}
}
public void sleep(long millis) public void sleep(long millis)
{ {
SleepService.sleep(mApplication, millis, threadWakeLock.get(), K9.PUSH_WAKE_LOCK_TIMEOUT); SleepService.sleep(mApplication, millis, threadWakeLock.get(), K9.PUSH_WAKE_LOCK_TIMEOUT);

View File

@ -6,6 +6,7 @@ public interface PushReceiver
{ {
public void acquireWakeLock(); public void acquireWakeLock();
public void releaseWakeLock(); public void releaseWakeLock();
public void syncFolder(Folder folder);
public void messagesArrived(Folder folder, List<Message> mess); public void messagesArrived(Folder folder, List<Message> mess);
public void messagesFlagsChanged(Folder folder, List<Message> mess); public void messagesFlagsChanged(Folder folder, List<Message> mess);
public String getPushState(String folderName); public String getPushState(String folderName);

View File

@ -1094,7 +1094,10 @@ public class ImapStore extends Store
if (o != null && o instanceof Part) if (o != null && o instanceof Part)
{ {
Part part = (Part) o; Part part = (Part) o;
String partId = part.getHeader(MimeHeader.HEADER_ANDROID_ATTACHMENT_STORE_DATA)[0]; String[] parts = part.getHeader(MimeHeader.HEADER_ANDROID_ATTACHMENT_STORE_DATA);
if (parts != null)
{
String partId = parts[0];
if ("TEXT".equals(partId)) if ("TEXT".equals(partId))
{ {
fetchFields.add(String.format("BODY.PEEK[TEXT]<0.%d>", FETCH_BODY_SANE_SUGGESTED_SIZE)); fetchFields.add(String.format("BODY.PEEK[TEXT]<0.%d>", FETCH_BODY_SANE_SUGGESTED_SIZE));
@ -1105,6 +1108,7 @@ public class ImapStore extends Store
} }
} }
} }
}
try try
{ {
@ -2615,7 +2619,7 @@ public class ImapStore extends Store
{ {
Log.e(K9.LOG_TAG, "Unable to get oldUidNext for " + getLogId(), e); Log.e(K9.LOG_TAG, "Unable to get oldUidNext for " + getLogId(), e);
} }
ImapConnection oldConnection = mConnection;
List<ImapResponse> responses = internalOpen(OpenMode.READ_ONLY); List<ImapResponse> responses = internalOpen(OpenMode.READ_ONLY);
if (mConnection == null) if (mConnection == null)
{ {
@ -2634,6 +2638,10 @@ public class ImapStore extends Store
{ {
handleUntaggedResponses(responses); handleUntaggedResponses(responses);
} }
if (false && mConnection != oldConnection)
{
receiver.syncFolder(ImapFolderPusher.this);
}
int startUid = oldUidNext; int startUid = oldUidNext;
if (startUid < uidNext - mAccount.getDisplayCount()) if (startUid < uidNext - mAccount.getDisplayCount())
{ {