mirror of
https://github.com/M66B/FairEmail.git
synced 2026-04-05 08:33:37 +02:00
Added block sender
This commit is contained in:
@@ -2809,13 +2809,11 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
||||
}
|
||||
|
||||
private void onActionJunk(TupleMessageEx message) {
|
||||
String who = MessageHelper.formatAddresses(message.from);
|
||||
|
||||
Bundle aargs = new Bundle();
|
||||
aargs.putString("question", context.getString(R.string.title_ask_spam_who, who));
|
||||
aargs.putLong("id", message.id);
|
||||
aargs.putString("from", MessageHelper.formatAddresses(message.from));
|
||||
|
||||
FragmentDialogAsk ask = new FragmentDialogAsk();
|
||||
FragmentDialogJunk ask = new FragmentDialogJunk();
|
||||
ask.setArguments(aargs);
|
||||
ask.setTargetFragment(parentFragment, FragmentMessages.REQUEST_MESSAGE_JUNK);
|
||||
ask.show(parentFragment.getParentFragmentManager(), "message:junk");
|
||||
@@ -4790,6 +4788,33 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
||||
}
|
||||
}
|
||||
|
||||
public static class FragmentDialogJunk extends FragmentDialogBase {
|
||||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
|
||||
String from = getArguments().getString("from");
|
||||
|
||||
View view = LayoutInflater.from(getContext()).inflate(R.layout.dialog_junk, null);
|
||||
final TextView tvMessage = view.findViewById(R.id.tvMessage);
|
||||
final CheckBox cbBlock = view.findViewById(R.id.cbBlock);
|
||||
|
||||
tvMessage.setText(getString(R.string.title_ask_spam_who, from));
|
||||
cbBlock.setEnabled(ActivityBilling.isPro(getContext()));
|
||||
|
||||
return new AlertDialog.Builder(getContext())
|
||||
.setView(view)
|
||||
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
getArguments().putBoolean("block", cbBlock.isChecked());
|
||||
sendResult(RESULT_OK);
|
||||
}
|
||||
})
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.create();
|
||||
}
|
||||
}
|
||||
|
||||
public static class FragmentKeywordManage extends FragmentDialogBase {
|
||||
@NonNull
|
||||
@Override
|
||||
|
||||
@@ -129,6 +129,8 @@ import org.bouncycastle.cms.jcajce.JcaSimpleSignerInfoVerifierBuilder;
|
||||
import org.bouncycastle.cms.jcajce.JceKeyTransEnvelopedRecipient;
|
||||
import org.bouncycastle.cms.jcajce.JceKeyTransRecipient;
|
||||
import org.bouncycastle.util.Store;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
import org.openintents.openpgp.AutocryptPeerUpdate;
|
||||
@@ -167,6 +169,7 @@ import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.mail.Address;
|
||||
import javax.mail.FolderClosedException;
|
||||
import javax.mail.Session;
|
||||
import javax.mail.internet.InternetAddress;
|
||||
@@ -4226,7 +4229,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
|
||||
break;
|
||||
case REQUEST_MESSAGE_JUNK:
|
||||
if (resultCode == RESULT_OK && data != null)
|
||||
onJunk(data.getBundleExtra("args").getLong("id"));
|
||||
onJunk(data.getBundleExtra("args"));
|
||||
break;
|
||||
case REQUEST_MESSAGES_JUNK:
|
||||
if (resultCode == RESULT_OK)
|
||||
@@ -5075,14 +5078,12 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
|
||||
}.execute(this, args, "messages:delete:execute");
|
||||
}
|
||||
|
||||
private void onJunk(long id) {
|
||||
Bundle args = new Bundle();
|
||||
args.putLong("id", id);
|
||||
|
||||
private void onJunk(Bundle args) {
|
||||
new SimpleTask<Void>() {
|
||||
@Override
|
||||
protected Void onExecute(Context context, Bundle args) {
|
||||
protected Void onExecute(Context context, Bundle args) throws JSONException {
|
||||
long id = args.getLong("id");
|
||||
boolean block = args.getBoolean("block");
|
||||
|
||||
DB db = DB.getInstance(context);
|
||||
try {
|
||||
@@ -5098,12 +5099,40 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
|
||||
|
||||
EntityOperation.queue(context, message, EntityOperation.MOVE, junk.id);
|
||||
|
||||
if (block && message.from != null)
|
||||
for (Address from : message.from) {
|
||||
String sender = ((InternetAddress) from).getAddress();
|
||||
String name = MessageHelper.formatAddresses(new Address[]{from});
|
||||
|
||||
JSONObject jsender = new JSONObject();
|
||||
jsender.put("value", sender);
|
||||
jsender.put("regex", false);
|
||||
|
||||
JSONObject jcondition = new JSONObject();
|
||||
jcondition.put("sender", jsender);
|
||||
|
||||
JSONObject jaction = new JSONObject();
|
||||
jaction.put("type", EntityRule.TYPE_MOVE);
|
||||
jaction.put("target", junk.id);
|
||||
|
||||
EntityRule rule = new EntityRule();
|
||||
rule.folder = message.folder;
|
||||
rule.name = context.getString(R.string.title_block, name);
|
||||
rule.order = 1000;
|
||||
rule.enabled = true;
|
||||
rule.stop = true;
|
||||
rule.condition = jcondition.toString();
|
||||
rule.action = jaction.toString();
|
||||
rule.id = db.rule().insertRule(rule);
|
||||
}
|
||||
|
||||
|
||||
db.setTransactionSuccessful();
|
||||
} finally {
|
||||
db.endTransaction();
|
||||
}
|
||||
|
||||
ServiceSynchronize.eval(context, "move");
|
||||
ServiceSynchronize.eval(context, "junk");
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user