Skip to content

feat: Add User-specific Sender Whitelisting and Blacklisting #154

Description

@onkar0127

Description:

Feature Summary

To give users more control over their spam detection settings, we should implement a user-level Blacklist & Whitelist rules manager. This allows users to manually specify email addresses or domains that should:

  • Whitelist: Always be marked as safe (bypassing the ML model predictions).
  • Blacklist: Always be flagged as spam/malicious (bypassing the ML model predictions).

Proposed Scope of Integration

  • Node.js Gateway Router: server.js
  • Frontend Rules Management Interface: App.jsx

Suggested Implementation Plan

1. Database Schema (MongoDB)

Create a new Rule mongoose schema to map rules to specific users:

// backend/models/Rule.js
const mongoose = require('mongoose');

const ruleSchema = new mongoose.Schema({
  user: { type: mongoose.Schema.Types.ObjectId, ref: 'User', required: true },
  type: { type: String, enum: ['blacklist', 'whitelist'], required: true },
  pattern: { type: String, required: true }, // e.g. "friend@trusted.com" or "@trusted.com"
}, { timestamps: true });

module.exports = mongoose.model('Rule', ruleSchema);

2. API Gateway Logic in server.js

Before making a prediction request to the Flask ML service inside the /predict route, query the database for matching user-defined rules:

// backend/server.js
const Rule = require('./models/Rule');

app.post("/predict", protect, async (req, res) => {
  const { text, type, sender } = req.body; // e.g. sender email passed from client
  
  if (sender) {
    // Check for matching rules
    const rule = await Rule.findOne({ user: req.user.id, pattern: sender });
    if (rule) {
      const isSpam = rule.type === 'blacklist';
      return res.json({
        prediction: isSpam ? "spam" : "ham",
        confidence: 1.0,
        rule_applied: rule.type
      });
    }
  }
  
  // Otherwise, fallback to the Flask ML model prediction
  // const response = await axios.post(...)
});

3. Frontend UI Settings Tab

Add a "Rule Manager" view to the frontend where users can:

  • View their existing blacklist/whitelist entries.
  • Add new rules (e.g., input field for email/domain + dropdown for type).
  • Delete existing rules.

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions