diff --git a/src/com/fsck/k9/Account.java b/src/com/fsck/k9/Account.java index bf563c839..b885b7378 100644 --- a/src/com/fsck/k9/Account.java +++ b/src/com/fsck/k9/Account.java @@ -79,9 +79,6 @@ public class Account private String mExpungePolicy = EXPUNGE_IMMEDIATELY; private int mMaxPushFolders; private Map compressionMap = new ConcurrentHashMap(); - // Tracks if we have sent a notification for this account for - // current set of fetched messages - private boolean mRingNotified; private List identities; @@ -547,20 +544,7 @@ public class Account mVibrate = vibrate; } - - - /* Have we sent a new mail notification on this account */ - public boolean isRingNotified() - { - return mRingNotified; - } - - public void setRingNotified(boolean ringNotified) - { - mRingNotified = ringNotified; - } - - public synchronized String getRingtone() + public synchronized String getRingtone() { return mRingtoneUri; } diff --git a/src/com/fsck/k9/MessagingController.java b/src/com/fsck/k9/MessagingController.java index 2654c1f83..2543b817d 100644 --- a/src/com/fsck/k9/MessagingController.java +++ b/src/com/fsck/k9/MessagingController.java @@ -1330,8 +1330,10 @@ public class MessagingController implements Runnable } // Send a notification of this message - if (notifyAccount(mApplication, account, message) == true) + if (!message.isSet(Flag.SEEN) && + (account.isNotifySelfNewMail() || account.isAnIdentity(message.getFrom()) == false)) { + notifyAccount(mApplication, account, message); newMessages.incrementAndGet(); } @@ -1423,7 +1425,6 @@ public class MessagingController implements Runnable l.synchronizeMailboxNewMessage(account, folder, localMessage); } } - notifyAccount(mApplication, account, message); } catch (MessagingException me) @@ -1551,7 +1552,6 @@ public class MessagingController implements Runnable l.synchronizeMailboxNewMessage(account, folder, localMessage); } } - notifyAccount(mApplication, account, message); }//for large messsages if (K9.DEBUG) Log.d(K9.LOG_TAG, "SYNC: Done fetching large messages for folder " + folder); @@ -3901,6 +3901,8 @@ public class MessagingController implements Runnable { if (K9.DEBUG) Log.i(K9.LOG_TAG, "Skipping synchronizing account " + account.getDescription()); + + continue; } @@ -4167,16 +4169,12 @@ public class MessagingController implements Runnable } /** Creates a notification of new email messages - * ringtone, lights, and vibration to be played + * ringtone, lights, and vibration to be played */ - private boolean notifyAccount(Context context, Account account, Message message) + private void notifyAccount(Context context, Account account, Message message) { - // Do not notify if the user does not have notifications - // enabled or if the message has been read - if (!account.isNotifyNewMail() || message.isSet(Flag.SEEN)) - { - return false; - } + if (!account.isNotifyNewMail()) + return; // If we have a message, set the notification to ": " StringBuffer messageNotice = new StringBuffer(); @@ -4184,8 +4182,8 @@ public class MessagingController implements Runnable { if (message != null && message.getFrom() != null) { - Address[] fromAddrs = message.getFrom(); - String from = fromAddrs.length > 0 ? fromAddrs[0].toFriendly() : null; + Address[] addrs = message.getFrom(); + String from = addrs.length > 0 ? addrs[0].toFriendly() : null; String subject = message.getSubject(); if (subject == null) { @@ -4194,20 +4192,13 @@ public class MessagingController implements Runnable if (from != null) { - // Show From: address by default - if (account.isAnIdentity(fromAddrs) == false) + // Show From: address, except show To: if sent from me + if (account.isAnIdentity(message.getFrom()) == false) { messageNotice.append(from + ": " + subject); } - // show To: if the message was sent from me else { - // Do not notify of mail from self if !isNotifySelfNewMail - if (!account.isNotifySelfNewMail()) - { - return false; - } - Address[] rcpts = message.getRecipients(Message.RecipientType.TO); String to = rcpts.length > 0 ? rcpts[0].toFriendly() : null; if (to != null) @@ -4256,29 +4247,23 @@ public class MessagingController implements Runnable String accountNotice = context.getString(R.string.notification_new_one_account_fmt, unreadMessageCount, account.getDescription()); notif.setLatestEventInfo(context, accountNotice, messageNotice, pi); - // Only ring or vibrate if we have not done so already on this - // account and fetch - if (!account.isRingNotified()) + if (account.isRing()) { - account.setRingNotified(true); - if (account.isRing()) - { - String ringtone = account.getRingtone(); - notif.sound = TextUtils.isEmpty(ringtone) ? null : Uri.parse(ringtone); - } - if (account.isVibrate()) - { - notif.defaults |= Notification.DEFAULT_VIBRATE; - } + String ringtone = account.getRingtone(); + notif.sound = TextUtils.isEmpty(ringtone) ? null : Uri.parse(ringtone); } - notif.flags |= Notification.FLAG_SHOW_LIGHTS; + if (account.isVibrate()) + { + notif.defaults |= Notification.DEFAULT_VIBRATE; + } + + notif.flags |= Notification.FLAG_SHOW_LIGHTS | Notification.FLAG_ONLY_ALERT_ONCE; notif.ledARGB = K9.NOTIFICATION_LED_COLOR; notif.ledOnMS = K9.NOTIFICATION_LED_ON_TIME; notif.ledOffMS = K9.NOTIFICATION_LED_OFF_TIME; notifMgr.notify(account.getAccountNumber(), notif); - return true; } /** Cancel a notification of new email messages */ @@ -4580,7 +4565,6 @@ public class MessagingController implements Runnable localFolder= localStore.getFolder(remoteFolder.getName()); localFolder.open(OpenMode.READ_WRITE); - account.setRingNotified(false); int newCount = downloadMessages(account, remoteFolder, localFolder, messages, flagSyncOnly); int unreadMessageCount = setLocalUnreadCountToRemote(localFolder, remoteFolder, messages.size()); diff --git a/src/com/fsck/k9/service/PollService.java b/src/com/fsck/k9/service/PollService.java index 19c193302..27cc61ff5 100644 --- a/src/com/fsck/k9/service/PollService.java +++ b/src/com/fsck/k9/service/PollService.java @@ -159,8 +159,6 @@ public class PollService extends CoreService if (K9.DEBUG) Log.v(K9.LOG_TAG, "***** PollService *****: checkMailFinished"); - // Reset RingNotified so the next new mail will notify - account.setRingNotified(false); release(); } public int getStartId()