Added block sender

pull/172/head
M66B 5 years ago
parent d3e6792a90
commit 3b548dab16

@ -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;
}

@ -0,0 +1,43 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="24dp"
android:scrollbarStyle="outsideOverlay">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/tvMessage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/title_ask_spam_who"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:textColor="?android:attr/textColorPrimary"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<CheckBox
android:id="@+id/cbBlock"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_block_sender"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvMessage" />
<TextView
android:id="@+id/tvBlockHint"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/title_block_sender_hint"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="?android:attr/textColorPrimary"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/cbBlock" />
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>

@ -85,6 +85,13 @@
</plurals>
<string name="title_ask_spam_who">Treat message from %1$s as spam?</string>
<string name="title_block">Block %1$s</string>
<string name="title_block_sender">Block sender</string>
<string name="title_block_sender_hint">
This will create a rule to automatically move future messages to the spam folder.
Creating and using rules is a pro feature.
</string>
<string name="title_notification_waiting">Waiting for suitable connection</string>
<string name="title_notification_sending">Sending messages</string>
<string name="title_notification_failed">\'%1$s\' failed</string>

Loading…
Cancel
Save