mirror of
https://github.com/moparisthebest/k-9
synced 2024-12-24 08:38:51 -05:00
Use a heuristic to try to avoid notifying POP3 users about older mail
messages
This commit is contained in:
parent
7858f72c53
commit
22f422ea29
@ -78,6 +78,7 @@ public class Account implements BaseAccount
|
||||
private int mDisplayCount;
|
||||
private int mChipColor;
|
||||
private long mLastAutomaticCheckTime;
|
||||
private long mLatestOldMessageSeenTime;
|
||||
private boolean mNotifyNewMail;
|
||||
private boolean mNotifySelfNewMail;
|
||||
private String mDraftsFolderName;
|
||||
@ -257,14 +258,11 @@ public class Account implements BaseAccount
|
||||
{
|
||||
mDisplayCount = K9.DEFAULT_VISIBLE_LIMIT;
|
||||
}
|
||||
mLastAutomaticCheckTime = prefs.getLong(mUuid
|
||||
+ ".lastAutomaticCheckTime", 0);
|
||||
mNotifyNewMail = prefs.getBoolean(mUuid + ".notifyNewMail",
|
||||
false);
|
||||
mNotifySelfNewMail = prefs.getBoolean(mUuid + ".notifySelfNewMail",
|
||||
true);
|
||||
mNotifySync = prefs.getBoolean(mUuid + ".notifyMailCheck",
|
||||
false);
|
||||
mLastAutomaticCheckTime = prefs.getLong(mUuid + ".lastAutomaticCheckTime", 0);
|
||||
mLatestOldMessageSeenTime = prefs.getLong(mUuid +".latestOldMessageSeenTime",0);
|
||||
mNotifyNewMail = prefs.getBoolean(mUuid + ".notifyNewMail", false);
|
||||
mNotifySelfNewMail = prefs.getBoolean(mUuid + ".notifySelfNewMail", true);
|
||||
mNotifySync = prefs.getBoolean(mUuid + ".notifyMailCheck", false);
|
||||
mDeletePolicy = prefs.getInt(mUuid + ".deletePolicy", 0);
|
||||
mDraftsFolderName = prefs.getString(mUuid + ".draftsFolderName",
|
||||
"Drafts");
|
||||
@ -445,6 +443,7 @@ public class Account implements BaseAccount
|
||||
editor.remove(mUuid + ".saveAllHeaders");
|
||||
editor.remove(mUuid + ".idleRefreshMinutes");
|
||||
editor.remove(mUuid + ".lastAutomaticCheckTime");
|
||||
editor.remove(mUuid + ".latestOldMessageSeenTime");
|
||||
editor.remove(mUuid + ".notifyNewMail");
|
||||
editor.remove(mUuid + ".notifySelfNewMail");
|
||||
editor.remove(mUuid + ".deletePolicy");
|
||||
@ -546,6 +545,7 @@ public class Account implements BaseAccount
|
||||
editor.putBoolean(mUuid + ".pushPollOnConnect", mPushPollOnConnect);
|
||||
editor.putInt(mUuid + ".displayCount", mDisplayCount);
|
||||
editor.putLong(mUuid + ".lastAutomaticCheckTime", mLastAutomaticCheckTime);
|
||||
editor.putLong(mUuid + ".latestOldMessageSeenTime", mLatestOldMessageSeenTime);
|
||||
editor.putBoolean(mUuid + ".notifyNewMail", mNotifyNewMail);
|
||||
editor.putBoolean(mUuid + ".notifySelfNewMail", mNotifySelfNewMail);
|
||||
editor.putBoolean(mUuid + ".notifyMailCheck", mNotifySync);
|
||||
@ -850,6 +850,16 @@ public class Account implements BaseAccount
|
||||
this.mLastAutomaticCheckTime = lastAutomaticCheckTime;
|
||||
}
|
||||
|
||||
public synchronized long getLatestOldMessageSeenTime()
|
||||
{
|
||||
return mLatestOldMessageSeenTime;
|
||||
}
|
||||
|
||||
public synchronized void setLatestOldMessageSeenTime(long latestOldMessageSeenTime)
|
||||
{
|
||||
this.mLatestOldMessageSeenTime = latestOldMessageSeenTime;
|
||||
}
|
||||
|
||||
public synchronized boolean isNotifyNewMail()
|
||||
{
|
||||
return mNotifyNewMail;
|
||||
|
@ -1396,6 +1396,9 @@ public class MessagingController implements Runnable
|
||||
final LocalFolder localFolder, List<Message> inputMessages, boolean flagSyncOnly) throws MessagingException
|
||||
{
|
||||
final Date earliestDate = account.getEarliestPollDate();
|
||||
Date downloadStarted = new Date(); // now
|
||||
|
||||
|
||||
if (earliestDate != null)
|
||||
{
|
||||
if (K9.DEBUG)
|
||||
@ -1540,6 +1543,25 @@ public class MessagingController implements Runnable
|
||||
|
||||
});
|
||||
|
||||
// If the oldest message seen on this sync is newer than
|
||||
// the oldest message seen on the previous sync, then
|
||||
// we want to move our high-water mark forward
|
||||
// this is all here just for pop which only syncs inbox
|
||||
// this would be a little wrong for IMAP (we'd want a folder-level pref, not an account level pref.)
|
||||
// fortunately, we just don't care.
|
||||
Long oldestMessageTime = localFolder.getOldestMessageDate();
|
||||
|
||||
if (oldestMessageTime != null)
|
||||
{
|
||||
Date oldestExtantMessage = new Date(oldestMessageTime);
|
||||
if (oldestExtantMessage.before(downloadStarted) &&
|
||||
oldestExtantMessage.after(new Date(account.getLatestOldMessageSeenTime())))
|
||||
{
|
||||
account.setLatestOldMessageSeenTime(oldestExtantMessage.getTime());
|
||||
account.save(Preferences.getPreferences(mApplication.getApplicationContext()));
|
||||
}
|
||||
|
||||
}
|
||||
return newMessages.get();
|
||||
}
|
||||
private void evaluateMessageForDownload(final Message message, final String folder,
|
||||
@ -4693,6 +4715,17 @@ public class MessagingController implements Runnable
|
||||
return false;
|
||||
}
|
||||
|
||||
// If the account us a POP3 account and the message is older than
|
||||
// the oldest message we've previously seen then don't notify about it
|
||||
if (account.getStoreUri().startsWith("pop3") )
|
||||
{
|
||||
if ( message.olderThan(new Date(account.getLatestOldMessageSeenTime())))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// If we have a message, set the notification to "<From>: <Subject>"
|
||||
StringBuilder messageNotice = new StringBuilder();
|
||||
final KeyguardManager keyguardService = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
|
||||
|
@ -3281,6 +3281,41 @@ public class LocalStore extends Store implements Serializable
|
||||
Log.d(K9.LOG_TAG, "Updated last UID for folder " + mName + " to " + lastUid);
|
||||
mLastUid = lastUid;
|
||||
}
|
||||
|
||||
public long getOldestMessageDate() throws MessagingException
|
||||
{
|
||||
return database.execute(false, new DbCallback<Long>()
|
||||
{
|
||||
@Override
|
||||
public Long doDbWork(final SQLiteDatabase db)
|
||||
{
|
||||
Cursor cursor = null;
|
||||
try
|
||||
{
|
||||
open(OpenMode.READ_ONLY);
|
||||
cursor = db.rawQuery("SELECT MIN(date) FROM messages WHERE folder_id=?", new String[] { Long.toString(mFolderId) });
|
||||
if (cursor.getCount() > 0)
|
||||
{
|
||||
cursor.moveToFirst();
|
||||
return cursor.getLong(0);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.e(K9.LOG_TAG, "Unable to fetch oldest message date: ", e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (cursor != null)
|
||||
{
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class LocalTextBody extends TextBody
|
||||
|
Loading…
Reference in New Issue
Block a user