diff --git a/src/com/android/email/Account.java b/src/com/android/email/Account.java index e239b4b91..c115255f7 100644 --- a/src/com/android/email/Account.java +++ b/src/com/android/email/Account.java @@ -42,6 +42,7 @@ public class Account implements Serializable { int mDisplayCount; long mLastAutomaticCheckTime; boolean mNotifyNewMail; + boolean mNotifySelfNewMail; String mDraftsFolderName; String mSentFolderName; String mTrashFolderName; @@ -86,6 +87,7 @@ public class Account implements Serializable { mNotifyNewMail = true; mNotifySync = true; mVibrate = false; + mNotifySelfNewMail = true; mFolderDisplayMode = FolderMode.NOT_SECOND_CLASS; mFolderSyncMode = FolderMode.FIRST_CLASS; mFolderPushMode = FolderMode.FIRST_CLASS; @@ -618,6 +620,23 @@ public class Account implements Serializable { } + public boolean isAnIdentity(Address[] addrs) + { + if (addrs == null) + { + return false; + } + for (Address addr : addrs) + { + if (findIdentity(addr) != null) + { + return true; + } + } + + return false; + } + public boolean isAnIdentity(Address addr) { return findIdentity(addr) != null; @@ -810,4 +829,14 @@ public class Account implements Serializable { this.mIsSignatureBeforeQuotedText = mIsSignatureBeforeQuotedText; } + public boolean isNotifySelfNewMail() + { + return mNotifySelfNewMail; + } + + public void setNotifySelfNewMail(boolean notifySelfNewMail) + { + mNotifySelfNewMail = notifySelfNewMail; + } + } diff --git a/src/com/android/email/MessagingController.java b/src/com/android/email/MessagingController.java index a12d5b620..86c2c5392 100644 --- a/src/com/android/email/MessagingController.java +++ b/src/com/android/email/MessagingController.java @@ -1119,7 +1119,10 @@ public class MessagingController implements Runnable { public void messageFinished(Message message, int number, int ofTotal) { try { if (!message.isSet(Flag.SEEN)) { - newMessages.incrementAndGet(); + if ( account.isNotifySelfNewMail() || account.isAnIdentity(message.getFrom()) == false) + { + newMessages.incrementAndGet(); + } } // Store the new message locally @@ -3325,14 +3328,16 @@ public class MessagingController implements Runnable { }); } - public void notifyAccount(Context context, Account thisAccount, int unreadMessageCount) + public void notifyAccount(Context context, Account thisAccount, int newMailCount, int unreadMessageCount) { + Log.i(Email.LOG_TAG, "notifyAccount Account " + thisAccount.getDescription() + ", newMailCount = " + newMailCount + + ", unreadMessageCount = " + unreadMessageCount); boolean isNotifyAccount = thisAccount.isNotifyNewMail(); if (isNotifyAccount) { NotificationManager notifMgr = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE); - if (unreadMessageCount > 0) + if (newMailCount > 0 && unreadMessageCount > 0) { String notice = context.getString(R.string.notification_new_one_account_fmt, unreadMessageCount, thisAccount.getDescription()); @@ -3744,7 +3749,7 @@ public class MessagingController implements Runnable { localFolder.open(OpenMode.READ_WRITE); remoteFolder.open(OpenMode.READ_WRITE); - downloadMessages(account, remoteFolder, localFolder, messages); + int newCount = downloadMessages(account, remoteFolder, localFolder, messages); int unreadCount = 0; for (Message message : messages) { @@ -3759,11 +3764,11 @@ public class MessagingController implements Runnable { int unreadMessageCount = account.getUnreadMessageCount(mApplication, mApplication); if (doNotify && unreadCount > 0) { - notifyAccount(mApplication, account, unreadMessageCount); + notifyAccount(mApplication, account, newCount, unreadMessageCount); } if (unreadCount == 0) { - notifyAccount(mApplication, account, unreadMessageCount); + notifyAccount(mApplication, account, newCount, unreadMessageCount); } for (MessagingListener l : getListeners()) diff --git a/src/com/android/email/service/PollService.java b/src/com/android/email/service/PollService.java index cd77ecff1..4e843cd1d 100644 --- a/src/com/android/email/service/PollService.java +++ b/src/com/android/email/service/PollService.java @@ -145,14 +145,9 @@ public class PollService extends CoreService try { int unreadMessageCount = thisAccount.getUnreadMessageCount(context, getApplication()); - if (unreadMessageCount > 0 && newMailCount > 0) - { - MessagingController.getInstance(getApplication()).notifyAccount(context, thisAccount, unreadMessageCount); - } - else if (unreadMessageCount == 0) - { - MessagingController.getInstance(getApplication()).notifyAccount(context, thisAccount, unreadMessageCount); - } + MessagingController.getInstance(getApplication()).notifyAccount(context, thisAccount, + newMailCount, unreadMessageCount); + } catch (MessagingException me) {