Removed auto junk

pull/206/head
M66B 3 years ago
parent c2c2d131c8
commit 7904267e9b

@ -4021,6 +4021,7 @@ class Core {
EntityFolder junk = db.folder().getFolderByType(message.account, EntityFolder.JUNK); EntityFolder junk = db.folder().getFolderByType(message.account, EntityFolder.JUNK);
if (junk != null) { if (junk != null) {
EntityOperation.queue(context, message, EntityOperation.MOVE, junk.id); EntityOperation.queue(context, message, EntityOperation.MOVE, junk.id);
message.ui_hide = true;
executed = true; executed = true;
} }
break; break;

@ -100,45 +100,36 @@ public class EntityContact implements Serializable {
@NonNull EntityAccount account, @NonNull EntityAccount account,
@NonNull EntityFolder folder, @NonNull EntityFolder folder,
@NonNull EntityMessage message) { @NonNull EntityMessage message) {
if (!EntityFolder.JUNK.equals(folder.type)) { int days = (folder.isOutgoing() ? folder.keep_days : folder.sync_days);
int days = (folder.isOutgoing() ? folder.keep_days : folder.sync_days); if (days == Integer.MAX_VALUE)
if (days == Integer.MAX_VALUE) days = EntityFolder.DEFAULT_KEEP;
days = EntityFolder.DEFAULT_KEEP; if (message.received < account.created - days * 24 * 3600 * 1000L)
if (message.received < account.created - days * 24 * 3600 * 1000L) return;
return;
}
if (EntityFolder.DRAFTS.equals(folder.type) || if (EntityFolder.DRAFTS.equals(folder.type) ||
EntityFolder.ARCHIVE.equals(folder.type) || EntityFolder.ARCHIVE.equals(folder.type) ||
EntityFolder.TRASH.equals(folder.type)) EntityFolder.TRASH.equals(folder.type) ||
EntityFolder.JUNK.equals(folder.type))
return; return;
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean suggest_sent = prefs.getBoolean("suggest_sent", true); boolean suggest_sent = prefs.getBoolean("suggest_sent", true);
boolean suggest_received = prefs.getBoolean("suggest_received", false); boolean suggest_received = prefs.getBoolean("suggest_received", false);
boolean auto_junk = prefs.getBoolean("auto_junk", false);
// Shortcut // Shortcut
if (!suggest_sent && !suggest_received && if (!suggest_sent && !suggest_received)
!(EntityFolder.JUNK.equals(folder.type) && auto_junk))
return; return;
int type; int type = (folder.isOutgoing() ? TYPE_TO : TYPE_FROM);
if (EntityFolder.JUNK.equals(folder.type))
type = TYPE_JUNK;
else
type = (folder.isOutgoing() ? TYPE_TO : TYPE_FROM);
// Check if from self // Check if from self
if (type == TYPE_FROM || type == TYPE_JUNK) { if (type == TYPE_FROM) {
if (message.from != null) { if (message.from != null) {
List<EntityIdentity> identities = Core.getIdentities(folder.account, context); List<EntityIdentity> identities = Core.getIdentities(folder.account, context);
if (identities != null) { if (identities != null) {
for (Address sender : message.from) { for (Address sender : message.from) {
for (EntityIdentity identity : identities) for (EntityIdentity identity : identities)
if (identity.similarAddress(sender)) { if (identity.similarAddress(sender)) {
if (type == TYPE_JUNK)
return;
type = TYPE_TO; type = TYPE_TO;
break; break;
} }
@ -153,8 +144,6 @@ public class EntityContact implements Serializable {
return; return;
if (type == TYPE_FROM && !suggest_received) if (type == TYPE_FROM && !suggest_received)
return; return;
if (type == TYPE_JUNK && !auto_junk)
return;
List<Address> addresses = new ArrayList<>(); List<Address> addresses = new ArrayList<>();
if (type == TYPE_FROM) { if (type == TYPE_FROM) {
@ -168,19 +157,6 @@ public class EntityContact implements Serializable {
addresses.addAll(Arrays.asList(message.to)); addresses.addAll(Arrays.asList(message.to));
if (message.cc != null) if (message.cc != null)
addresses.addAll(Arrays.asList(message.cc)); addresses.addAll(Arrays.asList(message.cc));
} else if (type == TYPE_JUNK) {
if (message.from != null) {
DB db = DB.getInstance(context);
for (Address from : message.from) {
String email = ((InternetAddress) from).getAddress();
if (TextUtils.isEmpty(email))
continue;
EntityContact nojunk = db.contact().getContact(message.account, TYPE_NO_JUNK, email);
if (nojunk != null)
return;
}
addresses.addAll(Arrays.asList(message.from));
}
} }
update(context, folder.account, addresses.toArray(new Address[0]), type, message.received); update(context, folder.account, addresses.toArray(new Address[0]), type, message.received);

@ -64,7 +64,6 @@ public class FragmentDialogJunk extends FragmentDialogBase {
final ImageButton ibMore = view.findViewById(R.id.ibMore); final ImageButton ibMore = view.findViewById(R.id.ibMore);
final TextView tvMore = view.findViewById(R.id.tvMore); final TextView tvMore = view.findViewById(R.id.tvMore);
final Button btnEditRules = view.findViewById(R.id.btnEditRules); final Button btnEditRules = view.findViewById(R.id.btnEditRules);
final CheckBox cbJunkAuto = view.findViewById(R.id.cbJunkAuto);
final CheckBox cbJunkFilter = view.findViewById(R.id.cbJunkFilter); final CheckBox cbJunkFilter = view.findViewById(R.id.cbJunkFilter);
final ImageButton ibInfoFilter = view.findViewById(R.id.ibInfoFilter); final ImageButton ibInfoFilter = view.findViewById(R.id.ibInfoFilter);
final CheckBox cbBlocklist = view.findViewById(R.id.cbBlocklist); final CheckBox cbBlocklist = view.findViewById(R.id.cbBlocklist);
@ -74,7 +73,6 @@ public class FragmentDialogJunk extends FragmentDialogBase {
final Group grpMore = view.findViewById(R.id.grpMore); final Group grpMore = view.findViewById(R.id.grpMore);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean auto_junk = prefs.getBoolean("auto_junk", false);
boolean check_blocklist = prefs.getBoolean("check_blocklist", false); boolean check_blocklist = prefs.getBoolean("check_blocklist", false);
boolean use_blocklist = prefs.getBoolean("use_blocklist", false); boolean use_blocklist = prefs.getBoolean("use_blocklist", false);
@ -158,13 +156,6 @@ public class FragmentDialogJunk extends FragmentDialogBase {
} }
}); });
cbJunkAuto.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
prefs.edit().putBoolean("auto_junk", isChecked).apply();
}
});
cbJunkFilter.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { cbJunkFilter.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override @Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
@ -253,7 +244,6 @@ public class FragmentDialogJunk extends FragmentDialogBase {
cbBlockSender.setEnabled(canBlock); cbBlockSender.setEnabled(canBlock);
cbBlockDomain.setEnabled(false); cbBlockDomain.setEnabled(false);
ibMore.setImageLevel(1); ibMore.setImageLevel(1);
cbJunkAuto.setChecked(auto_junk);
cbBlocklist.setChecked(check_blocklist && use_blocklist); cbBlocklist.setChecked(check_blocklist && use_blocklist);
tvBlocklist.setText(TextUtils.join(", ", DnsBlockList.getNamesEnabled(context))); tvBlocklist.setText(TextUtils.join(", ", DnsBlockList.getNamesEnabled(context)));
grpInJunk.setVisibility(inJunk ? View.GONE : View.VISIBLE); grpInJunk.setVisibility(inJunk ? View.GONE : View.VISIBLE);

@ -7827,10 +7827,6 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
if (message == null) if (message == null)
return null; return null;
EntityAccount account = db.account().getAccount(message.account);
if (account == null)
return null;
EntityFolder junk = db.folder().getFolderByType(message.account, EntityFolder.JUNK); EntityFolder junk = db.folder().getFolderByType(message.account, EntityFolder.JUNK);
if (junk == null) if (junk == null)
throw new IllegalArgumentException(context.getString(R.string.title_no_junk_folder)); throw new IllegalArgumentException(context.getString(R.string.title_no_junk_folder));

@ -117,30 +117,6 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvMore" /> app:layout_constraintTop_toBottomOf="@id/tvMore" />
<CheckBox
android:id="@+id/cbJunkAuto"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_junk_auto"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintEnd_toStartOf="@+id/ibInfoFilter"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/btnEditRules" />
<eu.faircode.email.FixedTextView
android:id="@+id/tvJunkAutoHint"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:text="@string/title_junk_auto_hint"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="?attr/colorWarning"
android:textStyle="italic"
app:layout_constraintEnd_toStartOf="@+id/ibInfoFilter"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbJunkAuto" />
<CheckBox <CheckBox
android:id="@+id/cbJunkFilter" android:id="@+id/cbJunkFilter"
android:layout_width="0dp" android:layout_width="0dp"
@ -150,7 +126,7 @@
android:textAppearance="@style/TextAppearance.AppCompat.Small" android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintEnd_toStartOf="@+id/ibInfoFilter" app:layout_constraintEnd_toStartOf="@+id/ibInfoFilter"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvJunkAutoHint" /> app:layout_constraintTop_toBottomOf="@id/btnEditRules" />
<eu.faircode.email.FixedTextView <eu.faircode.email.FixedTextView
android:id="@+id/tvJunkFilterHint" android:id="@+id/tvJunkFilterHint"
@ -243,7 +219,7 @@
android:layout_height="0dp" android:layout_height="0dp"
app:constraint_referenced_ids=" app:constraint_referenced_ids="
btnEditRules, btnEditRules,
cbJunkAuto,tvJunkAutoHint,cbJunkFilter,tvJunkFilterHint,ibInfoFilter, cbJunkFilter,tvJunkFilterHint,ibInfoFilter,
cbBlocklist,tvBlocklist,tvBlocklistHint,ibInfoBlocklist" /> cbBlocklist,tvBlocklist,tvBlocklistHint,ibInfoBlocklist" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
</eu.faircode.email.ScrollViewEx> </eu.faircode.email.ScrollViewEx>

@ -98,9 +98,7 @@
Blocking a sender domain uses filter rules, which is a pro feature. Blocking a sender domain uses filter rules, which is a pro feature.
</string> </string>
<string name="title_junk_auto">Automatically block spam senders</string>
<string name="title_junk_filter">Use local spam filter</string> <string name="title_junk_filter">Use local spam filter</string>
<string name="title_junk_auto_hint">This will block senders of new messages in the spam folder</string>
<string name="title_junk_filter_hint">This can increase battery usage and incorrectly mark messages as spam</string> <string name="title_junk_filter_hint">This can increase battery usage and incorrectly mark messages as spam</string>
<string name="title_junk_blocklist">Use spam block lists</string> <string name="title_junk_blocklist">Use spam block lists</string>

Loading…
Cancel
Save