Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 95c546d9 authored by cketti's avatar cketti Committed by GitHub
Browse files

Merge pull request #1485 from k9mail/notifications_only_from_contacts

Setting: only show notifications for messages from contacts
parents fcf6e9e9 1d471a86
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -181,6 +181,7 @@ public class Account implements BaseAccount, StoreConfig {
    private boolean mNotifyNewMail;
    private FolderMode mFolderNotifyNewMailMode;
    private boolean mNotifySelfNewMail;
    private boolean mNotifyContactsMailOnly;
    private String mInboxFolderName;
    private String mDraftsFolderName;
    private String mSentFolderName;
@@ -289,6 +290,7 @@ public class Account implements BaseAccount, StoreConfig {
        mFolderNotifyNewMailMode = FolderMode.ALL;
        mNotifySync = true;
        mNotifySelfNewMail = true;
        mNotifyContactsMailOnly = false;
        mFolderDisplayMode = FolderMode.NOT_SECOND_CLASS;
        mFolderSyncMode = FolderMode.FIRST_CLASS;
        mFolderPushMode = FolderMode.FIRST_CLASS;
@@ -397,6 +399,7 @@ public class Account implements BaseAccount, StoreConfig {

        mFolderNotifyNewMailMode = getEnumStringPref(storage, mUuid + ".folderNotifyNewMailMode", FolderMode.ALL);
        mNotifySelfNewMail = storage.getBoolean(mUuid + ".notifySelfNewMail", true);
        mNotifyContactsMailOnly = storage.getBoolean(mUuid + ".notifyContactsMailOnly", false);
        mNotifySync = storage.getBoolean(mUuid + ".notifyMailCheck", false);
        mDeletePolicy =  DeletePolicy.fromInt(storage.getInt(mUuid + ".deletePolicy", DeletePolicy.NEVER.setting));
        mInboxFolderName = storage.getString(mUuid  + ".inboxFolderName", INBOX);
@@ -684,6 +687,7 @@ public class Account implements BaseAccount, StoreConfig {
        editor.putBoolean(mUuid + ".notifyNewMail", mNotifyNewMail);
        editor.putString(mUuid + ".folderNotifyNewMailMode", mFolderNotifyNewMailMode.name());
        editor.putBoolean(mUuid + ".notifySelfNewMail", mNotifySelfNewMail);
        editor.putBoolean(mUuid + ".notifyContactsMailOnly", mNotifyContactsMailOnly);
        editor.putBoolean(mUuid + ".notifyMailCheck", mNotifySync);
        editor.putInt(mUuid + ".deletePolicy", mDeletePolicy.setting);
        editor.putString(mUuid + ".inboxFolderName", mInboxFolderName);
@@ -1252,6 +1256,14 @@ public class Account implements BaseAccount, StoreConfig {
        mNotifySelfNewMail = notifySelfNewMail;
    }

    public synchronized boolean isNotifyContactsMailOnly() {
        return mNotifyContactsMailOnly;
    }

    public synchronized void setNotifyContactsMailOnly(boolean notifyContactsMailOnly) {
        this.mNotifyContactsMailOnly = notifyContactsMailOnly;
    }

    public synchronized Expunge getExpungePolicy() {
        return mExpungePolicy;
    }
+6 −0
Original line number Diff line number Diff line
@@ -78,6 +78,7 @@ public class AccountSettings extends K9PreferenceActivity {
    private static final String PREFERENCE_NOTIFY = "account_notify";
    private static final String PREFERENCE_NOTIFY_NEW_MAIL_MODE = "folder_notify_new_mail_mode";
    private static final String PREFERENCE_NOTIFY_SELF = "account_notify_self";
    private static final String PREFERENCE_NOTIFY_CONTACTS_MAIL_ONLY = "account_notify_contacts_mail_only";
    private static final String PREFERENCE_NOTIFY_SYNC = "account_notify_sync";
    private static final String PREFERENCE_VIBRATE = "account_vibrate";
    private static final String PREFERENCE_VIBRATE_PATTERN = "account_vibrate_pattern";
@@ -146,6 +147,7 @@ public class AccountSettings extends K9PreferenceActivity {
    private CheckBoxPreference mAccountNotify;
    private ListPreference mAccountNotifyNewMailMode;
    private CheckBoxPreference mAccountNotifySelf;
    private CheckBoxPreference mAccountNotifyContactsMailOnly;
    private ListPreference mAccountShowPictures;
    private CheckBoxPreference mAccountNotifySync;
    private CheckBoxPreference mAccountVibrate;
@@ -590,6 +592,9 @@ public class AccountSettings extends K9PreferenceActivity {
        mAccountNotifySelf = (CheckBoxPreference) findPreference(PREFERENCE_NOTIFY_SELF);
        mAccountNotifySelf.setChecked(mAccount.isNotifySelfNewMail());

        mAccountNotifyContactsMailOnly = (CheckBoxPreference) findPreference(PREFERENCE_NOTIFY_CONTACTS_MAIL_ONLY);
        mAccountNotifyContactsMailOnly.setChecked(mAccount.isNotifyContactsMailOnly());

        mAccountNotifySync = (CheckBoxPreference) findPreference(PREFERENCE_NOTIFY_SYNC);
        mAccountNotifySync.setChecked(mAccount.isShowOngoing());

@@ -753,6 +758,7 @@ public class AccountSettings extends K9PreferenceActivity {
        mAccount.setNotifyNewMail(mAccountNotify.isChecked());
        mAccount.setFolderNotifyNewMailMode(FolderMode.valueOf(mAccountNotifyNewMailMode.getValue()));
        mAccount.setNotifySelfNewMail(mAccountNotifySelf.isChecked());
        mAccount.setNotifyContactsMailOnly(mAccountNotifyContactsMailOnly.isChecked());
        mAccount.setShowOngoing(mAccountNotifySync.isChecked());
        mAccount.setDisplayCount(Integer.parseInt(mDisplayCount.getValue()));
        mAccount.setMaximumAutoDownloadMessageSize(Integer.parseInt(mMessageSize.getValue()));
+11 −2
Original line number Diff line number Diff line
@@ -55,6 +55,7 @@ import com.fsck.k9.R;
import com.fsck.k9.activity.MessageReference;
import com.fsck.k9.activity.setup.AccountSetupCheckSettings.CheckDirection;
import com.fsck.k9.cache.EmailProviderCache;
import com.fsck.k9.helper.Contacts;
import com.fsck.k9.mail.Address;
import com.fsck.k9.mail.AuthenticationFailedException;
import com.fsck.k9.mail.CertificateValidationException;
@@ -151,6 +152,7 @@ public class MessagingController implements Runnable {

    private final Context context;
    private final NotificationController notificationController;
    private final Contacts contacts;
    private volatile boolean stopped = false;

    private static final Set<Flag> SYNC_FLAGS = EnumSet.of(Flag.SEEN, Flag.FLAGGED, Flag.ANSWERED, Flag.FORWARDED);
@@ -209,9 +211,11 @@ public class MessagingController implements Runnable {


    @VisibleForTesting
    MessagingController(Context context, NotificationController notificationController) {
    MessagingController(Context context, NotificationController notificationController, Contacts contacts) {
        this.context = context;
        this.notificationController = notificationController;
        this.contacts = contacts;

        mThread = new Thread(this);
        mThread.setName("MessagingController");
        mThread.start();
@@ -231,7 +235,8 @@ public class MessagingController implements Runnable {
        if (inst == null) {
            Context appContext = context.getApplicationContext();
            NotificationController notificationController = NotificationController.newInstance(appContext);
            inst = new MessagingController(appContext, notificationController);
            Contacts contacts = Contacts.getInstance(context);
            inst = new MessagingController(appContext, notificationController, contacts);
        }
        return inst;
    }
@@ -4225,6 +4230,10 @@ public class MessagingController implements Runnable {
            return false;
        }

        if (account.isNotifyContactsMailOnly() && !contacts.isAnyInContacts(message.getFrom())) {
            return false;
        }

        return true;
    }

+20 −0
Original line number Diff line number Diff line
@@ -141,6 +141,26 @@ public class Contacts {
        return result;
    }

    /**
     * Check whether one of the provided addresses belongs to one of the contacts.
     *
     * @param addresses The addresses to search in contacts
     * @return <tt>true</tt>, if one address belongs to a contact.
     *         <tt>false</tt>, otherwise.
     */
    public boolean isAnyInContacts(final Address[] addresses) {
        if (addresses == null) {
            return false;
        }

        for (Address addr : addresses) {
            if (isInContacts(addr.getAddress())) {
                return true;
            }
        }
        return false;
    }

    /**
     * Get the name of the contact an email address belongs to.
     *
+3 −0
Original line number Diff line number Diff line
@@ -224,6 +224,9 @@ public class AccountSettings {
        s.put("remoteSearchFullText", Settings.versions(
                new V(18, new BooleanSetting(false))
            ));
        s.put("notifyContactsMailOnly", Settings.versions(
                new V(42, new BooleanSetting(false))
            ));

        SETTINGS = Collections.unmodifiableMap(s);

Loading