Fixes Issue 957
Fixes Issue 868 May not be perfect, either, but may help in some situations with getting all emails to arrive via push.
This commit is contained in:
parent
3c7eea7fa5
commit
d08c9d6ce2
1 changed files with 44 additions and 16 deletions
|
@ -2416,7 +2416,7 @@ public class ImapStore extends Store
|
||||||
|
|
||||||
class ImapMessage extends MimeMessage
|
class ImapMessage extends MimeMessage
|
||||||
{
|
{
|
||||||
ImapMessage(String uid, Folder folder) throws MessagingException
|
ImapMessage(String uid, Folder folder)
|
||||||
{
|
{
|
||||||
this.mUid = uid;
|
this.mUid = uid;
|
||||||
this.mFolder = folder;
|
this.mFolder = folder;
|
||||||
|
@ -2716,7 +2716,7 @@ public class ImapStore extends Store
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void processUntaggedResponses(List<ImapResponse> responses)
|
protected void processUntaggedResponses(List<ImapResponse> responses) throws MessagingException
|
||||||
{
|
{
|
||||||
boolean skipSync = false;
|
boolean skipSync = false;
|
||||||
int oldMessageCount = mMessageCount;
|
int oldMessageCount = mMessageCount;
|
||||||
|
@ -2738,7 +2738,7 @@ public class ImapStore extends Store
|
||||||
}
|
}
|
||||||
if (mMessageCount > oldMessageCount)
|
if (mMessageCount > oldMessageCount)
|
||||||
{
|
{
|
||||||
syncMessages(oldMessageCount + 1, mMessageCount, true);
|
syncMessages(mMessageCount, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (K9.DEBUG)
|
if (K9.DEBUG)
|
||||||
|
@ -2750,25 +2750,53 @@ public class ImapStore extends Store
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void syncMessages(int start, int end, boolean newArrivals)
|
private void syncMessages(int end, boolean newArrivals) throws MessagingException
|
||||||
{
|
{
|
||||||
|
int oldUidNext = -1;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Message[] messageArray = null;
|
String pushStateS = receiver.getPushState(getName());
|
||||||
|
ImapPushState pushState = ImapPushState.parse(pushStateS);
|
||||||
messageArray = getMessages(start, end, true, null);
|
oldUidNext = pushState.uidNext;
|
||||||
|
if (K9.DEBUG)
|
||||||
List<Message> messages = new ArrayList<Message>();
|
Log.i(K9.LOG_TAG, "Got oldUidNext " + oldUidNext + " for " + getLogId());
|
||||||
for (Message message : messageArray)
|
|
||||||
{
|
|
||||||
messages.add(message);
|
|
||||||
}
|
|
||||||
pushMessages(messages, newArrivals);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
receiver.pushError("Exception while processing Push untagged responses", e);
|
Log.e(K9.LOG_TAG, "Unable to get oldUidNext for " + getLogId(), e);
|
||||||
|
}
|
||||||
|
|
||||||
|
Message[] messageArray = getMessages(end, end, true, null);
|
||||||
|
if (messageArray != null && messageArray.length > 0)
|
||||||
|
{
|
||||||
|
int newUid = Integer.parseInt(messageArray[0].getUid());
|
||||||
|
if (K9.DEBUG)
|
||||||
|
Log.i(K9.LOG_TAG, "Got newUid " + newUid + " for message " + end + " on " + getLogId());
|
||||||
|
int startUid = oldUidNext;
|
||||||
|
if (startUid < newUid - 10)
|
||||||
|
{
|
||||||
|
startUid = newUid - 10;
|
||||||
|
}
|
||||||
|
if (startUid < 1)
|
||||||
|
{
|
||||||
|
startUid = 1;
|
||||||
|
}
|
||||||
|
if (newUid >= startUid)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (K9.DEBUG)
|
||||||
|
Log.i(K9.LOG_TAG, "Needs sync from uid " + startUid + " to " + newUid + " for " + getLogId());
|
||||||
|
List<Message> messages = new ArrayList<Message>();
|
||||||
|
for (int uid = startUid; uid <= newUid; uid++)
|
||||||
|
{
|
||||||
|
ImapMessage message = new ImapMessage("" + uid, ImapFolderPusher.this);
|
||||||
|
messages.add(message);
|
||||||
|
}
|
||||||
|
if (messages.size() > 0)
|
||||||
|
{
|
||||||
|
pushMessages(messages, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue