1
0
Fork 0
mirror of https://github.com/M66B/FairEmail.git synced 2025-03-03 18:26:20 +00:00

Allow selected rules for POP3 accounts

This commit is contained in:
M66B 2020-07-01 08:57:17 +02:00
parent d26e5de818
commit 4d130ea18c
7 changed files with 31 additions and 14 deletions

2
FAQ.md
View file

@ -1840,8 +1840,6 @@ it is not possible to preview which messages would match a header rule condition
In the three-dots *more* message menu there is an item to create a rule for a received message with the most common conditions filled in.
Rules are available for IMAP accounts only because the POP3 protocol allows downloading and permanently deleting messages from the inbox only.
Using rules is a pro feature.
<br />

View file

@ -520,6 +520,9 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
}
}
if (EntityFolder.INBOX.equals(folder.type) && folder.accountProtocol == EntityAccount.TYPE_POP)
popupMenu.getMenu().add(Menu.NONE, R.string.title_edit_rules, 11, R.string.title_edit_rules);
if (folder.account != null && folder.accountProtocol == EntityAccount.TYPE_IMAP)
popupMenu.getMenu().add(Menu.NONE, R.string.title_create_sub_folder, 16, R.string.title_create_sub_folder)
.setEnabled(folder.inferiors);
@ -725,7 +728,8 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
lbm.sendBroadcast(
new Intent(ActivityView.ACTION_EDIT_RULES)
.putExtra("account", folder.account)
.putExtra("folder", folder.id));
.putExtra("folder", folder.id)
.putExtra("protocol", folder.accountProtocol));
}
private void onActionEditProperties() {

View file

@ -4424,6 +4424,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
Intent rule = new Intent(ActivityView.ACTION_EDIT_RULE);
rule.putExtra("account", message.account);
rule.putExtra("folder", message.folder);
rule.putExtra("protocol", message.accountProtocol);
if (message.from != null && message.from.length > 0)
rule.putExtra("sender", ((InternetAddress) message.from[0]).getAddress());
if (message.to != null && message.to.length > 0)

View file

@ -66,6 +66,7 @@ public class AdapterRule extends RecyclerView.Adapter<AdapterRule.ViewHolder> {
private LifecycleOwner owner;
private LayoutInflater inflater;
private int protocol = -1;
private List<TupleRuleEx> items = new ArrayList<>();
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
@ -192,7 +193,8 @@ public class AdapterRule extends RecyclerView.Adapter<AdapterRule.ViewHolder> {
new Intent(ActivityView.ACTION_EDIT_RULE)
.putExtra("id", rule.id)
.putExtra("account", rule.account)
.putExtra("folder", rule.folder));
.putExtra("folder", rule.folder)
.putExtra("protocol", protocol));
}
@Override
@ -215,8 +217,10 @@ public class AdapterRule extends RecyclerView.Adapter<AdapterRule.ViewHolder> {
popupMenu.getMenu().add(Menu.NONE, R.string.title_rule_execute, 2, R.string.title_rule_execute)
.setEnabled(ActivityBilling.isPro(context));
popupMenu.getMenu().add(Menu.NONE, R.string.title_reset, 3, R.string.title_reset);
popupMenu.getMenu().add(Menu.NONE, R.string.title_move_to_folder, 4, R.string.title_move_to_folder);
popupMenu.getMenu().add(Menu.NONE, R.string.title_copy, 5, R.string.title_copy);
if (protocol == EntityAccount.TYPE_IMAP) {
popupMenu.getMenu().add(Menu.NONE, R.string.title_move_to_folder, 4, R.string.title_move_to_folder);
popupMenu.getMenu().add(Menu.NONE, R.string.title_copy, 5, R.string.title_copy);
}
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
@ -378,6 +382,7 @@ public class AdapterRule extends RecyclerView.Adapter<AdapterRule.ViewHolder> {
.putExtra("id", rule.id)
.putExtra("account", rule.account)
.putExtra("folder", rule.folder)
.putExtra("protocol", protocol)
.putExtra("copy", true));
}
});
@ -405,8 +410,9 @@ public class AdapterRule extends RecyclerView.Adapter<AdapterRule.ViewHolder> {
});
}
public void set(@NonNull List<TupleRuleEx> rules) {
Log.i("Set rules=" + rules.size());
public void set(int protocol, @NonNull List<TupleRuleEx> rules) {
this.protocol = protocol;
Log.i("Set protocol=" + protocol + " rules=" + rules.size());
DiffUtil.DiffResult diff = DiffUtil.calculateDiff(new DiffCallback(items, rules), false);

View file

@ -1689,6 +1689,8 @@ class Core {
return;
}
List<EntityRule> rules = db.rule().getEnabledRules(folder.id);
try {
db.folder().setFolderSyncState(folder.id, "syncing");
@ -1843,8 +1845,7 @@ class Core {
attachment.id = db.attachment().insertAttachment(attachment);
}
// No rules
runRules(context, imessage, account, folder, message, rules);
reportNewMessage(context, account, folder, message);
db.setTransactionSuccessful();

View file

@ -158,6 +158,7 @@ public class FragmentRule extends FragmentBase {
private long copy = -1;
private long account = -1;
private long folder = -1;
private int protocol = -1;
private final static int MAX_CHECK = 10;
@ -180,6 +181,7 @@ public class FragmentRule extends FragmentBase {
id = args.getLong("id", -1);
account = args.getLong("account", -1);
folder = args.getLong("folder", -1);
protocol = args.getInt("protocol", EntityAccount.TYPE_IMAP);
}
@Override
@ -383,9 +385,11 @@ public class FragmentRule extends FragmentBase {
actions.add(new Action(EntityRule.TYPE_SNOOZE, getString(R.string.title_rule_snooze)));
actions.add(new Action(EntityRule.TYPE_FLAG, getString(R.string.title_rule_flag)));
actions.add(new Action(EntityRule.TYPE_IMPORTANCE, getString(R.string.title_rule_importance)));
actions.add(new Action(EntityRule.TYPE_KEYWORD, getString(R.string.title_rule_keyword)));
actions.add(new Action(EntityRule.TYPE_MOVE, getString(R.string.title_rule_move)));
actions.add(new Action(EntityRule.TYPE_COPY, getString(R.string.title_rule_copy)));
if (protocol == EntityAccount.TYPE_IMAP) {
actions.add(new Action(EntityRule.TYPE_KEYWORD, getString(R.string.title_rule_keyword)));
actions.add(new Action(EntityRule.TYPE_MOVE, getString(R.string.title_rule_move)));
actions.add(new Action(EntityRule.TYPE_COPY, getString(R.string.title_rule_copy)));
}
actions.add(new Action(EntityRule.TYPE_ANSWER, getString(R.string.title_rule_answer)));
actions.add(new Action(EntityRule.TYPE_AUTOMATION, getString(R.string.title_rule_automation)));
adapterAction.addAll(actions);

View file

@ -48,6 +48,7 @@ import static android.app.Activity.RESULT_OK;
public class FragmentRules extends FragmentBase {
private long account;
private long folder;
private int protocol;
private boolean cards;
@ -68,6 +69,7 @@ public class FragmentRules extends FragmentBase {
Bundle args = getArguments();
account = args.getLong("account", -1);
folder = args.getLong("folder", -1);
protocol = args.getInt("protocol", -1);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
cards = prefs.getBoolean("cards", true);
@ -107,6 +109,7 @@ public class FragmentRules extends FragmentBase {
Bundle args = new Bundle();
args.putLong("account", account);
args.putLong("folder", folder);
args.putInt("protocol", protocol);
FragmentRule fragment = new FragmentRule();
fragment.setArguments(args);
@ -139,7 +142,7 @@ public class FragmentRules extends FragmentBase {
if (rules == null)
rules = new ArrayList<>();
adapter.set(rules);
adapter.set(protocol, rules);
pbWait.setVisibility(View.GONE);
grpReady.setVisibility(View.VISIBLE);