diff --git a/FAQ.md b/FAQ.md index f79d214e47..c4383920dc 100644 --- a/FAQ.md +++ b/FAQ.md @@ -3423,6 +3423,10 @@ This will enable learning mode only. Each folder has an option to enable automatic message classification. When this is turned on, new messages in other folders which the classifier thinks belong to that folder will be automatically moved. +The option *Use local spam filter* turns on message classification and auto classification for the spam folder. +Please understand that this is not a replacement for the spam filter of the email server. +See also [this FAQ](#user-content-faq92). + A practical example: suppose there is a folder 'marketing' and auto message classification is enabled for this folder. Each time you move a message into this folder you'll train FairEmail that similar messages belong in this folder. Each time you move a message out of this folder you'll train FairEmail that similar messages do not belong in this folder. diff --git a/app/src/main/java/eu/faircode/email/AdapterMessage.java b/app/src/main/java/eu/faircode/email/AdapterMessage.java index c3d4f5521a..75602d3fe5 100644 --- a/app/src/main/java/eu/faircode/email/AdapterMessage.java +++ b/app/src/main/java/eu/faircode/email/AdapterMessage.java @@ -6355,7 +6355,7 @@ public class AdapterMessage extends RecyclerView.Adapter() { + @Override + protected Void onExecute(Context context, Bundle args) throws Throwable { + long account = args.getLong("account"); + boolean filter = args.getBoolean("filter"); + + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); + + DB db = DB.getInstance(context); + EntityFolder junk = db.folder().getFolderByType(account, EntityFolder.JUNK); + if (junk != null) { + db.folder().setFolderAutoClassify(junk.id, filter); + prefs.edit().putBoolean("classification", true).apply(); + } + + return null; + } + + @Override + protected void onException(Bundle args, Throwable ex) { + Log.unexpectedError(getParentFragmentManager(), ex); + } + }.execute(FragmentDialogJunk.this, args, "junk:filter"); + } + }); + + ibInfoFilter.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Helper.viewFAQ(v.getContext(), 163); + } + }); + grpInJunk.setVisibility(inJunk ? View.GONE : View.VISIBLE); + new SimpleTask() { + @Override + protected void onPreExecute(Bundle args) { + cbJunkFilter.setEnabled(false); + } + + @Override + protected Boolean onExecute(Context context, Bundle args) throws Throwable { + long account = args.getLong("account"); + + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); + boolean classification = prefs.getBoolean("classification", false); + + DB db = DB.getInstance(context); + EntityFolder junk = db.folder().getFolderByType(account, EntityFolder.JUNK); + if (junk == null) + return false; + + return classification && junk.auto_classify; + } + + @Override + protected void onExecuted(Bundle args, Boolean filter) { + if (filter != null) { + cbJunkFilter.setChecked(filter); + cbJunkFilter.setEnabled(true); + } + } + + @Override + protected void onException(Bundle args, Throwable ex) { + Log.unexpectedError(getParentFragmentManager(), ex); + } + }.execute(FragmentDialogJunk.this, args, "junk:filter"); + return new AlertDialog.Builder(getContext()) .setView(view) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { diff --git a/app/src/main/java/eu/faircode/email/DaoFolder.java b/app/src/main/java/eu/faircode/email/DaoFolder.java index 51f606a150..33b26cde51 100644 --- a/app/src/main/java/eu/faircode/email/DaoFolder.java +++ b/app/src/main/java/eu/faircode/email/DaoFolder.java @@ -344,6 +344,9 @@ public interface DaoFolder { @Query("UPDATE folder SET poll_count = :count WHERE id = :id AND NOT (poll_count IS :count)") int setFolderPollCount(long id, int count); + @Query("UPDATE folder SET auto_classify = :auto_classify WHERE id = :id AND NOT (auto_classify IS :auto_classify)") + int setFolderAutoClassify(long id, boolean auto_classify); + @Query("DELETE FROM folder WHERE id = :id") void deleteFolder(long id); diff --git a/app/src/main/res/layout/dialog_junk.xml b/app/src/main/res/layout/dialog_junk.xml index c02a864afa..06b599b43f 100644 --- a/app/src/main/res/layout/dialog_junk.xml +++ b/app/src/main/res/layout/dialog_junk.xml @@ -29,12 +29,12 @@ android:text="@string/title_junk_hint" android:textAppearance="@style/TextAppearance.AppCompat.Small" android:textStyle="italic" - app:layout_constraintEnd_toStartOf="@+id/ibInfo" + app:layout_constraintEnd_toStartOf="@+id/ibInfoProvider" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/tvMessage" /> + + + + + app:constraint_referenced_ids=" + tvMessage,tvJunkHint,ibInfoProvider, + cbJunkFilter,ibInfoFilter" /> \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 607968df12..4b17279e6d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -99,6 +99,8 @@ Creating and using rules is a pro feature. + Use local spam filter + Sending messages Waiting for suitable connection Idle