Added blocking sender domain

pull/172/head
M66B 5 years ago
parent a812f52e80
commit f9af0b1c1a

@ -4951,17 +4951,27 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
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);
final CheckBox cbBlockSender = view.findViewById(R.id.cbBlockSender);
final CheckBox cbBlockDomain = view.findViewById(R.id.cbBlockDomain);
tvMessage.setText(getString(R.string.title_ask_spam_who, from));
cbBlock.setEnabled(ActivityBilling.isPro(getContext()));
cbBlockSender.setEnabled(ActivityBilling.isPro(getContext()));
cbBlockDomain.setEnabled(false);
cbBlockSender.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
cbBlockDomain.setEnabled(isChecked);
}
});
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());
getArguments().putBoolean("block_sender", cbBlockSender.isChecked());
getArguments().putBoolean("block_domain", cbBlockDomain.isChecked());
sendResult(RESULT_OK);
}
})

@ -5353,7 +5353,8 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
@Override
protected Void onExecute(Context context, Bundle args) throws JSONException {
long id = args.getLong("id");
boolean block = args.getBoolean("block");
boolean block_sender = args.getBoolean("block_sender");
boolean block_domain = args.getBoolean("block_domain");
DB db = DB.getInstance(context);
try {
@ -5369,33 +5370,38 @@ 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);
if ((block_sender || block_domain) &&
(message.from != null && message.from.length > 0)) {
String sender = ((InternetAddress) message.from[0]).getAddress();
String name = MessageHelper.formatAddresses(new Address[]{message.from[0]});
if (block_domain) {
int at = sender.indexOf('@');
if (at > 0)
sender = sender.substring(at);
}
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 {

@ -21,7 +21,7 @@
app:layout_constraintTop_toTopOf="parent" />
<CheckBox
android:id="@+id/cbBlock"
android:id="@+id/cbBlockSender"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
@ -30,14 +30,25 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvMessage" />
<CheckBox
android:id="@+id/cbBlockDomain"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_block_domain"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbBlockSender" />
<TextView
android:id="@+id/tvBlockHint"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
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" />
app:layout_constraintTop_toBottomOf="@+id/cbBlockDomain" />
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>

@ -87,6 +87,7 @@
<string name="title_block">Block %1$s</string>
<string name="title_block_sender">Block sender</string>
<string name="title_block_domain">Block sender domain</string>
<string name="title_block_sender_hint">
Blocking a sender will create a rule to automatically move future messages to the spam folder.
Creating and using rules is a pro feature.

Loading…
Cancel
Save